Jump to content

User:RFC bot/headerdelete.php

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

headerdelete.php stable version 1.0

See comments for copyright information.

<?php
/** headerdelete.php - Deletes {{moveheader}} when there is no accompanying {{movereq}}
 *  STABLE Version 1.0
 *
 *  (c) 2009 James Hare - http://en.wikipedia.org/wiki/User:Harej
 *
 *  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):
 *    James Hare - [[User:Harej]] - Wrote everything
 **/
ini_set("display_errors", 1);
error_reporting(E_ALL ^ E_NOTICE);
include("./public_html/botclasses.php");  // Botclasses.php was written by User:Chris_G and is available under the GNU General Public License
include("logininfo.php");

echo "Logging in...";
$objwiki = new wikipedia();
$objwiki->login($botuser, $botpass);
echo " done.\n";

echo "Checking for transclusions...";
$transcludes = $objwiki->getTransclusions("Template:Moveheader");
echo " done.\n";

echo "Counting the amount of transclusions...";
$count = count($transcludes);
echo " done.\n";

for ($i = 0; $i < $count; $i++) {
	echo "Retrieving $transcludes[$i] contents...\n";
	$contents[$transcludes[$i]] = $objwiki->getpage($transcludes[$i]);

	if (!preg_match("/\{{2}movereq.*\}{2}/i", $contents[$transcludes[$i]], $m)) {
		echo $transcludes[$i] . " is unpaired. Removing moveheader.\n";
		$contents[$transcludes[$i]] = preg_replace("/\{{2}moveheader.*\}{2}\n/i", "", $contents[$transcludes[$i]]);
		$objwiki->edit($transcludes[$i],$contents[$transcludes[$i]],"Removing unpaired moveheader",false,true);
	}
}

?>