Wikia

How To Wiki

How to create, read and modify MediaWiki pages in Perl

1,794pages on
this wiki
Talk0
Warning: This page is incomplete, use this article with caution. Please help finish it



Modifying MediaWiki pages in Perl.

There are a number of ways to edit MediaWiki pages in Perl.

CMS::MediaWikiEdit

CMS::MediaWiki is the main Perl module for reading reading editing MediaWiki pages

Me and this artclie, sitting in a tree, L-E-A-R-N-I-N-G!

Write a pageEdit

sub updatePage {
	my $pageTitle=$_[0];
	my $pageText=$_[1]; 
	my $sleepVar=0;
	my $sleepInterval=2; #in seconds
	#Post the page
	if($pageTitle eq ''){
		print "!!!!!!!!!!!!!!!!!!!!!!!!!!";
		print "!! name error: name empty";
		print "!!!!!!!!!!!!!!!!!!!!!!!!!!";
	}else{
		$rc = $mw->editPage(   
			title   => "$pageTitle" ,
			section => '' , 
			text    => "$pageText" ,
		  summary => "Updated via  Bot." , #add summary as you wish
		);
		# randome sleep from 0-n in sec
		# to put less load on server
	}
	$sleepVar = rand($sleepInterval);
	system(" sleep $sleepVar");
	print "Page writen...\n";
}
  • Call sub
    • &writePage($title, $text);

Reading pageEdit

Extracting pages from Archived databaseEdit

Downloading database dump

$dbfileLocation="http://wikistats.wikia.com/dbdumps/howto/pages_current.xml.gz";

sub downloadDB {
	my $dbfile=$dbfileLocation;
	my $dbfileOut='';
	my $dbfileType='';

	print "\n# Get the database\n\n";
	$dbfile =~ s/.*\///;
	$dbfileOut = $dbfile;
	$dbfileOut =~ s/\.gz$//;
	$dbfileOut =~ s/\.bz2$//;
	system("rm -f $dbfile"); #removing old file
	system("rm -f $dbfileOut");
	system("wget  $dbfileLocation"); #getting db
	$dbfileType = $dbfile;
	$dbfileType =~ s/.*\.//; #aquiring db file type
	if ( $dbfileType eq 'gz' ) { #extraxting db
		system("gzip -d $dbfile");
	} elsif ( $dbfileType eq 'bz2' ) {
		system("bzip2 -d $dbfile");
	}
	return $dbfileOut;
}
  • Calling subrutine
    • $dbfile = &downloadDB;
      $dbfile is the variable using for the database file name

link title

WWW::Mediawiki::ClientEdit

To be added

Around Wikia's network

Random Wiki