Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #standard perl procedure
- use strict;
- use warnings;
- #set encoding
- binmode STDOUT, ":encoding(UTF-8)";
- #use MediaWiki library for interaction with Wikipedia
- use MediaWiki::Bot qw(:constants);
- #use POSIX library for timestamp generation and initialise timestamp string
- use POSIX qw(strftime);
- my $datestring = "";
- #make new bot object
- my $bot = MediaWiki::Bot->new({
- assert => 'bot',
- protocol => 'https',
- host => 'en.wikipedia.org',
- agent => sprintf(
- 'PerlWikiBot/%s (https://metacpan.org/MediaWiki::Bot; User:Mike.lifeguard)',
- MediaWiki::Bot->VERSION
- ),
- login_data => { username => "StraussBot", password => "placeholder" },
- });
- #log bot in
- $bot->login({
- username => "StraussBot",
- password => "placeholder",
- }) or die "Login failed!";
- #get current count
- my $count = $bot->get_text('User:StraussBot/count');
- my $wikitext = "";
- my $username = "";
- #make array of today's pending submissions
- my @pages = $bot->get_pages_in_category('AfC pending submissions by age/0 days ago');
- #go through each page in array
- foreach my $page (@pages) {
- #retrieve wikitext of current page
- $wikitext = $bot->get_text($page);
- #if no references are present...
- if ($wikitext !~ /http/i and $wikitext !~ /www/i and $wikitext !~ /ref/i and $wikitext !~ /bibliography/i and $wikitext !~ /source/i and $wikitext !~ /cite/i) {
- $datestring = strftime "%Y%m%d%H%M%S", gmtime;
- #retrieve creator's username
- ($username) = $wikitext =~ /\|u=([^|]+)\|/;
- #define decline notification
- my $notification = "{{subst:Afc decline|full=" . $page . "|reason=source|sig=yes}}";
- #notify creator that their draft has been declined
- $bot->edit({
- page => 'User talk:' . $username,
- text => $notification,
- summary => 'AfC submission decline notification',
- section => 'new',
- });
- #change wikitext of pending submission template to declined template and leave any previous decline templates alone
- $wikitext =~ s/AFC submission\|\|\|/AfC submission\|d\|source\|decliner=StraussBot\|declinets=${datestring}\|/;
- #actually update the page thereby declining the draft and removing the submission from the pending category
- $bot->edit({
- page => $page,
- text => $wikitext,
- summary => 'Declining unreferenced AfC submission',
- });
- #increment count
- $count = $count + 1;
- #output list of declines executed in local console
- print "Declined draft: " . $page . "\n";
- }
- }
- #update count page which transcludes onto user page and print to console
- $bot->edit({
- page => 'User:StraussBot/count',
- text => $count,
- summary => 'Updating count',
- });
- print "All time total number of pages StraussBot has declined: " . $count;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement