[PerlWikiBot] SF.net SVN: perlwikibot: [20] trunk
Status: Pre-Alpha
Brought to you by:
rotemliss
From: <rot...@us...> - 2006-09-16 12:30:29
|
Revision: 20 http://svn.sourceforge.net/perlwikibot/?rev=20&view=rev Author: rotemliss Date: 2006-09-16 05:30:18 -0700 (Sat, 16 Sep 2006) Log Message: ----------- Splitting the actual actions on the server to another file, adding the refreshing, will add all the other features soon; may be broken for now. Modified Paths: -------------- trunk/bot.pl trunk/includes/functions.pm trunk/includes/http.pm Added Paths: ----------- trunk/includes/actions.pm Modified: trunk/bot.pl =================================================================== --- trunk/bot.pl 2006-09-16 11:45:57 UTC (rev 19) +++ trunk/bot.pl 2006-09-16 12:30:18 UTC (rev 20) @@ -38,8 +38,10 @@ my $title = $pages[$i]; my $action = $configure::actions{ $pages[$i + 1] }; - # Execute the action (TODO: add the actions which were supported in the previous bot) + # Execute the action (TODO: add move and delete) if ( $action eq "replace" ) { functions::replaceInPage( $title ); + } elsif ( $action eq "refresh" ) { + functions::refreshPage( $title ); } } Added: trunk/includes/actions.pm =================================================================== --- trunk/includes/actions.pm (rev 0) +++ trunk/includes/actions.pm 2006-09-16 12:30:18 UTC (rev 20) @@ -0,0 +1,184 @@ +# Package name +package actions; + +# Code style +use warnings; +use strict; + +# Libraries +use includes::http; +use config::configure; +use config::runtime; + +# Counters +my ( $i, $j, $k, $l, $m ); + +# Log in +sub login { + # Is sysop finally required? + my $sysop = 0; + + # Go through the array, and check if sysop permission is needed. + for ( $i = 0; $i <= $#configure::executedActions; $i++ ) { + my $action = $configure::actions{ $configure::executedActions[$i] }; + if ( $action eq "replace" ) { + # Continue + } elsif ($action eq "refresh") { + # Continue + } elsif ($action eq "delete") { + $sysop = 1; + } elsif ($action eq "move") { + # Continue + } + } + + # Get user name and password + my ( $username, $password ); + if ( $sysop == 1 ) { + $username = $configure::sysopUserNames{ $ARGV[0] }; + $password = $configure::sysopPasswords{ $ARGV[0] }; + } else { + $username = $configure::userNames{ $ARGV[0] }; + $password = $configure::passwords{ $ARGV[0] }; + } + + # Log in + print "Logging in...\n"; + http::postPage( "Special:Userlogin", "submitlogin", + [ + wpName => $username, + wpPassword => $password, + wpRemember => 0, + ], + , "type=login" ); + print "\tDone!\n"; +} + +# Get the contents of a page +sub getPageContents { + # Get parameters + my ( $title ) = @_; + + # Get page contents + return http::getPage( $title, "raw" ); +} + +# Edit page +sub editPage { + # Get parameters + my ( $title, $text, $editSummary ) = @_; + + print "Editing page $title...\n"; + + # Add prefix if necessary + if ( $configure::sendPages == 2 ) { + my $serverPrefix = $configure::serverPrefixes{ $ARGV[0] }; + $title = $serverPrefix.$title; + } + + # Get the edit page contents + my $editPage = http::getPage( $title, "edit" ); + + # Get the start time + $editPage =~ /<input type='hidden' value="([0-9]{14})" name="wpStarttime" \/>/; + my $startTime = $1; + + # Get the edit time + $editPage =~ /<input type='hidden' value="([0-9]{14})" name="wpEdittime" \/>/; + my $editTime = $1; + + # Get edit token + $editPage =~ /<input type='hidden' value="([0-9a-f]{32})" name="wpEditToken" \/>/; + my $editToken = $1; + + # Send page + if ( defined( $editToken ) && $editToken =~ /[0-9a-f]{32}/ ) { + if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { + http::postPage( $title, "submit", + [ + wpSection => "", + wpStarttime => $startTime, + wpEdittime => $editTime, + wpEditToken => $editToken, + wpSummary => $editSummary, + wpTextbox1 => $text, + wpMinoredit => 1, + ], + ); + } + print "\tDone!\n"; + } else { + print "Error!\nThis may be a protected page you don't have permission to edit, or it has deleted since the dump file you use created.\n"; + } +} + +# Refresh page +sub refreshPage { + # Get parameters + my ( $title ) = @_; + + # Null edit + editPage( $title, getPageContents( $title ), "Refreshing page" ); +} + +# Move page +sub movePage { + # Get parameters + my ( $title, $newTitle, $moveReason ) = @_; + + print "Moving page $title to $newTitle...\n"; + + # Get the delete page contents + my $movePage = http::getPage( "Special:Movepage/$title" ); + + # Get the edit token + if ($movePage =~ /<input type='hidden' name='wpEditToken' value="([0-9,a-f]{32})" \/>/) { + my $editToken = $1; + + # Send page + if ( $configure::sendPages == 1 ) { + http::postPage( "Special:Movepage", "submit", + [ + wpOldTitle => $title, + wpNewTitle => $newTitle, + wpReason => $moveReason, + wpEditToken => $editToken, + ], + ); + } + print "\tDone!\n"; + } else { + print "Error!\nYou may not have the permission to move pages, or there may already a page (which is not just a redirection) under the new title.\n"; + } +} + +# Delete page +sub deletePage { + # Get parameters + my ( $title, $reason ) = @_; + + print "Deleting page $title...\n"; + + # Get the delete page contents + my $deletePage = http::getPage( $title, "delete" ); + + # Get the edit token + if ($deletePage =~ /<input type='hidden' name='wpEditToken' value="([0-9,a-f]{32})" \/>/) { + my $editToken = $1; + + # Send page + if ( $configure::sendPages == 1 ) { + http::postPage( $title, "delete", + [ + wpReason => $reason, + wpEditToken => $editToken, + ], + ); + } + print "\tDone!\n"; + } else { + print "Error!\nYou may not have the permission to delete pages, or the page is already deleted.\n"; + } +} + +return 1; Property changes on: trunk/includes/actions.pm ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/includes/functions.pm =================================================================== --- trunk/includes/functions.pm 2006-09-16 11:45:57 UTC (rev 19) +++ trunk/includes/functions.pm 2006-09-16 12:30:18 UTC (rev 20) @@ -6,8 +6,8 @@ use strict; # Libraries +use includes::actions; use includes::dump; -use includes::http; use config::configure; use config::runtime; @@ -117,103 +117,6 @@ return timegm( $6, $5, $4, $3, $2 - 1, $1 - 1900 ); } -# Log in -sub login { - # Is sysop finally required? - my $sysop = 0; - - # Go through the array, and check if sysop permission is needed. - for ( $i = 0; $i <= $#configure::executedActions; $i++ ) { - my $action = $configure::actions{ $configure::executedActions[$i] }; - if ( $action eq "replace" ) { - # Continue - } elsif ($action eq "refresh") { - # Continue - } elsif ($action eq "delete") { - $sysop = 1; - } elsif ($action eq "move") { - # Continue - } - } - - # Get user name and password - my ( $username, $password ); - if ( $sysop == 1 ) { - $username = $configure::sysopUserNames{ $ARGV[0] }; - $password = $configure::sysopPasswords{ $ARGV[0] }; - } else { - $username = $configure::userNames{ $ARGV[0] }; - $password = $configure::passwords{ $ARGV[0] }; - } - - # Log in - print "Logging in...\n"; - http::postPage( "Special:Userlogin", "submitlogin", - [ - wpName => $username, - wpPassword => $password, - wpRemember => 0, - ], - , "type=login" ); - print "\tDone!\n"; -} - -# Get the contents of a page -sub getPageContents { - # Get parameters - my ( $title ) = @_; - - return http::getPage( $title, "raw" ); -} - -# Edit page -sub editPage { - # Get parameters - my ( $title, $text, $editSummary ) = @_; - - print "Editing page $title...\n"; - - if ( $configure::sendPages == 2 ) { - my $serverPrefix = $configure::serverPrefixes{ $ARGV[0] }; - $title = $serverPrefix.$title; - } - - # Get the edit page contents - my $editPage = http::getPage( $title, "edit" ); - - # Get the start time - $editPage =~ /<input type='hidden' value="([0-9]{14})" name="wpStarttime" \/>/; - my $startTime = $1; - - # Get the edit time - $editPage =~ /<input type='hidden' value="([0-9]{14})" name="wpEdittime" \/>/; - my $editTime = $1; - - # Get edit token - $editPage =~ /<input type='hidden' value="([0-9a-f]{32})" name="wpEditToken" \/>/; - my $editToken = $1; - - # Send page - if ( defined( $editToken ) && $editToken =~ /[0-9a-f]{32}/ ) { - if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { - http::postPage( $title, "submit", - [ - wpSection => "", - wpStarttime => $startTime, - wpEdittime => $editTime, - wpEditToken => $editToken, - wpSummary => $editSummary, - wpTextbox1 => $text, - wpMinoredit => 1, - ], - ); - } - print "\tDone!\n"; - } else { - print "Error!\nThis may be a protected page you don't have permission to edit, or it has deleted since the dump file you use created.\n"; - } -} - # Replace regular expressions in the page sub replaceInPage { # Get parameters @@ -249,7 +152,7 @@ # Edit page only of replaced something if ( $replaced == 1 ) { - editPage( $title, $editedPage, $editSummary ); + actions::editPage( $title, $editedPage, $editSummary ); } } else { print "Replaced in page $title.\n"; @@ -259,70 +162,24 @@ # Refresh page sub refreshPage { # Get parameters - my ( $server, $title ) = @_; + my ( $title ) = @_; - editPage( $title, getPageContents( $title ), "Refreshing page" ); -} - -# Move page -sub movePage { - # Get parameters - my ( $server, $title, $newTitle, $moveReason ) = @_; - - print "Moving page $title to $newTitle...\n"; - - # Get the delete page contents - my $movePage = http::getPage( "Special:Movepage/$title" ); - - # Get the edit token - if ($movePage =~ /<input type='hidden' name='wpEditToken' value="([0-9,a-f]{32})" \/>/) { - my $editToken = $1; - - # Send page - if ( $configure::sendPages == 1 ) { - http::postPage( "Special:Movepage", "submit", - [ - wpOldTitle => $title, - wpNewTitle => $newTitle, - wpReason => $moveReason, - wpEditToken => $editToken, - ], - ); - } - print "\tDone!\n"; + if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { + actions::refreshPage( $title ); + } else { + print "Refreshed page $title.\n"; } - else - { - print "Error!\nYou may not have the permission to move pages, or there may already a page (which is not just a redirection) under the new title.\n"; - } } -# Delete page +# Refresh page sub deletePage { # Get parameters - my ( $server, $title, $reason ) = @_; + my ( $title ) = @_; - print "Deleting page $title...\n"; - - # Get the delete page contents - my $deletePage = http::getPage( $title, "delete" ); - - # Get the edit token - if ($deletePage =~ /<input type='hidden' name='wpEditToken' value="([0-9,a-f]{32})" \/>/) { - my $editToken = $1; - - # Send page - if ( $configure::sendPages == 1 ) { - http::postPage( $title, "delete", - [ - wpReason => $reason, - wpEditToken => $editToken, - ], - ); - } - print "\tDone!\n"; + if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { + actions::deletePage( $title, getPageContents( $title ), "Refreshing page" ); } else { - print "Error!\nYou may not have the permission to delete pages, or the page is already deleted.\n"; + print "Refreshed page $title.\n"; } } Modified: trunk/includes/http.pm =================================================================== --- trunk/includes/http.pm 2006-09-16 11:45:57 UTC (rev 19) +++ trunk/includes/http.pm 2006-09-16 12:30:18 UTC (rev 20) @@ -55,7 +55,7 @@ # Post a wiki page, try again and again if error sub postPage { # Get parameters - my ($title, $action, $post, $get) = @_; + my ( $title, $action, $post, $get ) = @_; my $url = buildPageURL( $title, $action, $get ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |