User:Polbot/source/Add rationales for logos.pl

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";	

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.