Cms mediawiki tools

From Reto

Jump to: navigation, search

Bot 18:41, 13 August 2007 (CEST)

See also
A – Z


1.3 Tools


Home > MediaWiki Reference > CMS::MediaWiki > The Main Chapter > Tools

1.2 Usage of the Module [  up  ] - [ top ] 1.3.1 wikisync.pl
X

Purpose & Usage

  • Update MediaWiki with content from the Web at the command line prompt.


Example

  • wikisync.pl --host meta.example.net --path "wiki-path" --title "Cms_mediawiki_tools" --section 4 --src_url "http://www.example.ch/_files/wikisync_pl.html" --html_before "" --html_after "" --section_title "Your Section Title"


Download


wikisync.pl

#!/usr/bin/perl -w
use strict;
$| = 1;

#############################################################
# Infos & Docs
# http://meta.pgate.net/wiki-reto/cms-mediawiki-tools.html
#
# Author: Reto Schaer
# Location: nonius
#
my $VERSION = '0.8003';
#############################################################

use CMS::MediaWiki;
use Getopt::Long;
use Crypt::Lite;
use LWP::Simple;

sub Debug($);

#####  GLOBAL
my @getopt_args = (
	'h',			# help
	'host=s',		# target host
	'path=s',		# Wiki path
	'title=s',		# Title / name of the Wiki page
	'section=s',		# The section of the Wiki page
	'section_title=s',	# The headline of the section
	'enc_auth=s',		# Ciper of the login to the Wiki
	'src_url=s',		# Source Web document to sync
	'html_before=s', 	# Code before the content
	'html_after=s', 	# Code after the content
	'debug' ,		# debug mode for development support
	'v',			# Verbose mode
);

my %Options;

Getopt::Long::config("noignorecase", "bundling");

&Usage("") unless GetOptions(\%Options, @getopt_args);

# -- Encrypt "Wikiuser:wikipass"
#    https://ssl.pgate.net/cgi-bin/crypt-lite.cgi?in=foo&pass=bar&action=enc
$Options{'enc_auth'} ||=
	'5eed8455c4cb531eb5d109b9a1540dabd509a2920409e08b5eaffa000' .
	'abdd603fdfe0455e8d254abfe570ab88a56fdac0e09e982';
$Options{'host'   } ||= '';
$Options{'src_url'} ||= '';
$Options{'html_before'} ||= '';
my $hostname = `hostname`; chomp $hostname;
$Options{'html_after' } .= "\n<!-- " . (scalar localtime) . " by wikisync on $hostname -->\n";
$Options{'section_title'} ||= 'A Section';

&main();

########################################
sub main() {
########################################
	my $c = Crypt::Lite->new(encoding => 'hex8');
	my ($user, $pass) = split /:/, $c->decrypt($Options{'enc_auth'}, 'your_secret_word');

	Debug "Wiki user: \"$user\"";

	my $mw = CMS::MediaWiki->new(
		host  => $Options{'host'} ,
		path  => $Options{'path'} ,
		debug => 0
	);

	if ($mw->login(user => $user, pass => $pass)) {
		print STDERR "Could not login\n";
		return;
  	}
	Debug 'Logged in.';

	my $text = get $Options{'src_url'};
	   $text ||= '';

	unless ($text) {
		print STDERR "No text\n";
		return;
	}

	Debug "Updating page \"$Options{'title'}\" ...";

	my $rc = $mw->editPage(
		title   => $Options{'title'},
		section => $Options{'section'},
		text    => "== $Options{'section_title'} ==\n\n" .
				"$Options{'html_before'}\n" . $text . "$Options{'html_after'}\n",
		summary => 'by Bot'
	);

	Debug "rc = $rc";
}

sub Debug ($) { print "$_[0]\n"; }

sub Usage() { }

__END__

See also

Views
Personal tools