< User:Merge bot
Browse history interactively ← Previous edit Next edit → Content deleted Content addedVisual Wikitext Inline
Revision as of 05:09, 30 January 2017 edit Wbm1058 (talk | contribs )Autopatrolled , Administrators 264,846 edits v 1.21 - update redirects, per Misplaced Pages:Templates for discussion/Log/2015 May 24 , diff , Template talk:Merge to article , diff , diff , diff ← Previous edit
Revision as of 23:22, 31 January 2017 edit undo Wbm1058 (talk | contribs )Autopatrolled , Administrators 264,846 edits v 1.22 – remove Template:Move section portions from . That's in Category:Split maintenance templates , not Category:Merge templates Next edit →
Line 2:
Line 2:
<?php
<?php
/** proposedmergers.php - To generate lists of proposed page mergers on Misplaced Pages
/** proposedmergers.php - To generate lists of proposed page mergers on Misplaced Pages
* Version 1.21
* Version 1.22
*
*
* (c) 2009 James Hare - http://en.wikipedia.org/User:Harej
* (c) 2009 James Hare - http://en.wikipedia.org/User:Harej
Line 49:
Line 49:
$processed = preg_replace("/^(Mergefrom-multiple|Multiplemergefrom|Mergefrommultiple|Mergefrommulti|Multimergefrom)/i", "mergefrom", $processed);
$processed = preg_replace("/^(Mergefrom-multiple|Multiplemergefrom|Mergefrommultiple|Mergefrommulti|Multimergefrom)/i", "mergefrom", $processed);
# {{Move section portions from}}
$processed = preg_replace("/^(Move section portions from|Move_section_portions_from)/i", "mergefrom", $processed);
# {{Afd-merge from}}, {{Merging from}}
# {{Afd-merge from}}, {{Merging from}}
Revision as of 23:22, 31 January 2017
<?php
/** proposedmergers.php - To generate lists of proposed page mergers on Misplaced Pages
* Version 1.22
*
* (c) 2009 James Hare - http://en.wikipedia.org/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 - ] - Wrote everything
* WBM - ] - March/April 2013 updates
**/
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");
function templateprocess($processed) {
echo " :: " . $processed;
$processed = preg_replace("/\s?\|\s?/", "|", $processed);
$processed = preg_replace("/\{{2}\s?/", "", $processed);
$processed = preg_replace("/\s?\}{2}/", "", $processed);
$processed = preg_replace("/\s?=\s?/", "=", $processed);
# Redirects to {{Merge}} (14 aliases)
$processed = preg_replace("/^(Mergewith|Merge with|Merge_with|MergeVfD|Mergesplit|MergeSplit|Merge)/i", "merge", $processed);
$processed = preg_replace("/^(Mergedisputed|MergeDisputed|Merge-disputed|Merge disputed|Merge_disputed)/i", "merge", $processed);
$processed = preg_replace("/^(Merge-multiple|Mergemulti|Mergetomultiple-with|Multimerge)/i", "merge", $processed);
$processed = preg_replace("/^(Proposed merge|Proposed_merge)/i", "merge", $processed);
# {{Merging}}
$processed = preg_replace("/^(Mergingsectionto|Merging|Merging to|Merging_to)/i", "merge", $processed);
# Redirects to {{Merge from}} (11 aliases)
$processed = preg_replace("/^(Merge from|Merge_from|Merge-from|Include|Mergrefrom|Mergefrom-category|MergeFrom|Mergefrom)/i", "mergefrom", $processed);
$processed = preg_replace("/^(Mergefrom-multiple|Multiplemergefrom|Mergefrommultiple|Mergefrommulti|Multimergefrom)/i", "mergefrom", $processed);
# {{Afd-merge from}}, {{Merging from}}
$processed = preg_replace("/^(Afd-merge from|Afd-merge_from|Afd-mergefrom|Afdmergefrom|Merging from|Merging_from|Mergingfrom)/i", "mergefrom", $processed);
# Redirects to {{Merge to}} (15 aliases)
$processed = preg_replace("/^(Merge to|Merge_to|Merge-to|Mergeinto|MergetoCat|Mergelist|Mergeto-disputed)/i", "mergeto", $processed);
$processed = preg_replace("/^(MergePartial|Merge-multiple-to|Merge to article|Merge_to_article)/i", "mergeto", $processed);
$processed = preg_replace("/^(Mergeto-multiple|Multiplemergeto|Multiplemergeinto|Merge into|Merge_into|MergeTo|Mergeto|Merge2)/i", "mergeto", $processed);
# {{Afd-merge to}}
$processed = preg_replace("/^(Afd-merge to|Afd-merge_to|Afd-mergeto|Afdmergeto|AfD-merge to|AfD-merge_to)/i", "mergeto", $processed);
return $processed;
}
$othernamespace = 0;
$matchfailed = 0;
$templatesplitfailed = 0;
$nopartner = 0;
$mainsubmission = "";
echo "Logging in...\n";
$objwiki = new wikipedia();
$objwiki->login($mbuser, $mbpass);
echo "...done.\n";
$mergemonths = $objwiki->categorymembers("Category:Articles to be merged");
print_r($mergemonths);
for ($a = 0; $a < count($mergemonths); $a++) { // for each month
#if (preg_match("/Category:Articles to be merged/", $mergemonths)) {
if (preg_match("/Category:Articles to be merged from/", $mergemonths)) {
echo "\n__________\n" . $a . ": " . $mergemonths . "\n";
$transcludes = $objwiki->categorymembers($mergemonths);
#print_r($transcludes);
$monthyear = str_replace("Category:Articles to be merged from ", "", $mergemonths, $repcount);
if ($repcount == 0) {
$monthyear = str_replace("Category:", "", $mergemonths);
}
for ($i = 0; $i < count($transcludes); $i++) { // for each page
if ($i > $maxi) {
$maxi = $i;
}
if (preg_match("/^((User|Misplaced Pages|File|MediaWiki|Template|Help|Category|Portal)(( |_)talk)?|Talk):/", $transcludes)) {
echo "\n\n?? Other namespace: " . $transcludes . "\n\n";
$others = $transcludes;
$othernamespace += 1;
continue;
}
$getpagefailed = 0;
do {
$contents = $objwiki->getpage($transcludes);
if ($contents == FALSE) {
echo "\n\n?? getpage failed: " . $transcludes . "\n\n";
$getpagefailed += 1;
if ($getpagefailed == 5) {
die("getpage Error");
}
sleep(10);
continue;
}
} while ($contents == FALSE);
if (preg_match_all("/\{{2}\s?(merge|afd-merge|merging|move section)*\}{2}/i", $contents, $raw) == 0) {
#echo "contents:\n";
#echo "$contents";
#echo "\n";
unset($contents);
echo "\n\n?? Match failed: " . $transcludes . "\n\n";
$nomatches = $transcludes;
$matchfailed += 1;
continue;
}
$takeofflater = 0;
for ($j = 0; $j < count($raw); $j++) { // for each utterance
$key = $a . "-" . $i . "-" . $j;
$pagename = $transcludes;
echo $key . ">> " . $pagename;
$template = templateprocess($raw);
#echo "Count of raw: " . count($raw) . "\n";
unset($contents);
$templatesplit = array_map('trim',explode("|", $template));
echo " " . $templatesplit;
switch ($templatesplit) {
case "mergefrom":
$type = "into";
break;
case "mergeto":
echo " . "]\n";
unset($pagename);
$takeofflater += 1;
break;
case "merge":
$type = "with";
break;
default:
echo "*** templatesplitfailed: " . $templatesplit . "\n";
print_r($templatesplit);
$nosplits = $transcludes;
$templatesplitfailed += 1;
continue;
}
$otherpage = "{{pagelist|nspace=|";
for ($para = 1; $para < count($templatesplit); $para++) {
if (preg_match("/^date=/i", $templatesplit)) {
$date = str_replace("date=", "", $templatesplit);
}
elseif (preg_match("/^discuss=/i", $templatesplit)) {
$discuss = str_replace("discuss=", "", $templatesplit);
}
elseif (preg_match("/^target=/i", $templatesplit)) {
$target = str_replace("target=", "", $templatesplit);
if (in_array($target, $pagename)) {
echo " . "]\n";
unset($pagename);
unset($type);
unset($date);
unset($discuss);
unset($target);
unset($multiplesections);
$takeofflater += 1;
continue 2;
}
}
elseif (preg_match("/^multiplesections=/i", $templatesplit)) { // Template:Mergefrom uses parameter multiplesections; Merge and Mergeto do not
$multiplesections = str_replace("multiplesections=", "", $templatesplit);
}
else {
if (in_array($templatesplit, $pagename)) {
echo " . "]\n";
unset($pagename);
unset($type);
unset($date);
unset($discuss);
unset($target);
unset($multiplesections);
$takeofflater += 1;
continue 2;
}
else {
$otherpage .= $templatesplit . "|";
}
}
}
$otherpage .= "}}";
echo " -- " . $otherpage . "\n";
if ($date == "") {
$date = date("F Y");
}
elseif ($date != $monthyear) {
echo "\nAnother date: " . $date . " not " . $monthyear . "\n";
unset($pagename);
unset($type);
unset($date);
unset($discuss);
unset($target);
unset($multiplesections);
$takeofflater += 1;
}
if ($discuss == "") {
if (preg_match("/^(User|Misplaced Pages|Image|File|MediaWiki|Template|Help|Category|Portal):/i",$transcludes,$m)) {
$discuss = str_replace($m,$m.' talk',$transcludes);
}
else {
$discuss = "Talk:" . $transcludes;
}
}
}
}
$j = $j - $takeofflater;
$mainsubmission .= "* ]\n";
}
else {
echo "\n" . $a . ": Skipped: " . $mergemonths . "\n";
$skipped += 1;
}
}
if (count($pagename) < 1) {
echo "No pagenames! Exiting.";
die();
}
echo "\n*** Preparing Updates ***\n\n";
print_r($pagename);
foreach ($pagename as $key => $title) {
if ($counter] > $maxcounter) {
$maxcounter = $counter];
}
switch ($type) {
case "with": // regular merge
if ($target != "") {
#$submission] .= "# . "]] Request to merge ''']''' with '''" . $otherpage . "''' to ''' . "]]''' ([[" .
# $discuss . "|Discuss]])\n";
$submission] .= "{{merge log entry|1=]|2=$otherpage|3=]]|talk=$discuss|type=with}}\n";
}
else {
#$submission] .= "# . "]] Request to merge ''']''' with '''" . $otherpage . "''' ( . "|Discuss]])\n";
$submission] .= "{{merge log entry|1=]|2=$otherpage|talk=$discuss|type=with}}\n";
}
break;
case "into": // merge-from
#$submission] .= "# ''' . "]]''' Request to merge '''" . $otherpage . "''' into ''']''' ( . "|Discuss]])\n";
$submission] .= "{{merge log entry|1=$otherpage|2=]|talk=$discuss|type=into}}\n";
break;
default:
echo "\n*error* " . $type . "\n";
continue;
}
if ($otherpage == "{{pagelist|nspace=|}}") {
$nopartners = $title;
$nopartner += 1;
}
$counter] += 1;
echo $date . " | " . $counter] . ") " . $key . " ++ " . $title. "\n";
}
echo "\n\n*** Posting Updates ***\n\n";
foreach ($submission as $log => $content) {
echo "Updating> " . $log. "\n";
#echo $content . "\n";
$objwiki->edit("Misplaced Pages:Proposed mergers/Log/" . $log,$content,"Updating list of proposed mergers",false,true);
}
echo "Updating Misplaced Pages:Proposed mergers/Log\n";
$objwiki->edit("Misplaced Pages:Proposed mergers/Log",$mainsubmission,"Updating list of logs",true,true);
echo "done.\n";
echo "\nCategory members skipped: " . $skipped;
echo "\nMaximum pages in a category: " . $maxi;
echo "\nMaximum items on a report page: " . $maxcounter;
echo "\nOther namespaces skipped: " . $othernamespace . "\n";
print_r($others);
echo "\nPattern match failed: " . $matchfailed . "\n";
print_r($nomatches);
echo "\nTemplatesplit failed: " . $templatesplitfailed . "\n";
print_r($nosplits);
echo "\nNo partner: " . $nopartner . "\n";
print_r($nopartners);
echo "\nMission accomplished.\n\n";
?>