Wikipedia:Banner standardisation/Code

<?php

$username="";
$password="";


$PageNames=array();
$querycontinue="NONE";
$querynumber=0

//Getting articles from Category:WikiProject banners

while($querycontinue) {
  $CatQuery[$querynumber]=new DOMDocument();
  $url="http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:WikiProject banners&cmlimit=500&format=xml&cmprop=ids|title|sortkey|timestamp";
  if($querycontinue&&$querycontinue!="NONE") { $url=$url."$cmcontinue=".ereg_replace("&",'%26',$querycontinue); }
  $CatQuery[$querynumber]->load($url);
  $arrayoffset=$querynumber*500;
  $x=0;
  for($i=$arrayoffset;$i<$arrayoffset+$CatQuery[$querynumber]->getElementsByTagName("cm")->length;$i++) {
    $TitleArray[$i]=$CatQuery[$querynumber]->getElementsByTagName("cm")->item($x)->attributes->getNamedItem("title")->nodeValue;
    $x++;
  }
  if($CatQuery[$querynumber]->getElementsByTagName("query-continue")->length>0) {
    $querycontinue=$CatQuery[$querynumber]->getElementsByTagName("query-continue")->item(0)->childNodes->item(0)->attributes->getNamedItem("cmcontinue")->nodeValue;
    echo $querycontinue;
    $querynumber++;
  }
  else { $querycontinue=false; }
}
echo "\n\n\n";

$MoveName=array();
$NeedsHuman=array();

foreach($TitleArray as $number=>$title) {

  //Checking for Incorrect Syntax

  if(!ereg("Template:WikiProject ",$title) {

    //Checking for Project Mentions

    $ProjectMentions=array();
    $APIInfo=new DOMDocument();
    $APIInfo->load("http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=".ereg_replace("&",'%26',$title));
    echo ereg_replace("&",'%26',$title)."-".$number."|";
    ereg("\[\[Wikipedia:WikiProject [^\]\|]",$APIInfo,$ProjectMentions);

    //Matching Obvious Project Mentions and Setting Move Name

    if(isset($ProjectMentions[1])&&((!isset($ProjectMentions[2]))||(isset($ProjectMentions[2])&&$ProjectMentions[2]==$ProjectMentions[1]))) {
      $MoveName[$title]="Template:WikiProject ".ereg_replace("Wikipedia:WikiProject ","",ereg_replace("[\[\]\|]","",$ProjectMentions[1]));

    //OR adding to List that needs to be sorted by hand.

    else { $NeedsHuman[$title]=$title; }
    unset($ProjectMentions);
  }
}

//Checking for existing page

$NeedsDeletion=array();
$NeedsMove=array();

foreach($MoveName as $oldtitle=>$newtitle) {
  $APIInfo=new DOMDocument();
  $APIInfo->load("http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=".ereg_replace("&",'%26',$newtitle));

  // Checking for non-existent page

  if(isset($APIInfo->getElementsByTagName("page")->item(0)->attributes->getNamedItem("missing")) {
    $NeedsMove[$oldtitle]=$newtitle;
  }

  // Checking for redirect page

  elseif(ereg("#REDIRECT \[\[".$oldtitle,$APIInfo->getElementsByTagName("rev")->item(0)->nodeValue)) {
    $NeedsDeletion[$oldtitle]=$newtitle;
  }

  // Adding others to NeedsHuman

  else { $NeedsHuman[$oldtitle]=$oldtitle; }
}

unset($MoveName);

// Logging In

$LoginGet=curl_init("http://en.wikipedia.org/w/api.php");
curl_setopt($LoginGet,CURLOPT_POST,1);
curl_setopt($LoginGet,CURLOPT_RETURNTRANSFER,1);
curl_setopt($LoginGet,CURLOPT_COOKIEJAR,"cookies.txt");
curl_setopt($LoginGet,CURLOPT_POSTFIELDS,"lgname=".$username."&lgpassword=".$password."&action=login&format=xml");
$LoginResult=curl_exec($LoginGet);
$LoginDOM=new DOMDocument();
$LoginDOM->loadXML($LoginResult);
if($LoginDOM-getElementsByTagName("login")->item(0)->attributes->getNamedItem('result')->nodeValue!="Success") { die("No Login"); }
curl_close($LoginGet);

// UPDATE: Arrays to be acted upon -- NeedsMove, NeedsDeletion, and NeedsHuman

// Moving pages that can be moved

foreach($NeedsMove as $oldtitle=>$newtitle) {
  $MoveRequest=curl_init("http://en.wikipedia.org/w/index.php?title=Special:Movepage&action=submit");
  curl_setopt($MoveRequest,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($MoveRequest,CURLOPT_POST,1);
  curl_setopt($MoveRequest,CURLOPT_COOKIEJAR,"cookies.txt");
  curl_setopt($MoveRequest,CURLOPT_COOKIEFILE,"cookies.txt");
  $POSTvars="wpNewTitle=".$newtitle."&wpOldTitle=".$oldtitle."&wpReason=WikiProject Banner standardisation";
  $MoveTokenXML=new DOMDocument();
  $MoveTokenXML->load("http://en.wikipedia.org/w/api.php?action=query&prop=info&intoken=move&format=xml&titles=".$oldtitle);
  $MoveToken=$MoveTokenXML->getElementsByTagName("page")->item(0)->attributes->getNamedItem("movetoken")->nodeValue;
  $POSTvars=$POSTvars."&wpMove=Move page&wpEditToken=".$MoveToken;
  curl_setopt($MoveRequest,CURLOPT_POSTFIELDS,$POSTvars);
  curl_exec($MoveRequest);
  curl_close($MoveRequest);
  if(isset($MoveRequest)) { unset($MoveRequest); }
}

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.