Jump to content

User:Bot1058/shortpage-dabs.php

From Wikipedia, the free encyclopedia
<?php
/** shortpage-dabs.php - Clear disambiguation pages from [[Category:Monitored short pages]]
 *  Version 1.00
 *
 *  (c) 2019 WBM - http://en.wikipedia.org/wiki/User:Wbm1058
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *   
 *  Developers (add your self here if you worked on the code):
 *    WBM - [[User:Wbm1058]] - December 2019 - Initial release
 **/

ini_set("display_errors", 1);
error_reporting(E_ALL ^ E_NOTICE);
require_once 'botclasses.php';  // Botclasses.php was written by User:Chris_G and is available under the GNU General Public License
include("logininfo.php");

const long_comment = "{{Short pages monitor}}<!-- This long comment was added to the page to prevent it from being listed on Special:Shortpages. " .
	"It and the accompanying monitoring template were generated via Template:Long comment. Please do not remove the monitor template without removing the comment as well.-->";

const long_comment1 = "{{Short pages monitor}}<!-- This long comment was added to the page to prevent it from being listed on Special:Shortpages. " .
	"It and the accompanying monitoring template were generated via Template:Long comment. Please do not remove the monitoring template without removing this comment as well.-->";

const long_comment2 = "{{Short pages monitor}}<!-- This long comment was added to the page to prevent it being listed on Special:Shortpages. " .
	"It and the accompanying monitoring template were generated via Template:Longcomment. Please do not remove the monitor template without removing the comment as well. \n" .
	"                                                                                                                                               -->";
const long_comment3 = "{{Short pages monitor}}<!-- This long comment was added to the page to prevent it being listed on Special:Shortpages. " .
	"It and the accompanying monitoring template were generated via Template:Longcomment. Please do not remove the monitor template without removing the comment as well.-->";

const long_comment4 = "{{Short pages monitor}}<!-- This long comment was added to the page to prevent it being listed on Special:Shortpages. " .
	"It and the accompanying monitoring template were generated via Template:Longcomment. Please do not remove the monitor template without removing the comment as well. -->";

const long_comment5 = "{{Short pages monitor}}<!-- This long comment was added to the page to prevent it being listed on Special:Shortpages. " .
	"It and the accompanying monitoring template were generated via Template:Longcomment. Please do not remove the monitor template without removing the comment as well.\n" .
	"                                                                                                                                               -->";

echo "Logging in...\n";
$objwiki = new wikipedia();
$objwiki->http->useragent = '[[User:Bot1058]] php wikibot classes';
$objwiki->login($user, $pass);
echo "...done.\n";

/** TASK 6 **/
$dabpages = 0;
$notdab = 0;
$lc_cleared = 0;
$not_cleared = 0;

$msp = $objwiki->categorymembers("Category:Monitored short pages");
#print_r($msp);
echo "\n" . count($msp) . " pages in Category:Monitored short pages\n";

for ($a = 0; $a < count($msp); $a++) {
	echo "\n__________\n" . $a . " Retrieving $msp[$a] categories...\n";
	$categories = $objwiki->categories($msp[$a]);

	for ($c = 0; $c < count($categories); $c++) {
		echo "\n" . $categories[$c]['title'];
		if ($categories[$c]['title'] == "Category:All article disambiguation pages") {
			echo " -- disambiguation page";
			$dabpages += 1;
			echo " Retrieving $msp[$a] contents...\n";
			$contents = $objwiki->getpage($msp[$a]);
			#echo "\n$contents\n";

			$new_contents = str_replace(long_comment,"",$contents);
			$new_contents = str_replace(long_comment1,"",$new_contents);
			$new_contents = str_replace(long_comment2,"",$new_contents);
			$new_contents = str_replace(long_comment3,"",$new_contents);
			$new_contents = str_replace(long_comment4,"",$new_contents);
			$new_contents = str_replace(long_comment5,"",$new_contents);

			if ($new_contents != $contents) {
				$objwiki->edit($msp[$a],$new_contents,"[[User:Bot1058|Task 6]]: remove disambiguation page from [[Category:Monitored short pages]]",true,true);
				$lc_cleared += 1;
				sleep (4);
				#if ($lc_cleared >= 50) goto done;
			}
			else {
				echo "\n$new_contents\n";
				echo " -- Long comment was NOT REMOVED";
				$not_cleared += 1;
			}
			break;
		}
		if ($c == count($categories)-1) {
			echo " -- not a disambiguation page";
			$notdab += 1;
		}
	}
}

done:
echo "\n\nDisambiguation pages: " . $dabpages;
echo "\nNon-disambiguations : " . $notdab;
echo "\nTotal monitored pages: " . count($msp);
echo "\n\nLong comments cleared: " . $lc_cleared;
echo "\nNot cleared: " . $not_cleared;
echo "\n\nTask 6 done.\n";

echo "\nMission accomplished.\n\n";

?>