Thread: [PerlWikiBot] SF.net SVN: perlwikibot: [15] trunk
Status: Pre-Alpha
Brought to you by:
rotemliss
From: <rot...@us...> - 2006-09-01 11:27:29
|
Revision: 15 http://svn.sourceforge.net/perlwikibot/?rev=15&view=rev Author: rotemliss Date: 2006-09-01 04:27:14 -0700 (Fri, 01 Sep 2006) Log Message: ----------- Fixing typo. Modified Paths: -------------- trunk/bot.pl trunk/includes/functions.pm trunk/old/delete.pl trunk/old/move.pl trunk/old/refresh.pl trunk/old/replace.pl Modified: trunk/bot.pl =================================================================== --- trunk/bot.pl 2006-08-31 14:09:30 UTC (rev 14) +++ trunk/bot.pl 2006-09-01 11:27:14 UTC (rev 15) @@ -4,7 +4,7 @@ use warnings; use strict; -# Libaries +# Libraries use includes::functions; # Counters Modified: trunk/includes/functions.pm =================================================================== --- trunk/includes/functions.pm 2006-08-31 14:09:30 UTC (rev 14) +++ trunk/includes/functions.pm 2006-09-01 11:27:14 UTC (rev 15) @@ -2,7 +2,7 @@ use warnings; use strict; -# Libaries +# Libraries use LWP; use HTTP::Cookies; use includes::mwdump; Modified: trunk/old/delete.pl =================================================================== --- trunk/old/delete.pl 2006-08-31 14:09:30 UTC (rev 14) +++ trunk/old/delete.pl 2006-09-01 11:27:14 UTC (rev 15) @@ -3,7 +3,7 @@ # Code style use warnings; -# Libaries +# Libraries use Time::Local; use functions; use configure; Modified: trunk/old/move.pl =================================================================== --- trunk/old/move.pl 2006-08-31 14:09:30 UTC (rev 14) +++ trunk/old/move.pl 2006-09-01 11:27:14 UTC (rev 15) @@ -3,7 +3,7 @@ # Code style use warnings; -# Libaries +# Libraries use functions; use configure; Modified: trunk/old/refresh.pl =================================================================== --- trunk/old/refresh.pl 2006-08-31 14:09:30 UTC (rev 14) +++ trunk/old/refresh.pl 2006-09-01 11:27:14 UTC (rev 15) @@ -3,7 +3,7 @@ # Code style use warnings; -# Libaries +# Libraries use mwdump; use functions; use configure; Modified: trunk/old/replace.pl =================================================================== --- trunk/old/replace.pl 2006-08-31 14:09:30 UTC (rev 14) +++ trunk/old/replace.pl 2006-09-01 11:27:14 UTC (rev 15) @@ -3,7 +3,7 @@ # Code style use warnings; -# Libaries +# Libraries use functions; use configure; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rot...@us...> - 2006-09-16 10:54:55
|
Revision: 17 http://svn.sourceforge.net/perlwikibot/?rev=17&view=rev Author: rotemliss Date: 2006-09-16 03:54:41 -0700 (Sat, 16 Sep 2006) Log Message: ----------- Use namespaces, and directly access the variables instead of using many functions. Modified Paths: -------------- trunk/bot.pl trunk/config/configure.sample trunk/config/runtime.sample trunk/includes/dump.pm trunk/includes/functions.pm trunk/includes/http.pm Modified: trunk/bot.pl =================================================================== --- trunk/bot.pl 2006-09-01 16:04:29 UTC (rev 16) +++ trunk/bot.pl 2006-09-16 10:54:41 UTC (rev 17) @@ -6,6 +6,8 @@ # Libraries use includes::functions; +use config::configure; +use config::runtime; # Counters my ($i, $j, $k, $l, $m); @@ -17,34 +19,34 @@ } # Show notes about the sending pages configuration -if (sendPages() == 0) +if ($configure::sendPages == 0) { print "Note: There will be no changes in the real server. Please set sendPages to 1 to do them.\n"; } -elsif (sendPages() == 2) +elsif ($configure::sendPages == 2) { print "Note: A prefix will be used when editing pages. Please set sendPages to 1 to disable that.\n"; } # Log in to the server only if you have to do some stuff in the server -if (connectToServer()) +if ($configure::sendPages == 1 || $configure::sendPages == 2) { - login(); + functions::login(); } # All the matching pages in the XML file -my @pages = getMatchingPages(); +my @pages = functions::getMatchingPages(); # Execute actions of all the pages for ($i = 0; ($i <= $#pages); $i += 2) { # Get title and action my $title = $pages[$i]; - my $action = action($pages[$i + 1]); + my $action = $configure::actions{$pages[$i + 1]}; # Execute the action (TODO: add the actions which were supported in the previous bot) if ($action eq "replace") { - replaceInPage($title); + functions::replaceInPage($title); } } Modified: trunk/config/configure.sample =================================================================== --- trunk/config/configure.sample 2006-09-01 16:04:29 UTC (rev 16) +++ trunk/config/configure.sample 2006-09-16 10:54:41 UTC (rev 17) @@ -1,3 +1,6 @@ +# Package name +package configure; + # Code style use warnings; use strict; @@ -9,165 +12,56 @@ my ($i, $j, $k, $l, $m); # Available servers and details about them, the bot should work on -my %servers = ( +our %servers = ( "server" => "http://www.server.com", ); # The MediaWiki Server -my %scriptPaths = ( +our %scriptPaths = ( "server" => "/w/index.php", ); # The path to the script index.php (or wiki.phtml in old versions) -my %userNames = ( +our %userNames = ( "server" => "My-bot", ); # The bot user name in every server -my %passwords = ( +our %passwords = ( "server" => "password" ); # The bot password in every server -my %sysopUserNames = ( +our %sysopUserNames = ( "server" => "My-sysop", ); # The sysop bot user name in every server, blank if no -my %sysopPasswords = ( +our %sysopPasswords = ( "server" => "strong_password", ); # The sysop bot password in every server, blank if no -my %xmlFiles = ( +our %xmlFiles = ( "server" => "site.xml", ); # The XML file of the database -my %initialEditSummaries = ( +our %initialEditSummaries = ( "server" => "[[Project:Replace bot|Replace bot]] – " ); # Initial edit summary, when several replaces are done and several edit summaries are integrated, using the replace script -my %serverPrefixes = ( +our %serverPrefixes = ( "server" => "User:My-bot/Tests/", ); # Prefixes for the saved pages for tests; won't be used when really running the script # Avilable actions and details about them -my %actions = ( +our %actions = ( "action" => "move" ); # The global actions done -my %actionServers = ( +our %actionServers = ( "action" => "server" ); # Which server should it be executed on? TODO - allow using multiple servers like that, currently ignored -my %titles = ( +our %titles = ( "action" => "^שיחת משתמש:[\\d]+\\.[\\d]+\\.[\\d]+\\.[\\d]+\$" ); # Restrict the actions to these titles -my %texts = ( +our %texts = ( "action" => "^אנונימי\$" ); # Restrict the actions to the pages -my %news = ( +our %news = ( "action" => "שיחת משתמש:אנונימי" ); # New title (move) or text (replace), leave blank otherwise -my %reasons = ( +our %reasons = ( "action" => "מחליף שיחות אנונימיות" ); # Summary/reason sent about the action -my %minimumTimes = ( +our %minimumTimes = ( "action" => timegm(0, 0, 0, 1, 1 - 1, 1970 - 1900) ); # The minimum diff between the current time and the last edit time -sub server -{ - $servers{$ARGV[0]}; # Return -} - -sub scriptPath -{ - $scriptPaths{$ARGV[0]}; # Return -} - -sub userName -{ - # Return the appropriate user name, if the sysop is needed or not, - # using the parameter - if ($_[0] == 1) - { - $sysopUserNames{$ARGV[0]}; # Return - } - else - { - $userNames{$ARGV[0]}; # Return - } -} - -sub password -{ - # Return the appropriate user name, if the sysop is needed or not, - # using the parameter - if ($_[0] == 1) - { - $sysopPasswords{$ARGV[0]}; # Return - } - else - { - $passwords{$ARGV[0]}; # Return - } -} - -sub xmlFile -{ - $xmlFiles{$ARGV[0]}; # Return -} - -sub initialEditSummary -{ - $initialEditSummaries{$ARGV[0]}; # Return -} - -sub serverPrefix -{ - $serverPrefixes{$ARGV[0]}; # Return -} - -sub action -{ - # Get parameter - my $actionName = $_[0]; - - $actions{$actionName}; # Return -} - -sub actionServer -{ - # Get parameter - my $actionName = $_[0]; - - $actionServers{$actionName}; # Return -} - -sub title -{ - # Get parameter - my $actionName = $_[0]; - - $titles{$actionName}; # Return -} - -sub text -{ - # Get parameter - my $actionName = $_[0]; - - $texts{$actionName}; # Return -} - -sub new -{ - # Get parameter - my $actionName = $_[0]; - - $news{$actionName}; # Return -} - -sub reason -{ - # Get parameter - my $actionName = $_[0]; - - $reasons{$actionName}; # Return -} - -sub minimumTime -{ - # Get parameter - my $actionName = $_[0]; - - $minimumTimes{$actionName}; # Return -} - # Return a true value 1; Modified: trunk/config/runtime.sample =================================================================== --- trunk/config/runtime.sample 2006-09-01 16:04:29 UTC (rev 16) +++ trunk/config/runtime.sample 2006-09-16 10:54:41 UTC (rev 17) @@ -1,3 +1,6 @@ +# Package name +package configure; + # Code style use warnings; use strict; @@ -6,12 +9,12 @@ my ($i, $j, $k, $l, $m); # Actions to execute -my @executedActions = ( +our @executedActions = ( "action" ); # Actions to execute by the way, if you are already editing the page (replace only) -my @bywayActions = ( +our @bywayActions = ( "actionB" ); @@ -22,35 +25,7 @@ # * 2 - send to the server with prefix when editing (if not, don't send at all). # It's strongly recommended that you use 0 before making tests, and 2 before more # advanced tests, before you use 1 for the real changes. -my $sendPages = 0; +our $sendPages = 0; -sub executedActions -{ - @executedActions; # Return -} - -sub bywayActions -{ - @bywayActions; # Return -} - -sub sendPages -{ - $sendPages; # Return -} - -# Check if we have to connect to server -sub connectToServer -{ - if ($sendPages == 1 || $sendPages == 2) - { - 1; # Return - } - else - { - 0; # Return - } -} - # Return a true value 1; Modified: trunk/includes/dump.pm =================================================================== --- trunk/includes/dump.pm 2006-09-01 16:04:29 UTC (rev 16) +++ trunk/includes/dump.pm 2006-09-16 10:54:41 UTC (rev 17) @@ -4,7 +4,7 @@ #and shifting values for subroutine input should be avoided in #any subroutines that get called often, like the handlers -package Parse::MediaWikiDump::Pages; +package mwdump; #This parser works by placing all of the start, text, and end events into #a buffer as they come out of XML::Parser. On each call to page() the function Modified: trunk/includes/functions.pm =================================================================== --- trunk/includes/functions.pm 2006-09-01 16:04:29 UTC (rev 16) +++ trunk/includes/functions.pm 2006-09-16 10:54:41 UTC (rev 17) @@ -1,3 +1,6 @@ +# Package name +package functions; + # Code style use warnings; use strict; @@ -15,7 +18,7 @@ sub getMatchingPages { # Get the pages - my $pages = Parse::MediaWikiDump::Pages->new(xmlFile()); + my $pages = mwdump->new("dumps/".$configure::xmlFiles{$ARGV[0]}); # Can use only "first-letter", TODO: enable also "case-sensitive" for Wiktionary if ($pages->case ne "first-letter") @@ -24,7 +27,7 @@ } # Get the executed actions - my @possibleActions = executedActions(); + my @possibleActions = @configure::executedActions; # An array contains all the pages my @matchingPages; @@ -49,7 +52,7 @@ $tempCounter = 0; for ($i = 0; ($i <= $#pagePossibleActions); $i++) { - my $wantedTitle = title($pagePossibleActions[$i]); + my $wantedTitle = $configure::titles{$pagePossibleActions[$i]}; if ($title =~ /$wantedTitle/) { $tempTitleArray[$tempCounter++] = $pagePossibleActions[$i]; @@ -70,7 +73,7 @@ $tempCounter = 0; for ($i = 0; ($i <= $#pagePossibleActions); $i++) { - my $wantedText = text($pagePossibleActions[$i]); + my $wantedText = $configure::texts{$pagePossibleActions[$i]}; if ($$text =~ /$wantedText/) { $tempTextArray[$tempCounter++] = $pagePossibleActions[$i]; @@ -131,16 +134,13 @@ # Log in sub login { - # Get all the executed actions - my @executedActions = executedActions(); - - # Sysop finally required? + # Is sysop finally required? my $sysop = 0; # Go through the array, and check if sysop permission is needed. - for ($i = 0; ($i <= $#executedActions); $i++) + for ($i = 0; ($i <= $#configure::executedActions); $i++) { - my $action = action($executedActions[$i]); + my $action = $configure::actions{$configure::executedActions[$i]}; if ($action eq "replace") { # Continue @@ -159,12 +159,25 @@ } } + # 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"; - postPage("Special:Userlogin", "submitlogin", + http::postPage("Special:Userlogin", "submitlogin", [ - wpName => userName($sysop), - wpPassword => password($sysop), + wpName => $username, + wpPassword => $password, wpRemember => 0 ], , "type=login"); @@ -177,7 +190,7 @@ # Get parameters my $title = $_[0]; - getPage($title, "raw"); # Return + http::getPage($title, "raw"); # Return } # Edit page @@ -190,13 +203,14 @@ print "Editing page $title...\n"; - if (sendPages() == 2) + if ($configure::sendPages == 2) { - $title = serverPrefix().$title; + my $serverPrefix = $configure::serverPrefixes{$ARGV[0]}; + $title = $serverPrefix.$title; } # Get the edit page contents - my $editPage = getPage($title, "edit"); + my $editPage = http::getPage($title, "edit"); # Get the start time $editPage =~ /<input type='hidden' value="([0-9]{14})" name="wpStarttime" \/>/; @@ -211,11 +225,11 @@ my $editToken = $1; # Send page - if ((defined($editToken)) && ($editToken =~ /[0-9a-f]{32}/)) + if (defined($editToken) && $editToken =~ /[0-9a-f]{32}/) { - if ((sendPages() == 1) || (sendPages() == 2)) + if ($configure::sendPages == 1 || $configure::sendPages == 2) { - postPage($title, "submit", + http::postPage($title, "submit", [ wpSection => "", wpStarttime => $startTime, @@ -241,16 +255,16 @@ # Get parameters my $title = $_[0]; - if (connectToServer()) + if ($configure::sendPages == 1 || $configure::sendPages == 2) { # Get the edited page contents my $editedPage = getPageContents($title); # Set initial edit summary - my $editSummary = initialEditSummary(); + my $editSummary = $configure::initialEditSummaries{$ARGV[0]}; # Groups array - my @actions = (executedActions(), bywayActions()); + my @actions = (@configure::executedActions, @configure::bywayActions); # Replaced something at all? Flag to check my $replaced = 0; @@ -259,16 +273,16 @@ for ($i = 0; ($i <= $#actions); $i++) { my $action = $actions[$i]; - my $search = text($action); + my $search = $configure::texts{$action}; if ($editedPage =~ /$search/) { - my $replace = new($action); + my $replace = $configure::news{$action}; $editedPage =~ s/$search/$replace/g; if ($replaced == 1) { $editSummary = $editSummary.", "; } - $editSummary = $editSummary.reason($action); + $editSummary = $editSummary.$configure::reasons{$action}; $replaced = 1; } } @@ -307,7 +321,7 @@ print "Moving page $title to $newTitle...\n"; # Get the delete page contents - my $movePage = getPage("Special:Movepage/$title"); + my $movePage = http::getPage("Special:Movepage/$title"); # Get the edit token if ($movePage =~ /<input type='hidden' name='wpEditToken' value="([0-9,a-f]{32})" \/>/) @@ -315,9 +329,9 @@ my $editToken = $1; # Send page - if (sendPages() == 1) + if ($configure::sendPages == 1) { - postPage("Special:Movepage", "submit", + http::postPage("Special:Movepage", "submit", [ wpOldTitle => $title, wpNewTitle => $newTitle, @@ -345,7 +359,7 @@ print "Deleting page $title...\n"; # Get the delete page contents - my $deletePage = getPage($title, "delete"); + my $deletePage = http::getPage($title, "delete"); # Get the edit token if ($deletePage =~ /<input type='hidden' name='wpEditToken' value="([0-9,a-f]{32})" \/>/) @@ -353,9 +367,9 @@ my $editToken = $1; # Send page - if (sendPages() == 1) + if ($configure::sendPages == 1) { - postPage($title, "delete", + http::postPage($title, "delete", [ wpReason => $deleteReason, wpEditToken => $editToken Modified: trunk/includes/http.pm =================================================================== --- trunk/includes/http.pm 2006-09-01 16:04:29 UTC (rev 16) +++ trunk/includes/http.pm 2006-09-16 10:54:41 UTC (rev 17) @@ -1,3 +1,6 @@ +# Package name +package http; + # Code style use warnings; use strict; @@ -4,6 +7,7 @@ # Libraries use LWP; +use config::configure; # Counters my ($i, $j, $k, $l, $m); @@ -22,7 +26,9 @@ my $get = $_[2]; # Initial URL: server, script path and title - my $url = server().scriptPath()."?title=$title"; + my $server = $configure::servers{$ARGV[0]}; + my $scriptPath = $configure::scriptPaths{$ARGV[0]}; + my $url = "$server$scriptPath?title=$title"; # Action if (defined($action)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rot...@us...> - 2006-09-16 11:46:09
|
Revision: 19 http://svn.sourceforge.net/perlwikibot/?rev=19&view=rev Author: rotemliss Date: 2006-09-16 04:45:57 -0700 (Sat, 16 Sep 2006) Log Message: ----------- Reformatting the code: whitespaces, code style, return statements, etc. Modified Paths: -------------- trunk/bot.pl trunk/config/configure.sample trunk/config/runtime.sample trunk/includes/functions.pm trunk/includes/http.pm Modified: trunk/bot.pl =================================================================== --- trunk/bot.pl 2006-09-16 11:06:13 UTC (rev 18) +++ trunk/bot.pl 2006-09-16 11:45:57 UTC (rev 19) @@ -10,27 +10,22 @@ use config::runtime; # Counters -my ($i, $j, $k, $l, $m); +my ( $i, $j, $k, $l, $m ); # Do nothing if no server specified -if (!$ARGV[0]) -{ - die("No server name set - please set server name!\n"); +if ( !$ARGV[0] ) { + die "No server name set - please set server name!\n"; } # Show notes about the sending pages configuration -if ($configure::sendPages == 0) -{ +if ( $configure::sendPages == 0 ) { print "Note: There will be no changes in the real server. Please set sendPages to 1 to do them.\n"; -} -elsif ($configure::sendPages == 2) -{ +} elsif ( $configure::sendPages == 2 ) { print "Note: A prefix will be used when editing pages. Please set sendPages to 1 to disable that.\n"; } # Log in to the server only if you have to do some stuff in the server -if ($configure::sendPages == 1 || $configure::sendPages == 2) -{ +if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { functions::login(); } @@ -38,15 +33,13 @@ my @pages = functions::getMatchingPages(); # Execute actions of all the pages -for ($i = 0; ($i <= $#pages); $i += 2) -{ +for ( $i = 0; $i <= $#pages; $i += 2 ) { # Get title and action my $title = $pages[$i]; - my $action = $configure::actions{$pages[$i + 1]}; - + my $action = $configure::actions{ $pages[$i + 1] }; + # Execute the action (TODO: add the actions which were supported in the previous bot) - if ($action eq "replace") - { - functions::replaceInPage($title); + if ( $action eq "replace" ) { + functions::replaceInPage( $title ); } } Modified: trunk/config/configure.sample =================================================================== --- trunk/config/configure.sample 2006-09-16 11:06:13 UTC (rev 18) +++ trunk/config/configure.sample 2006-09-16 11:45:57 UTC (rev 19) @@ -8,9 +8,6 @@ # Libraries use Time::local; -# Counters -my ($i, $j, $k, $l, $m); - # Available servers and details about them, the bot should work on our %servers = ( "server" => "http://www.server.com", @@ -34,7 +31,7 @@ "server" => "site.xml", ); # The XML file of the database our %initialEditSummaries = ( - "server" => "[[Project:Replace bot|Replace bot]] – " + "server" => "[[Project:Replace bot|Replace bot]] – ", ); # Initial edit summary, when several replaces are done and several edit summaries are integrated, using the replace script our %serverPrefixes = ( "server" => "User:My-bot/Tests/", @@ -42,26 +39,25 @@ # Avilable actions and details about them our %actions = ( - "action" => "move" + "action" => "move", ); # The global actions done our %actionServers = ( - "action" => "server" + "action" => "server", ); # Which server should it be executed on? TODO - allow using multiple servers like that, currently ignored our %titles = ( - "action" => "^שיחת משתמש:[\\d]+\\.[\\d]+\\.[\\d]+\\.[\\d]+\$" + "action" => "^שיחת משתמש:[\\d]+\\.[\\d]+\\.[\\d]+\\.[\\d]+\$", ); # Restrict the actions to these titles our %texts = ( - "action" => "^אנונימי\$" + "action" => "^אנונימי\$", ); # Restrict the actions to the pages our %news = ( - "action" => "שיחת משתמש:אנונימי" + "action" => "שיחת משתמש:אנונימי", ); # New title (move) or text (replace), leave blank otherwise our %reasons = ( - "action" => "מחליף שיחות אנונימיות" + "action" => "מחליף שיחות אנונימיות", ); # Summary/reason sent about the action our %minimumTimes = ( - "action" => timegm(0, 0, 0, 1, 1 - 1, 1970 - 1900) + "action" => timegm( 0, 0, 0, 1, 1 - 1, 1970 - 1900 ), ); # The minimum diff between the current time and the last edit time -# Return a true value -1; +return 1; Modified: trunk/config/runtime.sample =================================================================== --- trunk/config/runtime.sample 2006-09-16 11:06:13 UTC (rev 18) +++ trunk/config/runtime.sample 2006-09-16 11:45:57 UTC (rev 19) @@ -5,17 +5,14 @@ use warnings; use strict; -# Counters -my ($i, $j, $k, $l, $m); - # Actions to execute our @executedActions = ( - "action" + "action", ); # Actions to execute by the way, if you are already editing the page (replace only) our @bywayActions = ( - "actionB" + "actionB", ); # This variable enables and disables the actual sends to the server. @@ -27,5 +24,4 @@ # advanced tests, before you use 1 for the real changes. our $sendPages = 0; -# Return a true value -1; +return 1; Modified: trunk/includes/functions.pm =================================================================== --- trunk/includes/functions.pm 2006-09-16 11:06:13 UTC (rev 18) +++ trunk/includes/functions.pm 2006-09-16 11:45:57 UTC (rev 19) @@ -12,221 +12,191 @@ use config::runtime; # Counters -my ($i, $j, $k, $l, $m); +my ( $i, $j, $k, $l, $m ); # Get all the pages matching specific restrictions -sub getMatchingPages -{ +sub getMatchingPages { # Get the pages - my $pages = mwdump->new("dumps/".$configure::xmlFiles{$ARGV[0]}); - + my $pages = mwdump->new( "dumps/".$configure::xmlFiles{ $ARGV[0] } ); + # Can use only "first-letter", TODO: enable also "case-sensitive" for Wiktionary - if ($pages->case ne "first-letter") - { + if ( $pages->case ne "first-letter" ) { die "Unable to handle any case setting besides \"first-letter\".\n"; } - + # Get the executed actions my @possibleActions = @configure::executedActions; - + # An array contains all the pages my @matchingPages; - + # Reset counter my $counter = 0; - + # Iterate over all the pages print "Checking all the pages...\n"; - while (my $page = $pages->page) - { + while ( my $page = $pages->page ) { # Temporary array counter my $tempCounter; - + # Get the page possible actions my @pagePossibleActions = @possibleActions; - + # Check if the page title matches to one of the titles my @tempTitleArray; my $title = $page->title; - utf8::encode($title); + utf8::encode( $title ); $tempCounter = 0; - for ($i = 0; ($i <= $#pagePossibleActions); $i++) - { - my $wantedTitle = $configure::titles{$pagePossibleActions[$i]}; - if ($title =~ /$wantedTitle/) - { + for ( $i = 0; $i <= $#pagePossibleActions; $i++ ) { + my $wantedTitle = $configure::titles{ $pagePossibleActions[$i] }; + if ( $title =~ /$wantedTitle/ ) { $tempTitleArray[$tempCounter++] = $pagePossibleActions[$i]; } } - + # Continue if there are no matching pages @pagePossibleActions = @tempTitleArray; - if ($#pagePossibleActions < 0) - { + if ( $#pagePossibleActions < 0 ) { next; } - + # Check if the page text matches to one of the texts my @tempTextArray; my $text = $page->text; - utf8::encode($$text); + utf8::encode( $$text ); $tempCounter = 0; - for ($i = 0; ($i <= $#pagePossibleActions); $i++) - { - my $wantedText = $configure::texts{$pagePossibleActions[$i]}; - if ($$text =~ /$wantedText/) - { + for ( $i = 0; $i <= $#pagePossibleActions; $i++ ) { + my $wantedText = $configure::texts{ $pagePossibleActions[$i] }; + if ($$text =~ /$wantedText/) { $tempTextArray[$tempCounter++] = $pagePossibleActions[$i]; } } - + # Continue if there are no matching pages @pagePossibleActions = @tempTextArray; - if ($#pagePossibleActions < 0) - { + if ( $#pagePossibleActions < 0 ) { next; } - + # All the previous checks were OK - add the page, using the first available action $matchingPages[$counter++] = $title; $matchingPages[$counter++] = $pagePossibleActions[0]; } print "\tDone!\n"; - - @matchingPages; # Return + + return @matchingPages; } # Get page last edit # TODO: Move to getMatchingPages -sub getPageLastEdit -{ +sub getPageLastEdit { # Get parameters - my ($xmlFile, $title) = @_; - utf8::decode($title); - + my ( $xmlFile, $title ) = @_; + utf8::decode( $title ); + # Get the pages - my $pages = Parse::MediaWikiDump::Pages->new($xmlFile); - + my $pages = mwdump->new($xmlFile); + # Can use only "first-letter", which is also the only currently known value, # but there could be more in the future - if ($pages->case ne "first-letter") - { + if ( $pages->case ne "first-letter" ) { die "Unable to handle any case setting besides \"first-letter\".\n"; } - + # Searching for the page, and getting its timestamp my $lastEditTimestamp = "0"; - while (($lastEditTimestamp eq "0") && (my $page = $pages->page)) - { - if ($title eq $page->title) - { + while ( $lastEditTimestamp eq "0" && ( my $page = $pages->page ) ) { + if ( $title eq $page->title ) { $lastEditTimestamp = $page->timestamp; } } - + # Check the time by RegExp $lastEditTimestamp =~ /([\d]+)-([\d]+)-([\d]+)T([\d]+):([\d]+):([\d]+)Z/; - - timegm($6, $5, $4, $3, $2 - 1, $1 - 1900); # Return + + return timegm( $6, $5, $4, $3, $2 - 1, $1 - 1900 ); } # Log in -sub login -{ +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") - { + for ( $i = 0; $i <= $#configure::executedActions; $i++ ) { + my $action = $configure::actions{ $configure::executedActions[$i] }; + if ( $action eq "replace" ) { # Continue - } - elsif ($action eq "refresh") - { + } elsif ($action eq "refresh") { # Continue - } - elsif ($action eq "delete") - { + } elsif ($action eq "delete") { $sysop = 1; - } - elsif ($action eq "move") - { + } 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]}; + 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] }; } - else - { - $username = $configure::userNames{$ARGV[0]}; - $password = $configure::passwords{$ARGV[0]}; - } - + # Log in print "Logging in...\n"; - http::postPage("Special:Userlogin", "submitlogin", + http::postPage( "Special:Userlogin", "submitlogin", [ wpName => $username, wpPassword => $password, - wpRemember => 0 + wpRemember => 0, ], - , "type=login"); + , "type=login" ); print "\tDone!\n"; } # Get the contents of a page -sub getPageContents -{ +sub getPageContents { # Get parameters - my ($title) = @_; - - http::getPage($title, "raw"); # Return + my ( $title ) = @_; + + return http::getPage( $title, "raw" ); } # Edit page -sub editPage -{ +sub editPage { # Get parameters - my ($title, $text, $editSummary) = @_; - + my ( $title, $text, $editSummary ) = @_; + print "Editing page $title...\n"; - - if ($configure::sendPages == 2) - { - my $serverPrefix = $configure::serverPrefixes{$ARGV[0]}; + + if ( $configure::sendPages == 2 ) { + my $serverPrefix = $configure::serverPrefixes{ $ARGV[0] }; $title = $serverPrefix.$title; } - + # Get the edit page contents - my $editPage = http::getPage($title, "edit"); - + 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", + if ( defined( $editToken ) && $editToken =~ /[0-9a-f]{32}/ ) { + if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { + http::postPage( $title, "submit", [ wpSection => "", wpStarttime => $startTime, @@ -234,102 +204,88 @@ wpEditToken => $editToken, wpSummary => $editSummary, wpTextbox1 => $text, - wpMinoredit => 1 + wpMinoredit => 1, ], ); } print "\tDone!\n"; - } - else - { + } 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 -{ +sub replaceInPage { # Get parameters my ($title) = @_; - - if ($configure::sendPages == 1 || $configure::sendPages == 2) - { + + if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { # Get the edited page contents - my $editedPage = getPageContents($title); - + my $editedPage = getPageContents( $title ); + # Set initial edit summary - my $editSummary = $configure::initialEditSummaries{$ARGV[0]}; - + my $editSummary = $configure::initialEditSummaries{ $ARGV[0] }; + # Groups array - my @actions = (@configure::executedActions, @configure::bywayActions); - + my @actions = ( @configure::executedActions, @configure::bywayActions ); + # Replaced something at all? Flag to check my $replaced = 0; - + # Replace regular expressions - for ($i = 0; ($i <= $#actions); $i++) - { + for ( $i = 0; $i <= $#actions; $i++ ) { my $action = $actions[$i]; - my $search = $configure::texts{$action}; - if ($editedPage =~ /$search/) - { - my $replace = $configure::news{$action}; + my $search = $configure::texts{ $action }; + if ( $editedPage =~ /$search/ ) { + my $replace = $configure::news{ $action }; $editedPage =~ s/$search/$replace/g; - if ($replaced == 1) - { - $editSummary = $editSummary.", "; + if ( $replaced == 1 ) { + $editSummary = "$editSummary, "; } - $editSummary = $editSummary.$configure::reasons{$action}; + $editSummary = $editSummary.$configure::reasons{ $action }; $replaced = 1; } } - + # Edit page only of replaced something - if ($replaced == 1) - { - editPage($title, $editedPage, $editSummary); + if ( $replaced == 1 ) { + editPage( $title, $editedPage, $editSummary ); } - } - else - { + } else { print "Replaced in page $title.\n"; } } # Refresh page -sub refreshPage -{ +sub refreshPage { # Get parameters - my ($server, $title) = @_; - - editPage($title, getPageContents($title), "Refreshing page"); + my ( $server, $title ) = @_; + + editPage( $title, getPageContents( $title ), "Refreshing page" ); } # Move page -sub movePage -{ +sub movePage { # Get parameters - my ($server, $title, $newTitle, $moveReason) = @_; - + my ( $server, $title, $newTitle, $moveReason ) = @_; + print "Moving page $title to $newTitle...\n"; - + # Get the delete page contents - my $movePage = http::getPage("Special:Movepage/$title"); - + my $movePage = http::getPage( "Special:Movepage/$title" ); + # Get the edit token - if ($movePage =~ /<input type='hidden' name='wpEditToken' value="([0-9,a-f]{32})" \/>/) - { + 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", + if ( $configure::sendPages == 1 ) { + http::postPage( "Special:Movepage", "submit", [ wpOldTitle => $title, wpNewTitle => $newTitle, wpReason => $moveReason, - wpEditToken => $editToken + wpEditToken => $editToken, ], ); } @@ -342,38 +298,32 @@ } # Delete page -sub deletePage -{ +sub deletePage { # Get parameters - my ($server, $title, $reason) = @_; - + my ( $server, $title, $reason ) = @_; + print "Deleting page $title...\n"; - + # Get the delete page contents - my $deletePage = http::getPage($title, "delete"); - + my $deletePage = http::getPage( $title, "delete" ); + # Get the edit token - if ($deletePage =~ /<input type='hidden' name='wpEditToken' value="([0-9,a-f]{32})" \/>/) - { + 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", + if ( $configure::sendPages == 1 ) { + http::postPage( $title, "delete", [ wpReason => $reason, - wpEditToken => $editToken + wpEditToken => $editToken, ], ); } print "\tDone!\n"; - } - else - { + } else { print "Error!\nYou may not have the permission to delete pages, or the page is already deleted.\n"; } } -# Return a true value -1; +return 1; Modified: trunk/includes/http.pm =================================================================== --- trunk/includes/http.pm 2006-09-16 11:06:13 UTC (rev 18) +++ trunk/includes/http.pm 2006-09-16 11:45:57 UTC (rev 19) @@ -9,72 +9,62 @@ use LWP; use config::configure; -# Counters -my ($i, $j, $k, $l, $m); - # The browser we use to surf; enable cookies, and use a specific user agent -my $browser = LWP::UserAgent->new; -$browser->cookie_jar({}); -$browser->agent("Mozilla/5.0 (compatible; Perl MediaWiki Robot)"); +my $browser = LWP::UserAgent->new(); +$browser->cookie_jar( {} ); +$browser->agent( "Mozilla/5.0 (compatible; Perl MediaWiki Robot)" ); # Build the URL of a wiki page -sub buildPageURL -{ +sub buildPageURL { # Get parameters - my ($title, $action, $get) = @_; - + my ( $title, $action, $get ) = @_; + # Initial URL: server, script path and title - my $server = $configure::servers{$ARGV[0]}; - my $scriptPath = $configure::scriptPaths{$ARGV[0]}; + my $server = $configure::servers{ $ARGV[0] }; + my $scriptPath = $configure::scriptPaths{ $ARGV[0] }; my $url = "$server$scriptPath?title=$title"; - + # Action - if (defined($action)) - { + if ( defined( $action ) ) { $url = "$url&action=$action"; } - + # Parameters - if (defined($get)) - { + if ( defined( $get ) ) { $url = "$url&$get"; } - - $url; # Return + + return $url; } # Get a wiki page, try again and again if error -sub getPage -{ +sub getPage { # Get parameters - my ($title, $action, $get) = @_; - - my $url = buildPageURL($title, $action, $get); - + my ( $title, $action, $get ) = @_; + + my $url = buildPageURL( $title, $action, $get ); + my $result; - do - { - $result = $browser->get($url); - } - while (!$result->is_success && $result->status_line =~ /302[\s\w]+/); - - $result->content; # Return + do { + $result = $browser->get( $url ); + } while ( !$result->is_success && $result->status_line =~ /302[\s\w]+/ ); + + return $result->content; } # Post a wiki page, try again and again if error -sub postPage -{ +sub postPage { # Get parameters my ($title, $action, $post, $get) = @_; - - my $url = buildPageURL($title, $action, $get); - + + my $url = buildPageURL( $title, $action, $get ); + my $result; - do - { - $result = $browser->post($url, $post); - } - while (!$result->is_success && !$result->status_line =~ /302[\s\w]+/); - - $result->content; # Return + do { + $result = $browser->post( $url, $post ); + } while ( !$result->is_success && !$result->status_line =~ /302[\s\w]+/ ); + + return $result->content; } + +return 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <rot...@us...> - 2006-09-16 12:48:19
|
Revision: 21 http://svn.sourceforge.net/perlwikibot/?rev=21&view=rev Author: rotemliss Date: 2006-09-16 05:48:10 -0700 (Sat, 16 Sep 2006) Log Message: ----------- Several fixes. Modified Paths: -------------- trunk/bot.pl trunk/includes/actions.pm trunk/includes/functions.pm trunk/includes/http.pm Modified: trunk/bot.pl =================================================================== --- trunk/bot.pl 2006-09-16 12:30:18 UTC (rev 20) +++ trunk/bot.pl 2006-09-16 12:48:10 UTC (rev 21) @@ -5,13 +5,14 @@ use strict; # Libraries +use LWP::UserAgent; +use includes::actions; +use includes::dump; use includes::functions; +use includes::http; use config::configure; use config::runtime; -# Counters -my ( $i, $j, $k, $l, $m ); - # Do nothing if no server specified if ( !$ARGV[0] ) { die "No server name set - please set server name!\n"; @@ -33,7 +34,7 @@ my @pages = functions::getMatchingPages(); # Execute actions of all the pages -for ( $i = 0; $i <= $#pages; $i += 2 ) { +for ( my $i = 0; $i <= $#pages; $i += 2 ) { # Get title and action my $title = $pages[$i]; my $action = $configure::actions{ $pages[$i + 1] }; Modified: trunk/includes/actions.pm =================================================================== --- trunk/includes/actions.pm 2006-09-16 12:30:18 UTC (rev 20) +++ trunk/includes/actions.pm 2006-09-16 12:48:10 UTC (rev 21) @@ -5,55 +5,6 @@ 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 Modified: trunk/includes/functions.pm =================================================================== --- trunk/includes/functions.pm 2006-09-16 12:30:18 UTC (rev 20) +++ trunk/includes/functions.pm 2006-09-16 12:48:10 UTC (rev 21) @@ -5,15 +5,6 @@ use warnings; use strict; -# Libraries -use includes::actions; -use includes::dump; -use config::configure; -use config::runtime; - -# Counters -my ( $i, $j, $k, $l, $m ); - # Get all the pages matching specific restrictions sub getMatchingPages { # Get the pages @@ -47,7 +38,7 @@ my $title = $page->title; utf8::encode( $title ); $tempCounter = 0; - for ( $i = 0; $i <= $#pagePossibleActions; $i++ ) { + for ( my $i = 0; $i <= $#pagePossibleActions; $i++ ) { my $wantedTitle = $configure::titles{ $pagePossibleActions[$i] }; if ( $title =~ /$wantedTitle/ ) { $tempTitleArray[$tempCounter++] = $pagePossibleActions[$i]; @@ -65,7 +56,7 @@ my $text = $page->text; utf8::encode( $$text ); $tempCounter = 0; - for ( $i = 0; $i <= $#pagePossibleActions; $i++ ) { + for ( my $i = 0; $i <= $#pagePossibleActions; $i++ ) { my $wantedText = $configure::texts{ $pagePossibleActions[$i] }; if ($$text =~ /$wantedText/) { $tempTextArray[$tempCounter++] = $pagePossibleActions[$i]; @@ -117,6 +108,47 @@ 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 ( my $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"; +} + # Replace regular expressions in the page sub replaceInPage { # Get parameters @@ -124,7 +156,7 @@ if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { # Get the edited page contents - my $editedPage = getPageContents( $title ); + my $editedPage = actions::getPageContents( $title ); # Set initial edit summary my $editSummary = $configure::initialEditSummaries{ $ARGV[0] }; @@ -136,7 +168,7 @@ my $replaced = 0; # Replace regular expressions - for ( $i = 0; $i <= $#actions; $i++ ) { + for ( my $i = 0; $i <= $#actions; $i++ ) { my $action = $actions[$i]; my $search = $configure::texts{ $action }; if ( $editedPage =~ /$search/ ) { Modified: trunk/includes/http.pm =================================================================== --- trunk/includes/http.pm 2006-09-16 12:30:18 UTC (rev 20) +++ trunk/includes/http.pm 2006-09-16 12:48:10 UTC (rev 21) @@ -5,10 +5,6 @@ use warnings; use strict; -# Libraries -use LWP; -use config::configure; - # The browser we use to surf; enable cookies, and use a specific user agent my $browser = LWP::UserAgent->new(); $browser->cookie_jar( {} ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rot...@us...> - 2006-09-16 13:06:45
|
Revision: 22 http://svn.sourceforge.net/perlwikibot/?rev=22&view=rev Author: rotemliss Date: 2006-09-16 06:06:38 -0700 (Sat, 16 Sep 2006) Log Message: ----------- Adding the ability to specify a server for each action, and ignoring actions which are not executed on the specified server. Modified Paths: -------------- trunk/config/configure.sample trunk/includes/functions.pm Modified: trunk/config/configure.sample =================================================================== --- trunk/config/configure.sample 2006-09-16 12:48:10 UTC (rev 21) +++ trunk/config/configure.sample 2006-09-16 13:06:38 UTC (rev 22) @@ -43,7 +43,7 @@ ); # The global actions done our %actionServers = ( "action" => "server", -); # Which server should it be executed on? TODO - allow using multiple servers like that, currently ignored +); # Which server should it be executed on? our %titles = ( "action" => "^שיחת משתמש:[\\d]+\\.[\\d]+\\.[\\d]+\\.[\\d]+\$", ); # Restrict the actions to these titles Modified: trunk/includes/functions.pm =================================================================== --- trunk/includes/functions.pm 2006-09-16 12:48:10 UTC (rev 21) +++ trunk/includes/functions.pm 2006-09-16 13:06:38 UTC (rev 22) @@ -15,8 +15,8 @@ die "Unable to handle any case setting besides \"first-letter\".\n"; } - # Get the executed actions - my @possibleActions = @configure::executedActions; + # Get the executed actions of the specified server + my @possibleActions = filterActionsList( @configure::executedActions ); # An array contains all the pages my @matchingPages; @@ -108,6 +108,23 @@ return timegm( $6, $5, $4, $3, $2 - 1, $1 - 1900 ); } +# Filter actions list to the specified script server +sub filterActionsList { + # Get parameters + my @originalList = @_; + + # Go over the actions list, and filter the actions which are not in the current server + my @newList; + my $counter = 0; + for ( my $i = 0; $i <= $#originalList; $i++ ) { + if ( $configure::actionServers{ $originalList[$i] } eq $ARGV[0] ) { + $newList[$counter++] = $originalList[$i]; + } + } + + return @newList; +} + # Log in sub login { # Is sysop finally required? @@ -162,7 +179,9 @@ my $editSummary = $configure::initialEditSummaries{ $ARGV[0] }; # Groups array - my @actions = ( @configure::executedActions, @configure::bywayActions ); + my @executedActions = filterActionsList( @configure::executedActions ); + my @bywayActions = filterActionsList( @configure::bywayActions ); + my @actions = ( @executedActions, @bywayActions ); # Replaced something at all? Flag to check my $replaced = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rot...@us...> - 2006-09-16 14:07:29
|
Revision: 25 http://svn.sourceforge.net/perlwikibot/?rev=25&view=rev Author: rotemliss Date: 2006-09-16 07:07:18 -0700 (Sat, 16 Sep 2006) Log Message: ----------- Allowing automated page deletions, and several fixes. Modified Paths: -------------- trunk/bot.pl trunk/includes/actions.pm trunk/includes/functions.pm Modified: trunk/bot.pl =================================================================== --- trunk/bot.pl 2006-09-16 13:28:27 UTC (rev 24) +++ trunk/bot.pl 2006-09-16 14:07:18 UTC (rev 25) @@ -37,12 +37,15 @@ for ( my $i = 0; $i <= $#pages; $i += 2 ) { # Get title and action my $title = $pages[$i]; - my $action = $configure::actions{ $pages[$i + 1] }; + my $action = $pages[$i + 1]; + my $actionName = $configure::actions{ $action }; # Execute the action (TODO: add move and delete) - if ( $action eq "replace" ) { - functions::replaceInPage( $title ); - } elsif ( $action eq "refresh" ) { - functions::refreshPage( $title ); + if ( $actionName eq "replace" ) { + functions::replaceInPage( $title, $action ); + } elsif ( $actionName eq "refresh" ) { + functions::refreshPage( $title, $action ); + } elsif ( $actionName eq "delete" ) { + functions::deletePage( $title, $action ); } } Modified: trunk/includes/actions.pm =================================================================== --- trunk/includes/actions.pm 2006-09-16 13:28:27 UTC (rev 24) +++ trunk/includes/actions.pm 2006-09-16 14:07:18 UTC (rev 25) @@ -17,7 +17,7 @@ # Edit page sub editPage { # Get parameters - my ( $title, $text, $editSummary ) = @_; + my ( $title, $text, $summary ) = @_; print "Editing page $title...\n"; @@ -51,7 +51,7 @@ wpStarttime => $startTime, wpEdittime => $editTime, wpEditToken => $editToken, - wpSummary => $editSummary, + wpSummary => $summary, wpTextbox1 => $text, wpMinoredit => 1, ], @@ -75,12 +75,12 @@ # Move page sub movePage { # Get parameters - my ( $title, $newTitle, $reason ) = @_; + my ( $oldTitle, $newTitle, $reason ) = @_; - print "Moving page $title to $newTitle...\n"; + print "Moving page $oldTitle to $newTitle...\n"; # Get the delete page contents - my $page = http::getPage( "Special:Movepage/$title" ); + my $page = http::getPage( "Special:Movepage/$oldTitle" ); # Get edit token $page =~ /<input type='hidden' name='wpEditToken' value="([0-9,a-f]{32})" \/>/; @@ -91,7 +91,7 @@ if ( $configure::sendPages == 1 ) { http::postPage( "Special:Movepage", "submit", [ - wpOldTitle => $title, + wpOldTitle => $oldTitle, wpNewTitle => $newTitle, wpReason => $reason, wpEditToken => $editToken, Modified: trunk/includes/functions.pm =================================================================== --- trunk/includes/functions.pm 2006-09-16 13:28:27 UTC (rev 24) +++ trunk/includes/functions.pm 2006-09-16 14:07:18 UTC (rev 25) @@ -169,14 +169,15 @@ # Replace regular expressions in the page sub replaceInPage { # Get parameters - my ($title) = @_; + my ( $title, $action ) = @_; + # Send page if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { # Get the edited page contents - my $editedPage = actions::getPageContents( $title ); + my $page = actions::getPageContents( $title ); # Set initial edit summary - my $editSummary = $configure::initialEditSummaries{ $ARGV[0] }; + my $summary = $configure::initialEditSummaries{ $ARGV[0] }; # Groups array my @executedActions = filterActionsList( @configure::executedActions ); @@ -190,20 +191,20 @@ for ( my $i = 0; $i <= $#actions; $i++ ) { my $action = $actions[$i]; my $search = $configure::texts{ $action }; - if ( $editedPage =~ /$search/ ) { + if ( $page =~ /$search/ ) { my $replace = $configure::news{ $action }; - $editedPage =~ s/$search/$replace/g; + $page =~ s/$search/$replace/g; if ( $replaced == 1 ) { - $editSummary = "$editSummary, "; + $summary = "$summary, "; } - $editSummary = $editSummary.$configure::reasons{ $action }; + $summary = $summary.$configure::reasons{ $action }; $replaced = 1; } } # Edit page only of replaced something if ( $replaced == 1 ) { - actions::editPage( $title, $editedPage, $editSummary ); + actions::editPage( $title, $page, $summary ); } } else { print "Replaced in page $title.\n"; @@ -213,8 +214,9 @@ # Refresh page sub refreshPage { # Get parameters - my ( $title ) = @_; + my ( $title, $action ) = @_; + # Send page if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { actions::refreshPage( $title ); } else { @@ -225,10 +227,11 @@ # Delete page sub deletePage { # Get parameters - my ( $title ) = @_; + my ( $title, $action ) = @_; + # Send page if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { - actions::deletePage( $title ); + actions::deletePage( $title, $configure::reasons{ $action } ); } else { print "Deleted page $title.\n"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rot...@us...> - 2006-09-16 14:39:07
|
Revision: 26 http://svn.sourceforge.net/perlwikibot/?rev=26&view=rev Author: rotemliss Date: 2006-09-16 07:38:57 -0700 (Sat, 16 Sep 2006) Log Message: ----------- Allowing page moves, the bot is now pretty much completed for very general uses - now it should be simplified, allow other uses, etc. The moves bug is still exist, but it was exist also in the old files. Modified Paths: -------------- trunk/bot.pl trunk/includes/functions.pm Modified: trunk/bot.pl =================================================================== --- trunk/bot.pl 2006-09-16 14:07:18 UTC (rev 25) +++ trunk/bot.pl 2006-09-16 14:38:57 UTC (rev 26) @@ -40,11 +40,13 @@ my $action = $pages[$i + 1]; my $actionName = $configure::actions{ $action }; - # Execute the action (TODO: add move and delete) + # Execute the action if ( $actionName eq "replace" ) { functions::replaceInPage( $title, $action ); } elsif ( $actionName eq "refresh" ) { functions::refreshPage( $title, $action ); + } elsif ( $actionName eq "move" ) { + functions::movePage( $title, $action ); } elsif ( $actionName eq "delete" ) { functions::deletePage( $title, $action ); } Modified: trunk/includes/functions.pm =================================================================== --- trunk/includes/functions.pm 2006-09-16 14:07:18 UTC (rev 25) +++ trunk/includes/functions.pm 2006-09-16 14:38:57 UTC (rev 26) @@ -224,6 +224,23 @@ } } +# Move page +sub movePage { + # Get parameters + my ( $oldTitle, $action ) = @_; + + # Send page + if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { + my $oldTitles = $configure::titles{ $action }; + my $newTitles = $configure::news{ $action }; + my $newTitle = $oldTitle; + $newTitle =~ s/$oldTitles/$newTitles/; # FIXME: the frequent use of $1 or \1 does not work, therefore this feature is pretty useless; couldn't work around it so far + actions::movePage( $oldTitle, $newTitle, $configure::reasons{ $action } ); + } else { + print "Moved page $oldTitle.\n"; + } +} + # Delete page sub deletePage { # Get parameters This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rot...@us...> - 2006-09-16 15:12:22
|
Revision: 27 http://svn.sourceforge.net/perlwikibot/?rev=27&view=rev Author: rotemliss Date: 2006-09-16 08:12:13 -0700 (Sat, 16 Sep 2006) Log Message: ----------- Comparing diff of times. Modified Paths: -------------- trunk/bot.pl trunk/config/configure.sample trunk/includes/functions.pm Modified: trunk/bot.pl =================================================================== --- trunk/bot.pl 2006-09-16 14:38:57 UTC (rev 26) +++ trunk/bot.pl 2006-09-16 15:12:13 UTC (rev 27) @@ -6,6 +6,7 @@ # Libraries use LWP::UserAgent; +use Time::Local; use includes::actions; use includes::dump; use includes::functions; Modified: trunk/config/configure.sample =================================================================== --- trunk/config/configure.sample 2006-09-16 14:38:57 UTC (rev 26) +++ trunk/config/configure.sample 2006-09-16 15:12:13 UTC (rev 27) @@ -5,9 +5,6 @@ use warnings; use strict; -# Libraries -use Time::local; - # Available servers and details about them, the bot should work on our %servers = ( "server" => "http://www.server.com", @@ -57,7 +54,7 @@ "action" => "מחליף שיחות אנונימיות", ); # Summary/reason sent about the action our %minimumTimes = ( - "action" => timegm( 0, 0, 0, 1, 1 - 1, 1970 - 1900 ), -); # The minimum diff between the current time and the last edit time + "action" => timegm( 0, 0, 0, 1, 1 - 1, 0 + 70 ), +); # The minimum diff between the current time and the last edit time (use: seconds, minutes, hours, day in month, month, year number; 1 January 0 00:00:00 means no minimum time, 2 January 0 00:00:00 means that the last edit should be at least one day old, etc.; edit only the first numbers, as the second ones are used for compatibility to the function) return 1; Modified: trunk/includes/functions.pm =================================================================== --- trunk/includes/functions.pm 2006-09-16 14:38:57 UTC (rev 26) +++ trunk/includes/functions.pm 2006-09-16 15:12:13 UTC (rev 27) @@ -58,7 +58,7 @@ $tempCounter = 0; for ( my $i = 0; $i <= $#pagePossibleActions; $i++ ) { my $wantedText = $configure::texts{ $pagePossibleActions[$i] }; - if ($$text =~ /$wantedText/) { + if ( $$text =~ /$wantedText/ ) { $tempTextArray[$tempCounter++] = $pagePossibleActions[$i]; } } @@ -69,6 +69,26 @@ next; } + # Check if the page last edit is after the minimal time + my @tempLastEditArray; + my $lastEdit = $page->timestamp; + $lastEdit =~ /([\d]+)-([\d]+)-([\d]+)T([\d]+):([\d]+):([\d]+)Z/; + $lastEdit = main::timegm( $6, $5, $4, $3, $2 - 1, $1 - 1900 ); + my $betweenTime = time() - $lastEdit; + $tempCounter = 0; + for ( my $i = 0; $i <= $#pagePossibleActions; $i++ ) { + my $minimumTime = $configure::minimumTimes{ $pagePossibleActions[$i] }; + if ( $betweenTime > $minimumTime ) { + $tempLastEditArray[$tempCounter++] = $pagePossibleActions[$i]; + } + } + + # Continue if there are no matching pages + @pagePossibleActions = @tempLastEditArray; + if ( $#pagePossibleActions < 0 ) { + next; + } + # All the previous checks were OK - add the page, using the first available action $matchingPages[$counter++] = $title; $matchingPages[$counter++] = $pagePossibleActions[0]; @@ -78,36 +98,6 @@ return @matchingPages; } -# Get page last edit -# TODO: Move to getMatchingPages -sub getPageLastEdit { - # Get parameters - my ( $xmlFile, $title ) = @_; - utf8::decode( $title ); - - # Get the pages - my $pages = mwdump->new($xmlFile); - - # Can use only "first-letter", which is also the only currently known value, - # but there could be more in the future - if ( $pages->case ne "first-letter" ) { - die "Unable to handle any case setting besides \"first-letter\".\n"; - } - - # Searching for the page, and getting its timestamp - my $lastEditTimestamp = "0"; - while ( $lastEditTimestamp eq "0" && ( my $page = $pages->page ) ) { - if ( $title eq $page->title ) { - $lastEditTimestamp = $page->timestamp; - } - } - - # Check the time by RegExp - $lastEditTimestamp =~ /([\d]+)-([\d]+)-([\d]+)T([\d]+):([\d]+):([\d]+)Z/; - - return timegm( $6, $5, $4, $3, $2 - 1, $1 - 1900 ); -} - # Filter actions list to the specified script server sub filterActionsList { # Get parameters This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rot...@us...> - 2007-03-03 13:27:36
|
Revision: 35 http://svn.sourceforge.net/perlwikibot/?rev=35&view=rev Author: rotemliss Date: 2007-03-03 05:27:36 -0800 (Sat, 03 Mar 2007) Log Message: ----------- Use the sysop account only when 'sysop' is specified as a parameter. Modified Paths: -------------- trunk/README trunk/bot.pl trunk/includes/functions.pm Modified: trunk/README =================================================================== --- trunk/README 2007-03-03 12:08:10 UTC (rev 34) +++ trunk/README 2007-03-03 13:27:36 UTC (rev 35) @@ -10,7 +10,4 @@ Now copy the files "configure.sample" and "runtime.sample" in the folder "config" to the names "configure.pm" and "runtime.pm", and configure them. You should first go to the configure file, then define the servers, then the actions, then go to the runtime file and define there what actions to execute, and most importantly - set "$sendPages" to 1, after the tests. -After that, you can run the file "bot.pl", with the parameter of the site name. In later times, you can edit the configure file when you want to change the actions, and always edit the run-time file to enable and disable the page sends, and to define the actions to do. - -Tips: -* Don't execute both sysop and non-sysop actions, because the sysop account will be used, even if it doesn't have a bot flag. +After that, you can run the file "bot.pl", with the parameter of the site name, and the parameter "sysop" if you want to use the sysop user (if you don't use it, actions which require sysop rights won't be executed). In later times, you can edit the configure file when you want to change the actions, and always edit the run-time file to enable and disable the page sends, and to define the actions to do. Modified: trunk/bot.pl =================================================================== --- trunk/bot.pl 2007-03-03 12:08:10 UTC (rev 34) +++ trunk/bot.pl 2007-03-03 13:27:36 UTC (rev 35) @@ -19,6 +19,13 @@ die "No server name set - please set server name!\n"; } +my $sysop; +if ( $ARGV[1] eq "sysop" ) { + $sysop = 1; +} else { + $sysop = 0; +} + # Show notes about the sending pages configuration if ( $configure::sendPages == 0 ) { print "Note: There will be no changes in the real server. Please set sendPages to 1 to do them.\n"; @@ -28,11 +35,11 @@ # Log in to the server only if you have to do some stuff in the server if ( $configure::sendPages == 1 || $configure::sendPages == 2 ) { - functions::login(); + functions::login( $sysop ); } # All the matching pages in the XML file -my @pages = functions::getMatchingPages(); +my @pages = functions::getMatchingPages( $sysop ); # Execute actions of all the pages for ( my $i = 0; $i <= $#pages; $i += 2 ) { Modified: trunk/includes/functions.pm =================================================================== --- trunk/includes/functions.pm 2007-03-03 12:08:10 UTC (rev 34) +++ trunk/includes/functions.pm 2007-03-03 13:27:36 UTC (rev 35) @@ -7,6 +7,9 @@ # Get all the pages matching specific restrictions sub getMatchingPages { + # Parameters + my $sysop = @_; + # Get the pages my $pages = mwdump->new( "dumps/".$configure::xmlFiles{ $ARGV[0] } ); @@ -15,8 +18,8 @@ die "Unable to handle any case setting besides \"first-letter\".\n"; } - # Get the executed actions of the specified server - my @possibleActions = filterActionsList( @configure::executedActions ); + # Get the executed actions of the specified server and user + my @possibleActions = filterActionsList( $sysop, @configure::executedActions ); # An array contains all the pages my @matchingPages; @@ -101,13 +104,13 @@ # Filter actions list to the specified script server sub filterActionsList { # Get parameters - my @originalList = @_; + my ( $sysop, @originalList ) = @_; # Go over the actions list, and filter the actions which are not in the current server my @newList; my $counter = 0; for ( my $i = 0; $i <= $#originalList; $i++ ) { - if ( $configure::actionServers{ $originalList[$i] } eq $ARGV[0] ) { + if ( $configure::actionServers{ $originalList[$i] } eq $ARGV[0] && ( $sysop == 1 || $configure::actions ne "delete" ) ) { $newList[$counter++] = $originalList[$i]; } } @@ -117,23 +120,9 @@ # Log in sub login { - # Is sysop finally required? - my $sysop = 0; + # Get parameters + my ( $sysop ) = @_; - # Go through the array, and check if sysop permission is needed. - for ( my $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 ) { @@ -169,9 +158,9 @@ # Set initial edit summary my $summary = $configure::initialEditSummaries{ $ARGV[0] }; - # Groups array - my @executedActions = filterActionsList( @configure::executedActions ); - my @bywayActions = filterActionsList( @configure::bywayActions ); + # Groups array (assume non-sysop, as it doesn't matter for edits) + my @executedActions = filterActionsList( 0, @configure::executedActions ); + my @bywayActions = filterActionsList( 0, @configure::bywayActions ); my @actions = ( @executedActions, @bywayActions ); # Replaced something at all? Flag to check This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rot...@us...> - 2007-03-24 16:08:28
|
Revision: 37 http://svn.sourceforge.net/perlwikibot/?rev=37&view=rev Author: rotemliss Date: 2007-03-24 08:51:07 -0700 (Sat, 24 Mar 2007) Log Message: ----------- Fix libraries inclusion. Modified Paths: -------------- trunk/bot.pl trunk/config/configure.sample trunk/includes/functions.pm trunk/includes/http.pm Modified: trunk/bot.pl =================================================================== --- trunk/bot.pl 2007-03-03 14:08:53 UTC (rev 36) +++ trunk/bot.pl 2007-03-24 15:51:07 UTC (rev 37) @@ -5,8 +5,6 @@ use strict; # Libraries -use LWP::UserAgent; -use Time::Local; use includes::actions; use includes::dump; use includes::functions; Modified: trunk/config/configure.sample =================================================================== --- trunk/config/configure.sample 2007-03-03 14:08:53 UTC (rev 36) +++ trunk/config/configure.sample 2007-03-24 15:51:07 UTC (rev 37) @@ -5,6 +5,9 @@ use warnings; use strict; +# Libraries +use Time::Local; + # Available servers and details about them, the bot should work on our %servers = ( "server" => "http://www.server.com", Modified: trunk/includes/functions.pm =================================================================== --- trunk/includes/functions.pm 2007-03-03 14:08:53 UTC (rev 36) +++ trunk/includes/functions.pm 2007-03-24 15:51:07 UTC (rev 37) @@ -5,6 +5,9 @@ use warnings; use strict; +# Libraries +use Time::Local; + # Get all the pages matching specific restrictions sub getMatchingPages { # Parameters @@ -76,7 +79,7 @@ my @tempLastEditArray; my $lastEdit = $page->timestamp; $lastEdit =~ /([\d]+)-([\d]+)-([\d]+)T([\d]+):([\d]+):([\d]+)Z/; - $lastEdit = main::timegm( $6, $5, $4, $3, $2 - 1, $1 - 1900 ); + $lastEdit = timegm( $6, $5, $4, $3, $2 - 1, $1 - 1900 ); my $betweenTime = time() - $lastEdit; $tempCounter = 0; for ( my $i = 0; $i <= $#pagePossibleActions; $i++ ) { Modified: trunk/includes/http.pm =================================================================== --- trunk/includes/http.pm 2007-03-03 14:08:53 UTC (rev 36) +++ trunk/includes/http.pm 2007-03-24 15:51:07 UTC (rev 37) @@ -5,6 +5,9 @@ use warnings; use strict; +# Libraries +use LWP::UserAgent; + # The browser we use to surf; enable cookies, and use a specific user agent my $browser = LWP::UserAgent->new(); $browser->cookie_jar( {} ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |