User:Polbot/source/Add rationales for logos.pl
Appearance
< User:Polbot | source
use strict; use Perlwikipedia; my $starter = shift; my $soonest_next_op = time; my $pw=Perlwikipedia->new(); $pw->{mech}->agent('Bot/WP/EN/Quadell/polbot'); print "\nStarting polbot, logging in.\n" ; my $login_status=$pw->login('Polbot','password redacted'); die "I can't log in." unless ($login_status eq 0); my $category_name = "Category:All non-free Logos"; print "Reading [[$category_name]]\n"; my @allimages = $pw->get_pages_in_category($category_name); print "There are " . scalar(@allimages) . " total logos.\n\n"; foreach my $image (sort @allimages) { if ($image =~ m/^Image:/) { if ($image gt "Image:$starter") { print "Looking at [[$image]]\n"; my $wiki = $pw->get_text($image); if ($wiki =~ m/{{(Non-free media rationale|Non-free use rationale|Fair use rationale|Non-free fair use rationale|Rationale|Logo fur|Non-free image data|Non-free image rationale)/i) { print " already has a rationale\n"; } else { print " No rationale\n"; my @whatlinkshereraw = ($pw->get_file_links("$image")); my @whatlinkshere = (); foreach my $what (@whatlinkshereraw) { if ($what !~ m/^(Image:|Image talk:|User:|User talk:)/) { push @whatlinkshere, $what; } } if (scalar(@whatlinkshere) == 1) { my $inarticle = $whatlinkshere[0]; print " One link: [[$inarticle]].\n"; $wiki .= "\n{{Non-free use rationale\n| Article = $inarticle\n"; $wiki .= "| Description = logo\n| Source = intellectual property owned by the organization represented\n"; $wiki .= "| Portion = entire logo\n| Low_resolution = yes\n"; $wiki .= "| Purpose = Used to represent the organization in an article on that organization.\n| Replaceability=no\n"; $wiki .= "| other_information=This rationale '''only''' covers use in the article on this organization represented by this logo. Any other use requires a different, separate rationale.\n<small>This rationale was generated by a bot, based on the fact that this is tagged as a logo and is used only in the [[$inarticle]] article. If this is not correct, please remove.\n}}\n"; $|=1; print " Waiting " . ($soonest_next_op - time) . " secs... "; $|=1; while (time < $soonest_next_op) {}; $soonest_next_op = time + 10; print "Adding rationale\n"; $pw->edit($image, $wiki, "Adding rationale for use of logo in [[$inarticle]]"); } else { print " <> 1 link\n"; } } } } } print "Done!\n";