Advertisement
DrStrauss

StraussBot

Jun 13th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.75 KB | None | 0 0
  1. #standard perl procedure
  2. use strict;
  3. use warnings;
  4.  
  5. #set encoding
  6. binmode STDOUT, ":encoding(UTF-8)";
  7.  
  8. #use MediaWiki library for interaction with Wikipedia
  9. use MediaWiki::Bot qw(:constants);
  10.  
  11. #use POSIX library for timestamp generation and initialise timestamp string
  12. use POSIX qw(strftime);
  13. my $datestring = "";
  14. #make new bot object
  15. my $bot = MediaWiki::Bot->new({
  16.     assert      => 'bot',
  17.     protocol    => 'https',
  18.     host        => 'en.wikipedia.org',
  19.     agent       => sprintf(
  20.         'PerlWikiBot/%s (https://metacpan.org/MediaWiki::Bot; User:Mike.lifeguard)',
  21.         MediaWiki::Bot->VERSION
  22.     ),
  23.     login_data  => { username => "StraussBot", password => "placeholder" },
  24. });
  25.  
  26. #log bot in
  27. $bot->login({
  28.     username => "StraussBot",
  29.     password => "placeholder",
  30. }) or die "Login failed!";
  31.  
  32. #get current count
  33. my $count = $bot->get_text('User:StraussBot/count');
  34. my $wikitext = "";
  35. my $username = "";
  36.  
  37. #make array of today's pending submissions
  38. my @pages = $bot->get_pages_in_category('AfC pending submissions by age/0 days ago');
  39.  
  40. #go through each page in array
  41. foreach my $page (@pages) {
  42.  
  43.     #retrieve wikitext of current page
  44.     $wikitext = $bot->get_text($page);
  45.  
  46.     #if no references are present...
  47.     if ($wikitext !~ /http/i and $wikitext !~ /www/i and $wikitext !~ /ref/i and $wikitext !~ /bibliography/i and $wikitext !~ /source/i and $wikitext !~ /cite/i) {
  48.         $datestring = strftime "%Y%m%d%H%M%S", gmtime;
  49.        
  50.         #retrieve creator's username
  51.         ($username) = $wikitext =~ /\|u=([^|]+)\|/;
  52.        
  53.         #define decline notification
  54.         my $notification = "{{subst:Afc decline|full=" . $page . "|reason=source|sig=yes}}";
  55.        
  56.         #notify creator that their draft has been declined
  57.         $bot->edit({
  58.             page    => 'User talk:' . $username,
  59.             text    => $notification,
  60.             summary => 'AfC submission decline notification',
  61.             section => 'new',
  62.         });
  63.        
  64.         #change wikitext of pending submission template to declined template and leave any previous decline templates alone    
  65.         $wikitext =~ s/AFC submission\|\|\|/AfC submission\|d\|source\|decliner=StraussBot\|declinets=${datestring}\|/;
  66.        
  67.         #actually update the page thereby declining the draft and removing the submission from the pending category
  68.         $bot->edit({
  69.             page    => $page,
  70.             text    => $wikitext,
  71.             summary => 'Declining unreferenced AfC submission',
  72.         });
  73.        
  74.         #increment count
  75.         $count = $count + 1;
  76.        
  77.         #output list of declines executed in local console
  78.         print "Declined draft: " . $page . "\n";
  79.     }
  80. }
  81.  
  82. #update count page which transcludes onto user page and print to console
  83. $bot->edit({
  84.     page    => 'User:StraussBot/count',
  85.     text    => $count,
  86.     summary => 'Updating count',
  87. });
  88. print "All time total number of pages StraussBot has declined: " . $count;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement