public function execute()
 {
     $user = '******';
     $reason = 'No longer required';
     $this->output("Checking existence of old default messages...");
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select(array('page', 'revision'), array('page_namespace', 'page_title'), array('page_namespace' => NS_MEDIAWIKI, 'page_latest=rev_id', 'rev_user_text' => 'MediaWiki default'));
     if ($dbr->numRows($res) == 0) {
         # No more messages left
         $this->output("done.\n");
         return;
     }
     # Deletions will be made by $user temporarly added to the bot group
     # in order to hide it in RecentChanges.
     global $wgUser;
     $wgUser = User::newFromName($user);
     $wgUser->addGroup('bot');
     # Handle deletion
     $this->output("\n...deleting old default messages (this may take a long time!)...", 'msg');
     $dbw = wfGetDB(DB_MASTER);
     foreach ($res as $row) {
         if (function_exists('wfWaitForSlaves')) {
             wfWaitForSlaves(5);
         }
         $dbw->ping();
         $title = Title::makeTitle($row->page_namespace, $row->page_title);
         $article = new Article($title);
         $dbw->begin();
         $article->doDeleteArticle($reason);
         $dbw->commit();
     }
     $this->output('done!', 'msg');
 }
	public static function deleteArticle( $titletext ) {
		if ( ! OpenStackNovaArticle::canCreatePages() ) {
			return;
		}
		$title = Title::newFromText( $titletext, NS_NOVA_RESOURCE );
		$article = new Article( $title, 0 );
		$article->doDeleteArticle( '' );
	}
	function run() {
		global $wgUser;

		// Initialization
		$title = $this->title;
		// Other stuff
		$user    = $this->getUser();
		$summary = $this->getSummary();
		$base    = $this->getBase();

		PageTranslationHooks::$allowTargetEdit = true;
		$oldUser = $wgUser;
		$wgUser = $user;

		$error = '';
		$article = new Article( $title, 0 );
		$ok = $article->doDeleteArticle( $summary, false, 0, true, $error );
		if ( !$ok ) {
			$logger = new LogPage( 'pagetranslation' );
			$params = array(
				'user' => $this->getPerformer(),
				'target' => $base,
				'error' => base64_encode( serialize( $ok ) ), // This is getting ridiculous
			);
			$doer = User::newFromName( $this->getPerformer() );
			$msg = $this->getFull() ? 'deletefnok' : 'deletelnok';
			$logger->addEntry( $msg, $title, null, array( serialize( $params ) ), $doer );
		}

		PageTranslationHooks::$allowTargetEdit = false;

		$cache = wfGetCache( CACHE_DB );
		$pages = (array) $cache->get( wfMemcKey( 'pt-base', $base ) );
		$lastitem = array_pop( $pages );
		if ( $title->getPrefixedText() === $lastitem ) {
			$cache->delete( wfMemcKey( 'pt-base', $base ) );
			$logger = new LogPage( 'pagetranslation' );
			$params = array( 'user' => $this->getPerformer() );
			$doer = User::newFromName( $this->getPerformer() );
			$msg = $this->getFull() ? 'deletefok' : 'deletelok';
			$logger->addEntry( $msg, Title::newFromText( $base ), null, array( serialize( $params ) ), $doer );

			$tpage = TranslatablePage::newFromTitle( $title );
			$tpage->getTranslationPercentages( true );
			foreach ( $tpage->getTranslationPages() as $page ) {
				$page->invalidateCache();
			}
			$title->invalidateCache();
		}

		$wgUser = $oldUser;

		return true;
	}
function checkForEmpty($t)
{
    $deleteComment = "Deleting unused profile box page";
    if ($t) {
        $a = new Article($t);
        if ($a->exists()) {
            $content = $a->getContent();
            if ($content == "") {
                if ($a->doDeleteArticle($deleteComment)) {
                    echo $deleteComment . " " . $t->getText() . "\n";
                    return true;
                }
            }
        }
    }
    return false;
}
 /**
  * Helper function -- remove files and associated articles by Title
  * @param $title Title: title to be removed
  */
 public function deleteFileByTitle($title)
 {
     if ($title->exists()) {
         $file = wfFindFile($title, array('ignoreRedirect' => true));
         $noOldArchive = "";
         // yes this really needs to be set this way
         $comment = "removing for test";
         $restrictDeletedVersions = false;
         $status = FileDeleteForm::doDelete($title, $file, $noOldArchive, $comment, $restrictDeletedVersions);
         if (!$status->isGood()) {
             return false;
         }
         $article = new Article($title);
         $article->doDeleteArticle("removing for test");
         // see if it now doesn't exist; reload
         $title = Title::newFromText($title->getText(), NS_FILE);
     }
     return !($title && $title instanceof Title && $title->exists());
 }
function deleteDefaultMessages()
{
    $user = '******';
    $reason = 'No longer required';
    global $wgUser;
    $wgUser = User::newFromName($user);
    $wgUser->addGroup('bot');
    $dbr =& wfGetDB(DB_SLAVE);
    $res = $dbr->select(array('page', 'revision'), array('page_namespace', 'page_title'), array('page_namespace' => NS_MEDIAWIKI, 'page_latest=rev_id', 'rev_user_text' => 'MediaWiki default'));
    $dbw =& wfGetDB(DB_MASTER);
    while ($row = $dbr->fetchObject($res)) {
        if (function_exists('wfWaitForSlaves')) {
            wfWaitForSlaves(5);
        }
        $dbw->ping();
        $title = Title::makeTitle($row->page_namespace, $row->page_title);
        $article = new Article($title);
        $dbw->begin();
        $article->doDeleteArticle($reason);
        $dbw->commit();
    }
}
Example #7
0
<?php

include '../commandLine.inc';
$wgShowExceptionDetails = true;
$wgUser = User::newFromName('Wikia');
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->select('page', array('page_title'), array('page_namespace' => 200), 'BlameTor', array('LIMIT' => 5));
while ($row = $dbr->fetchObject($res)) {
    $wikiTitle = Title::newFromText($row->page_title, 200);
    $wikiArticle = new Article($wikiTitle);
    $userTitle = Title::newFromText($wikiTitle->getText(), NS_USER);
    if (!$userTitle->exists()) {
        // move to new location
        $wikiTitle->moveNoAuth($userTitle);
        echo "Moved " . $wikiTitle->getText() . "\n";
        continue;
    }
    $userArticle = new Article($userTitle);
    if ($wikiArticle->getContent() !== '' && $userArticle->getContent() == '') {
        // delete
        $userArticle->doDeleteArticle('making way for user page move', true, $userArticle->mTitle->getArticleID(Title::GAID_FOR_UPDATE));
        echo "Deleted " . $userTitle->getText() . "\n";
        // then move the page
        $wikiTitle->moveNoAuth($userTitle);
        echo "Moved " . $wikiTitle->getText() . "\n";
        continue;
    }
    echo "Nothing happened\n";
}
Example #8
0
 /**
  * delete board
  */
 public function deleteBoard($board)
 {
     wfProfileIn(__METHOD__);
     Forum::$allowToEditBoard = true;
     $article = new Article($board->getTitle());
     $article->doDeleteArticle('', true);
     Forum::$allowToEditBoard = false;
     wfProfileOut(__METHOD__);
 }
 /**
  *
  * Deletes the article with the given nfdid
  *
  */
 function deleteArticle($nfdid, $nfdReason)
 {
     global $wgUser, $wgLang;
     wfLoadExtensionMessages("NFDGuardian");
     // keep the article
     $dbr = wfGetDB(DB_SLAVE);
     // load the revision text
     $pageid = $dbr->selectField('nfd', array('nfd_page'), array('nfd_id' => $nfdid), __METHOD__);
     $t = Title::newFromID($pageid);
     if (!$t) {
         return false;
     }
     $r = Revision::newFromTitle($t);
     if (!$r) {
         return false;
     }
     $article = new Article($t);
     if (!$article) {
         return false;
     }
     $dateStr = gmdate('n/j/Y', time());
     //$wgLang->date(wfTimestampNow());
     $votes = $this->getVotes($nfdid, $dbr);
     $comment = wfMsgHtml('nfd_delete_message', $dateStr, $nfdReason['type'], $votes['deleteUsers'], $votes['keepUsers'], "[[" . $t->getText() . "]]", number_format($article->getCount(), 0, "", ","));
     $foundDup = false;
     if ($nfdReason['type'] == "dup") {
         //check if it was a duplicate
         $dupTitle = Title::newFromText($nfdReason['article']);
         if (!$dupTitle) {
             $dupTitle = Title::newFromText("Deleted-Article", NS_PROJECT);
         }
         if ($dupTitle) {
             $dupRev = Revision::newFromTitle($dupTitle);
             if ($dupRev) {
                 //the duplicate title exists, so turn the current article into a redirct
                 $editSuccess = $article->doEdit("#REDIRECT [[" . $dupTitle->getPrefixedURL() . "]]", $comment);
                 $foundDup = true;
                 self::markAsDup($nfdid, $pageid);
                 //log redirect in the nfd table
                 $log = new LogPage('nfd', false);
                 $log->addEntry('redirect', $t, $comment);
                 $commentDup = wfMsgHtml('nfd_dup_message', $dateStr, $nfdReason['type'], $votes['deleteUsers'], $votes['keepUsers'], "[[" . $t->getText() . "]]", number_format($article->getCount(), 0, "", ","), "[[" . $dupTitle->getText() . "]]");
                 $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, "NFD-Voter-Tool", "NFD Voter Tool", $commentDup);
                 $discussionTitle = $t->getTalkPage();
                 $text = "";
                 if ($discussionTitle->getArticleId() > 0) {
                     $r = Revision::newFromTitle($discussionTitle);
                     $text = $r->getText();
                 }
                 //add a comment to the discussion page
                 $articleDiscussion = new Article($discussionTitle);
                 $text .= "\n\n{$formattedComment}\n\n";
                 $articleDiscussion->doEdit($text, "");
             }
         }
     }
     //if we haven't found a duplicate, then go ahead and do the delete
     if (!$foundDup) {
         $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, "NFD-Voter-Tool", "NFD Voter Tool", $comment);
         $discussionTitle = $t->getTalkPage();
         $text = "";
         if ($discussionTitle->getArticleId() > 0) {
             $r = Revision::newFromTitle($discussionTitle);
             $text = $r->getText();
         }
         //add a comment to the discussion page
         $articleDiscussion = new Article($discussionTitle);
         $text .= "\n\n{$formattedComment}\n\n";
         $articleDiscussion->doEdit($text, "");
         //now delete the article
         $editSuccess = $article->doDeleteArticle($comment);
         //no need to log in the deletion table b/c doDeleteArticle does it for you
         //log same delete in the nfd table
         $log = new LogPage('nfd', false);
         $log->addEntry('delete', $t, $comment);
     }
 }
Example #10
0
 public function execute()
 {
     global $wgUser;
     # Change to current working directory
     $oldCwd = getcwd();
     chdir($oldCwd);
     # Options processing
     $user = $this->getOption('u', 'Delete page script');
     $reason = $this->getOption('r', '');
     $interval = $this->getOption('i', 0);
     if ($this->hasArg()) {
         $file = fopen($this->getArg(), 'r');
     } else {
         $file = $this->getStdin();
     }
     # Setup
     if (!$file) {
         $this->error("Unable to read file, exiting", true);
     }
     $wgUser = User::newFromName($user);
     $dbw = wfGetDB(DB_MASTER);
     # Handle each entry
     for ($linenum = 1; !feof($file); $linenum++) {
         $line = trim(fgets($file));
         if ($line == '') {
             continue;
         }
         $page = Title::newFromText($line);
         if (is_null($page)) {
             $this->output("Invalid title '{$line}' on line {$linenum}\n");
             continue;
         }
         if (!$page->exists()) {
             $this->output("Skipping nonexistent page '{$line}'\n");
             continue;
         }
         $this->output($page->getPrefixedText());
         $dbw->begin();
         if ($page->getNamespace() == NS_FILE) {
             $art = new ImagePage($page);
             $img = wfFindFile($art->mTitle);
             if (!$img || !$img->isLocal() || !$img->delete($reason)) {
                 $this->output(" FAILED to delete image file... ");
             }
         } else {
             $art = new Article($page);
         }
         $success = $art->doDeleteArticle($reason);
         $dbw->commit();
         if ($success) {
             $this->output(" Deleted!\n");
         } else {
             $this->output(" FAILED to delete article\n");
         }
         if ($interval) {
             sleep($interval);
         }
         wfWaitForSlaves();
     }
 }
Example #11
0
$wgTitle = $page;
// this cannot be NULL
print $page->getPrefixedText();
$dbw->begin();
$nspace = $page->getNamespace();
$success = 0;
$removed = 0;
if (in_array($nspace, array(NS_IMAGE, NS_FILE))) {
    $file = wfLocalFile($page);
    if ($file) {
        $oldimage = null;
        // Must be passed by reference
        $success = FileDeleteForm::doDelete($page, $file, $oldimage, $reason, $suppress)->isOK();
        $removed = 1;
    }
}
if ($removed == 0) {
    $page_id = $page->getArticleID();
    $art = new Article($page);
    $success = $art->doDeleteArticle($reason, $suppress);
}
$dbw->commit();
if ($success) {
    print "\n";
} else {
    print " FAILED\n";
}
if ($interval) {
    sleep($interval);
}
wfWaitForSlaves();
	$text = $revision->getText();
	if ( $text === false ) {
		echo "Cannot load text: $line\n";
		continue;
	}
	$redir = Title::newFromRedirect( $text );
	if ( !$redir ) {
		echo "Not a redirect: $line\n";
		continue;
	}


	if ( $unbrokenTitle->exists() ) {
		# Exists already, just delete this redirect
		$article = new Article( $brokenTitle );
		$success = $article->doDeleteArticle( 'Redundant redirect' );
		if ( $success ) {
			echo "Deleted: $line\n";
		} else {
			echo "Failed to delete: $line\n";
		}
	} else {
		# Does not exist, move this redirect to the unbroken title
		# Do not leave a redirect behind
		$result = $brokenTitle->moveTo( $unbrokenTitle, /*auth*/ false,
			'Fixing broken redirect', /*createRedirect*/ false );
		if ( $result === true ) {
			echo "Moved: $line\n";
		} else {
			$error = reset( $result );
			echo "Move error: {$error[0]}: $line\n";
<?php

require_once 'commandLine.inc';
$users = array("A.langley21", "ABCBlind", "ADILeak1", "ADresses0", "AEEL", "AEGONDirect", "AJohnson420", "ALexandra2012", "ASIANNATION", "ASMUDIN", "ATEAMHOMEIMPROVEMENT", "AZHeart", "Aaanetsolution", "Aacdevices", "Aadeshwarmetal", "Aadityaceramics", "Aadseducation", "Aagjeaaiza", "Aahnaawasthi", "Aakarexport", "Aakash101", "Aakashmehraa", "Aakritipackaging", "Aanalmagnet", "Aangel123", "Aangell79", "Aarankell123", "Aarceeengineeringworks", "Aarindustrial", "Aaronabel143", "Aaronhenryj", "Aaronlazarss", "Aaronlewis142", "Aaronslater", "Aaronstatonss", "Aartifashion", "Aashelyweng16", "Aatouspower", "Aatouspowerindia", "Aatravelromania", "Aba223", "Abacusmanufacturers", "Abang12", "Abbigilabbot", "Abbittedeen", "Abbittlothar", "Abccarpetcleaning", "Abclcarpet", "Abdellah", "Abdihow", "Abelabbey73", "Abeladam21", "Abelhenderson", "Abeniwilson", "Abercrombieclothes", "Abetterhealthway", "Abeyaustin111", "Abhilashenterprises", "Abhimanyushama003", "Abhisays", "Abhishekarar", "Abhishekenterprises", "Abhishekentp", "Abhishekmishra", "Abhishekpaul", "Abhishektch", "Abia524", "Abia619", "Abileweb", "Abilio", "Abimj", "Ableelectropolishing", "Abluescarab", "Abodedrugs", "AboutAsbestos", "Abrahamexports", "AbramCovington", "Absoluteair", "Abswood", "Abudhabirelocation", "Abunzareview7", "Acaforreal", "Acaiberryboutique", "Acarpetcleaning", "Accentstudios", "Accesscontrolsystem", "Accessories", "Accessoriesbuy2", "Accommdotcom", "Accountia", "Accountmmo", "Acdrives", "Acehardware", "Aceleertet", "Acer925", "Aceroinoxidable", "Achievablefashion", "Achievebeyond", "Achillemdz", "Achilles", "Acidrefluxdiet", "Acmeelevators", "AcneCream", "Acnehomeremedies2012", "Aconnect", "Acorncontrols", "Actech-drives", "Activatedliquid", "Activemds", "Activeseals", "Activitybreaks", "AdMaiorem", "Adalatham194", "AdalbertoRangel", "Adam-Sai", "AdamCartel", "Adambaldwinss", "Adambarnetts1", "Adamdevis", "Adamholland73", "Adamlf", "Adammarshale", "Adamparkar", "Adamwhi86", "Adanjay123", "Adanlloyd49", "Adapterlist", "AdaraHotel", "Adarshhosierymills", "Adasport01", "Addictivemedia", "Addisonclark94", "Addisoncurt", "Additivemaster", "Addy80", "Addysmith", "Adharvaamart", "Adiartech", "Adinkalis", "Adinojones", "Adiprcike", "Adithgraphicdesigns", "Aditya-finfab", "Adityainterior", "Adkins321", "Adksolar", "AdlerLaw", "Adneart01", "AdonesDe23", "Adoption25", "Adremoa", "Adren", "AdrianRKPS", "Adriana15", "Adrianaosorio11", "Adrianasimon", "Adrianhage", "Adrianogianninis", "Adrianus", "Adroit-techna", "Adryn", "Adt-florida", "Adultcallchat", "Advanced-Chiropractic-Rehab-Center", "Advanceddrying", "Advancedexteriors", "Advancedfootandanklesd", "Advancedhomes", "Advancerubber", "Advantagetreeny", "Adventurediscoverytreks", "Adventurespl", "AdvertisingCEO", "Advonnikon", "Adwardcarele", "Adwardmaklon", "Adwardmiclen", "Adwarnsiyan", "Adwords", "Aechellecaves", "Aelbane", "Aepiot", "Aeroequipments", "Aeronejames", "Aeronejamez", "Aeronejhomar33", "Aferrhasim", "Affiliate-radar", "AffiliateABCs", "AffiliateCoach", "Affilrev", "Affinitydrivingschools", "Affirmations9977", "Affluentpage", "Affordable_webhosting", "Affordabledentist", "Affordablereplica", "Affordablesmallbusinessseoservices", "Afia", "Aficaralaw", "Aforeverrecovery", "Africa-Travel", "Afrika111", "Afronom", "Afshispeaks", "Aftab111", "Aftab555", "Ag-af100", "Agabza2010", "Agelessmalereviews", "AgencyQ", "Agentzee", "Aggarwalrubberindustries", "Agiftidea", "Agingjohn", "Agnes11rb4v", "Agnes84561", "Agnesvann", "Agrainofsands", "Agriculturemachine", "Agriculturemachineindia", "Agritech", "Agtechnologies", "Aguapuroequipment", "Agustinpoteete", "Ahanna", "Ahfashion", "Ahito68", "Ahmedabadpneumatic", "Aiainsurance", "Aidenjump", "Ailasmoda", "Aimsinternational", "Aimyourway", "Air-separation-plant", "AirConditioningRepair", "AirGun-Depot", "Airconditioning", "Aires", "Airplanesimulatorgames", "Airporttaxi1", "Airroengineering", "Airtechgasplant", "Airtechgasplants", "Airtet", "Aisterwlsn", "Aithein", "AizaMarie101", "Ajantafoodproducts", "Ajayexim", "Ajayshirma", "Aje842", "Ajnabii", "Ajplumber", "Ak_271984", "Akalanka", "Akankshamart", "Akashfurniture", "Aki015", "Akif", "Akinggirl", "Akshayaboilers", "Akshayurja", "Alainc", "Alamannobjer923", "Alamlothar", "Alamocapital", "Alamoudi", "Alamowatches", "AlanRosinsky", "AlanaSophie", "Alangkarmazin", "Alankarmazin", "Alankarshilpa", "Alankingdave", "Alanmmaxzsd", "Alanpointing123", "Alansalton", "Alansfactoryoutlet", "Alastairclark90", "Albanyhomes", "Albanysalon", "Albanysheetrock", "Albanysuzuki", "Albee123", "Albert20", "AlbertDuran", "AlbertFontaine", "Albertaddy", "Albertaoil123", "Alberto%27s-Electric%2C-UCE", "Albertot1ago", "Albertrmikelscv", "Albertuimax", "Albertwochrisx", "Albertydx", "Albin", "Albiont11", "Albri1", "Albrightpatents", "Alcatelpbx", "Alcoholismtreatment", "Alcoholrehabfl", "Aldaren", "Aldarenxandar", "Alden32", "AldenEagle", "Aldennorris52", "Alder", "Alder-Eagle", "Aldiwan", "Aldora", "Aldougo", "AldrichDesmond", "AldrichDillon", "Aldwyn", "Aldzmodelo", "Alecramon", "AleenaShelly", "Aleksey1994j", "Alenntmaxgt", "Alenstuart", "Alenstuart007", "Alenturetx", "Alesanderburgess", "Aleseohubpages", "Alex00900", "Alex1223321", "Alex12321", "Alex17basler", "Alex2", "Alex2341", "Alex4395", "AlexJohnson420", "AlexJorden", "Alexagraf", "AlexanderDexter", "Alexanderwells642", "Alexandriatoyota", "Alexasakes", "Alexbanzamin", "Alexender", "Alexey", "Alexinawhite", "Alexiskillen", "Alexisnielsen", "Alexmartinyr", "Alexpolelein", "Alexrabe", "Alexreed975", "Alexrsmartins", "Alexsiyoen", "Alextrytomr", "Alextsui", "Alexwi1", "Alexz19", "Alfandi", "Alhindexports", "AliWatkins", "AliaBrown", "Aliadevyn", "Aliatemacx", "Aliatemaxfgh", "Aliatemaxv", "Alic015", "AlicaMetis", "Alicabacon", "Alice-Leung", "AliceHealthcare", "AliceIacuzzo", "Alicecheril", "Alicediets", "Alicemcintosh", "Alicenikolic", "Aliciadwyer", "AlignNet", "Alimessi10", "Alina1", "AlinaOrlova", "Alinagloria142", "Alinalagoviyer", "Alinapayne", "Alishahiggins", "Alishakhatri", "Alisonreddin", "Alissacordry", "Alixzarat", "Alizabaith", "Aljhur69", "Alkantenik", "AllElectric", "AllGreenLawns", "Allabouttoronto", "Allacesservices", "Allan285", "Allanalguire", "Allanta", "Allbestmessages", "Allblogtools", "Allcoast", "Alleganydental", "Allenkelly02", "Allenmorris36", "Allenssgarments", "Allgardenmachine", "Allgardenmachines", "Allhybrid", "Allianzexports", "Allina-jas", "Allisonbaunt", "Allisonfelix", "Allisonpaulsi924", "Allitsupported", "AllnOne", "Alloysteelpipes", "Allshore", "Allstate", "Allwc", "Allwinerecips", "Almamasmas", "Almasn4712", "Alnabiotech", "Alnikolic", "Alocalseo", "Alohaeverafter", "Alokrubber", "Alomari", "Alonfreediver", "Alorak", "Alphalinear", "Alreanbuc", "AltaMiraRecovery", "Altermarval", "Aluminum00", "Aluminumdiecasting", "Aluminumfence", "Alvin23", "AlvinCook", "Alvinbill", "Alvinbrown", "Alvinjoo", "Alvinolds", "Alviscuttingtools", "Alyajabeen", "Alycedesigns", "Amaalmcclure", "Amackley", "Amaiazohar", "Amalfis-Pizza", "Amandaranhami", "Amaralupin", "Amardan", "Amarketforce", "Amarrmartt", "Ambernecklace", "AmbitEnerg", "Ambit_Energy", "Ambrose", "Ambsil", "Amcguiness77", "Ameliabradshaw", "Ameliahoke411", "Amelm", "American-Invsco", "American-Striping", "Americantrainingonline", "Americarpetcommercial", "Americarpetfloors", "Amescastillo", "Amhebert100", "Ami4567", "Amiciziaeamore", "Amiclubwear", "Amidouche2011", "Amiegrace", "Aminconile", "Aminesbiotech", "Aminsiyone", "Aminul932", "Aminx89", "AmishHandcrafted", "Amit-Poreli", "Amitavaray", "Amitbajpai", "Amitgksingh", "Amitozsingh", "Amitsingh12", "Amjenfrank", "AmlenVigoth1", "Ammaf", "Ammyhilton", "Amod01nara", "Amol111", "Amolebonde", "Amperehourmeter", "Ampmfashion", "Amulo", "Amuorn", "AmyJohnson", "AmyPsa", "AmyTrenton", "Amyback795", "Amyfreeman", "Amyhall837", "Amyharris442", "Amyjackson", "Ana015", "Ana123", "Anab01", "AnabolicSteroids1", "Anaesthesia", "Anandhika", "Anandinternational", "Anandranawat", "AnanyaCreations", "Anapaul", "AnastassiaM", "Anazgombic", "AncientWisdom", "AnciraBuickGMC", "AnciraChevrolet", "Anciranissan", "Anddystand", "Andersonkid04", "Andin2187", "Andr10985", "Andrearayne", "Andrei49", "Andrejewelry", "Andrew-Edwards", "AndrewEdwards24", "Andrewclay57", "Andrewcorbin", "Andrewcruise12", "Andrewgreek", "Andrewgreggs", "Andrewhelland", "Andrewlucky", "Andrewmaxtr", "Andrewmichel");
$wgUser = User::newFromName("MiscBot");
$articleTitles = array("/profilebox-live", "/profilebox-aboutme", "/profilebox-occupation");
$totalDeleted = 0;
$deleteComment = "Deleting unused profile box page";
foreach ($users as $user) {
    $u = User::newFromName($user);
    if ($u) {
        $userPage = $u->getUserPage();
        foreach ($articleTitles as $title) {
            $t = Title::newFromText($userPage->getBaseText() . $title, NS_USER);
            if ($t) {
                $a = new Article($t);
                if ($a->exists()) {
                    if ($a->doDeleteArticle($deleteComment)) {
                        echo $deleteComment . " " . $t->getText() . "\n";
                    }
                }
            }
        }
    }
}
 /**
  *
  */
 protected function deleteFile($name)
 {
     $t = Title::newFromText($name, NS_FILE);
     $this->assertTrue($t->exists(), "File '{$name}' exists");
     if ($t->exists()) {
         $file = wfFindFile($name, array('ignoreRedirect' => true));
         $empty = "";
         FileDeleteForm::doDelete($t, $file, $empty, "none", true);
         $a = new Article($t);
         $a->doDeleteArticle("testing");
     }
     $t = Title::newFromText($name, NS_FILE);
     $this->assertFalse($t->exists(), "File '{$name}' was deleted");
 }
Example #15
0
 function executeScript($type)
 {
     global $wgOut, $wgRequest, $wgUser;
     wfLoadExtensionMessages('Maintenance');
     @set_time_limit(0);
     //if we can, disable the time limit
     $this->setHeaders();
     $wgOut->addHTML($wgUser->getSkin()->makeKnownLinkObj($this->getTitle(), wfMsgHtml('maintenance-backlink')) . '<br />');
     switch ($type) {
         case 'changePassword':
             $name = $wgRequest->getText('wpName');
             $password = $wgRequest->getText('wpPassword');
             $user = User::newFromName($name);
             if (!is_object($user) || !$user->getId()) {
                 $wgOut->addWikiMsg('maintenance-invalidname');
                 return;
             }
             $dbw = wfGetDB(DB_MASTER);
             $user->setPassword($password);
             $user->saveSettings();
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'createAndPromote':
             $name = $wgRequest->getText('wpName');
             $password = $wgRequest->getText('wpPassword');
             $bcrat = $wgRequest->getCheck('wpBcrat');
             $user = User::newFromName($name);
             if (!is_object($user)) {
                 $wgOut->addWikiMsg('maintenance-invalidname');
                 return;
             } elseif (0 != $user->idForName()) {
                 $wgOut->addWikiMsg('maintenance-userexists');
                 return;
             }
             $user->addToDatabase();
             $user->setPassword($password);
             $user->saveSettings();
             $user->addGroup('sysop');
             if ($bcrat) {
                 $user->addGroup('bureaucrat');
             }
             $ssu = new SiteStatsUpdate(0, 0, 0, 0, 1);
             $ssu->doUpdate();
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'deleteBatch':
             $reason = $wgRequest->getText('wpReason', '');
             $interval = 0;
             $pages = $wgRequest->getText('wpDelete');
             $dbw = wfGetDB(DB_MASTER);
             $lines = explode("\n", $pages);
             foreach ($lines as &$line) {
                 $line = trim($line);
                 if ($line == '') {
                     continue;
                 }
                 $page = Title::newFromText($line);
                 if (is_null($page)) {
                     $wgOut->addWikiMsg('maintenance-invalidtitle', $line);
                     continue;
                 }
                 if (!$page->exists()) {
                     $wgOut->addWikiMsg('maintenance-titlenoexist', $line);
                     continue;
                 }
                 $return = '* ' . $page->getPrefixedText();
                 // Switch the user here from the current user to Delete page script
                 $OldUser = $wgUser;
                 $wgUser = User::newFromName('Delete page script');
                 // Begin transaction
                 $dbw->begin();
                 if ($page->getNamespace() == NS_IMAGE) {
                     $art = new ImagePage($page);
                     $img = wfFindFile($art->mTitle);
                     if (!$img || !$img->delete($reason)) {
                         $return .= '... ' . wfMsg('maintenance-failed');
                     }
                 } else {
                     $art = new Article($page);
                 }
                 $success = $art->doDeleteArticle($reason);
                 // Commit changes to the database
                 $dbw->commit();
                 // ...and switch user back to the old user
                 $wgUser = $OldUser;
                 if ($success) {
                     $return .= '... ' . wfMsg('maintenance-deleted');
                 } else {
                     $return .= '... ' . wfMsg('maintenance-failed');
                 }
                 $wgOut->addWikiText($return);
                 waitForSlaves(5);
             }
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'deleteRevision':
             $delete = $wgRequest->getText('wpDelete');
             $revisions = explode("\n", $delete);
             $wgOut->addWikiMsg('maintenance-revdelete', implode(', ', $revisions), wfWikiID());
             $affected = 0;
             // Switch the user here from the current user to Delete page script
             $OldUser = $wgUser;
             $wgUser = User::newFromName('Delete page script');
             $dbw = wfGetDB(DB_MASTER);
             foreach ($revisions as $revID) {
                 $dbw->insertSelect('archive', array('page', 'revision'), array('ar_namespace' => 'page_namespace', 'ar_title' => 'page_title', 'ar_comment' => 'rev_comment', 'ar_user' => 'rev_user', 'ar_user_text' => 'rev_user_text', 'ar_timestamp' => 'rev_timestamp', 'ar_minor_edit' => 'rev_minor_edit', 'ar_rev_id' => 'rev_id', 'ar_text_id' => 'rev_text_id'), array('rev_id' => $revID, 'page_id = rev_page'), __METHOD__);
                 if (!$dbw->affectedRows()) {
                     $wgOut->addWikiMsg('maintenance-revnotfound', array($revID));
                 } else {
                     $affected += $dbw->affectedRows();
                     $dbw->delete('revision', array('rev_id' => $revID));
                 }
             }
             // ...and switch user back to the old user
             $wgUser = $OldUser;
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'purgeDeletedText':
             # Data should come off the master, wrapped in a transaction
             $dbw = wfGetDB(DB_MASTER);
             $dbw->begin();
             # compute table names
             $tbl_arc = $dbw->tableName('archive');
             $tbl_rev = $dbw->tableName('revision');
             $tbl_txt = $dbw->tableName('text');
             # Delete as appropriate
             $dbw->query("TRUNCATE TABLE {$tbl_arc}");
             // list of "valid" text ids
             $new_ids = array();
             $new_start = 0;
             // list of "existing" text ids
             $old_ids = array();
             $old_start = 0;
             // index id
             $id = 1;
             // list of ids to be deleted
             $del_ids = array();
             while ($id > 0 && count($del_ids) < 1000) {
                 // get some new "valid" text ids
                 if (count($new_ids) == 0) {
                     $res = $dbw->query("SELECT DISTINCTROW rev_text_id FROM {$tbl_rev} ORDER BY rev_text_id ASC LIMIT {$new_start},100");
                     while ($row = $dbw->fetchObject($res)) {
                         $new_ids[$row->rev_text_id] = $row->rev_text_id;
                     }
                     if (count($new_ids) == 0) {
                         $id = 0;
                     } else {
                         $new_start += count($new_ids);
                     }
                 }
                 // get some new "existing" text ids
                 if (count($old_ids) == 0) {
                     $res = $dbw->query("SELECT DISTINCTROW old_id FROM {$tbl_txt} ORDER BY old_id ASC LIMIT {$old_start},100");
                     while ($row = $dbw->fetchObject($res)) {
                         $old_ids[$row->old_id] = $row->old_id;
                     }
                     if (count($old_ids) == 0) {
                         $id = 0;
                     } else {
                         $old_start += count($old_ids);
                     }
                 }
                 // for all ids, check that existing ids are valid
                 while (count($new_ids) > 0 && count($old_ids) > 0) {
                     if (isset($new_ids[$id])) {
                         unset($new_ids[$id]);
                     } else {
                         if (isset($old_ids[$id])) {
                             $del_ids[] = $id;
                         }
                     }
                     unset($old_ids[$id]);
                     $id += 1;
                 }
             }
             // print result
             foreach ($del_ids as $del_id) {
                 $wgOut->addHTML(strval($del_id) . '<br/>');
             }
             // delete rows
             if (count($del_ids) > 0) {
                 $set = implode(', ', $del_ids);
                 $dbw->query("DELETE FROM {$tbl_txt} WHERE old_id IN ( {$set} )");
             }
             // this solution consummes too much memory
             //# Get "active" text records from the revisions table
             //$res = $dbw->query( "SELECT DISTINCTROW rev_text_id FROM $tbl_rev" );
             //while( $row = $dbw->fetchObject( $res ) ) {
             //    $cur[] = $row->rev_text_id;
             //}
             //# Get the IDs of all text records not in these sets
             //$set = implode( ', ', $cur );
             //$res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" );
             //$old = array();
             //while( $row = $dbw->fetchObject( $res ) ) {
             //    $old[] = $row->old_id;
             //}
             //$count = count( $old );
             //# Delete as appropriate
             //if( $count ) {
             //    $set = implode( ', ', $old );
             //    $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" );
             //}
             // this solution is too slow
             //$res = $dbw->query( "SELECT DISTINCTROW old_id FROM $tbl_txt WHERE NOT EXISTS (SELECT * FROM $tbl_rev WHERE $tbl_rev.rev_text_id = $tbl_txt.old_id)" );
             //while( $row = $dbw->fetchObject( $res ) ) {
             //    $old_id = $row->old_id;
             //    $wgOut->addHTML( strval($old_id).'<br/>' );
             //}
             # done
             $dbw->commit();
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'eval':
             $temp = error_reporting(E_ALL);
             ob_start();
             $str = eval($wgRequest->getText('wpCode', 'return;'));
             $ext = ob_get_clean();
             error_reporting(0);
             if ($ext) {
                 $wgOut->addHTML(nl2br($ext) . '<hr />');
             }
             if (!$str) {
                 // do nothing
             } elseif (is_string($str)) {
                 $wgOut->addHTML(nl2br($str) . '<hr />');
             } else {
                 $wgOut->addHTML(nl2br(var_export($str, true)) . '<hr />');
             }
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'initEditCount':
             global $wgDBservers;
             $dbw = wfGetDB(DB_MASTER);
             $user = $dbw->tableName('user');
             $revision = $dbw->tableName('revision');
             $dbver = $dbw->getServerVersion();
             $dbr = wfGetDB(DB_SLAVE);
             $chunkSize = 100;
             $lastUser = $dbr->selectField('user', 'MAX(user_id)', '', __FUNCTION__);
             $start = microtime(true);
             $migrated = 0;
             for ($min = 0; $min <= $lastUser; $min += $chunkSize) {
                 $max = $min + $chunkSize;
                 $result = $dbr->query("SELECT\r\n\t\t\t\t\t\t\tuser_id,\r\n\t\t\t\t\t\t\tCOUNT(rev_user) AS user_editcount\r\n\t\t\t\t\t\tFROM {$user}\r\n\t\t\t\t\t\tLEFT OUTER JOIN {$revision} ON user_id=rev_user\r\n\t\t\t\t\t\tWHERE user_id > {$min} AND user_id <= {$max}\r\n\t\t\t\t\t\tGROUP BY user_id", 'initEditCount');
                 while ($row = $dbr->fetchObject($result)) {
                     $dbw->update('user', array('user_editcount' => $row->user_editcount), array('user_id' => $row->user_id), 'initEditCount');
                     ++$migrated;
                 }
                 $dbr->freeResult($result);
                 waitForSlaves(10);
             }
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'initStats':
             $dbr = wfGetDB(DB_SLAVE);
             $edits = $dbr->selectField('revision', 'COUNT(*)', '', __METHOD__);
             $edits += $dbr->selectField('archive', 'COUNT(*)', '', __METHOD__);
             $wgOut->addWikiMsg('maintenance-stats-edits', $edits);
             global $wgContentNamespaces;
             $good = $dbr->selectField('page', 'COUNT(*)', array('page_namespace' => $wgContentNamespaces, 'page_is_redirect' => 0, 'page_len > 0'), __METHOD__);
             $wgOut->addWikiMsg('maintenance-stats-articles', $good);
             $pages = $dbr->selectField('page', 'COUNT(*)', '', __METHOD__);
             $wgOut->addWikiMsg('maintenance-stats-pages', $pages);
             $users = $dbr->selectField('user', 'COUNT(*)', '', __METHOD__);
             $wgOut->addWikiMsg('maintenance-stats-users', $users);
             $admin = $dbr->selectField('user_groups', 'COUNT(*)', array('ug_group' => 'sysop'), __METHOD__);
             $wgOut->addWikiMsg('maintenance-stats-admins', $admin);
             $image = $dbr->selectField('image', 'COUNT(*)', '', __METHOD__);
             $wgOut->addWikiMsg('maintenance-stats-images', $image);
             if (!$wgRequest->getCheck('wpNoview')) {
                 $views = $dbr->selectField('page', 'SUM(page_counter)', '', __METHOD__);
                 $wgOut->addWikiMsg('maintenance-stats-views', $views);
             }
             $wgOut->addWikiMsg('maintenance-stats-update');
             $dbw = wfGetDB(DB_MASTER);
             $values = array('ss_total_edits' => $edits, 'ss_good_articles' => $good, 'ss_total_pages' => $pages, 'ss_users' => $users, 'ss_admins' => $admin, 'ss_images' => $image);
             $conds = array('ss_row_id' => 1);
             $views = array('ss_total_views' => isset($views) ? $views : 0);
             if ($wgRequest->getCheck('wpUpdate')) {
                 $dbw->update('site_stats', $values, $conds, __METHOD__);
             } else {
                 $dbw->delete('site_stats', $conds, __METHOD__);
                 $dbw->insert('site_stats', array_merge($values, $conds, $views), __METHOD__);
             }
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'moveBatch':
             $reason = $wgRequest->getText('wpReason', '');
             $interval = 0;
             $pages = $wgRequest->getText('wpMove');
             $dbw = wfGetDB(DB_MASTER);
             $lines = explode("\n", $pages);
             foreach ($lines as $line) {
                 $parts = array_map('trim', explode('|', $line));
                 if (count($parts) != 2) {
                     continue;
                 }
                 $source = Title::newFromText($parts[0]);
                 $dest = Title::newFromText($parts[1]);
                 if (is_null($source) || is_null($dest)) {
                     continue;
                 }
                 $wgOut->addWikiText('* ' . wfMsg('maintenance-move', array($source->getPrefixedText(), $dest->getPrefixedText())));
                 $dbw->begin();
                 $err = $source->moveTo($dest, false, $reason);
                 if ($err !== true) {
                     $wgOut->addWikiText('** ' . wfMsg('maintenance-movefail', array($err)));
                 }
                 $dbw->commit();
                 waitForSlaves(5);
             }
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'reassignEdits':
             $wpFrom = $wgRequest->getVal('wpFrom');
             $wpTo = $wgRequest->getVal('wpTo');
             if (User::isIP($wpFrom)) {
                 $from = new User();
                 $from->setId(0);
                 $from->setName($wpFrom);
             } else {
                 $from = User::newFromName($wpFrom);
             }
             if (User::isIP($wpTo)) {
                 $to = new User();
                 $to->setId(0);
                 $to->setName($wpTo);
             } else {
                 $to = User::newFromName($wpTo);
             }
             if ($to->getId() || $wgRequest->getCheck('wpForce')) {
                 $report = $wgRequest->getCheck('wpReport');
                 $dbw = wfGetDB(DB_MASTER);
                 $dbw->immediateBegin();
                 $rcond = $from->getId() ? array('rev_user' => $from->getId()) : array('rev_user_text' => $from->getName());
                 $res = $dbw->select('revision', 'COUNT(*) AS count', $rcond, 'Maintenance::reassignEdits');
                 $row = $dbw->fetchObject($res);
                 $cur = $row->count;
                 $wgOut->addWikiMsg('maintenance-re-ce', $cur);
                 $acond = $from->getId() ? array('ar_user' => $from->getId()) : array('ar_user_text' => $from->getName());
                 $res = $dbw->select('archive', 'COUNT(*) AS count', $acond, 'Maintenance::reassignEdits');
                 $row = $dbw->fetchObject($res);
                 $del = $row->count;
                 $wgOut->addWikiMsg('maintenance-re-de', $del);
                 if (!$wgRequest->getCheck('wpRc')) {
                     $ccond = $from->getId() ? array('rc_user' => $from->getId()) : array('rc_user_text' => $from->getName());
                     $res = $dbw->select('recentchanges', 'COUNT(*) AS count', $ccond, 'Maintenance::reassignEdits');
                     $row = $dbw->fetchObject($res);
                     $rec = $row->count;
                     $wgOut->addWikiMsg('maintenance-re-rce', $rec);
                 } else {
                     $rec = 0;
                 }
                 $total = $cur + $del + $rec;
                 $wgOut->addWikiMsg('maintenance-re-total', $total);
                 if (!$report) {
                     $rspec = array('rev_user' => $to->getId(), 'rev_user_text' => $to->getName());
                     $res = $dbw->update('revision', $rspec, $rcond, 'Maintenance::reassignEdits');
                     $aspec = array('ar_user' => $to->getId(), 'ar_user_text' => $to->getName());
                     $res = $dbw->update('archive', $aspec, $acond, 'Maintenance::reassignEdits');
                     if (!$wgRequest->getCheck('wpRc')) {
                         $cspec = array('rc_user' => $to->getId(), 'rc_user_text' => $to->getName());
                         $res = $dbw->update('recentchanges', $cspec, $ccond, 'Maintenance::reassignEdits');
                     }
                 }
                 $dbw->immediateCommit();
                 if ($report) {
                     $wgOut->addWikiMsg('maintenance-re-rr', wfMsg('maintenance-re-report'));
                 }
             } else {
                 $ton = $to->getName();
                 $wgOut->addWikiMsg('maintenance-re-nf', $ton);
             }
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'runJobs':
             $maxJobs = 10000;
             $dbw = wfGetDB(DB_MASTER);
             $n = 0;
             while ($dbw->selectField('job', 'count(*)', '', 'runJobs.php')) {
                 $offset = 0;
                 for (;;) {
                     $job = Job::pop($offset);
                     if ($job == false) {
                         break;
                     }
                     waitForSlaves(5);
                     $wgOut->addWikiText("* " . $job->id . "  " . $job->toString());
                     $offset = $job->id;
                     if (!$job->run()) {
                         $wgOut->addWikiText("** " . wfMsg('maintenance-error', array($job->error)));
                     }
                     if ($maxJobs && ++$n > $maxJobs) {
                         break 2;
                     }
                 }
             }
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'showJobs':
             $dbw = wfGetDB(DB_MASTER);
             $count = $dbw->selectField('job', 'count(*)', '', 'runJobs.php');
             $wgOut->addHTML($count);
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'stats':
             global $wgMemc;
             if (get_class($wgMemc) == 'FakeMemCachedClient') {
                 $wgOut->addWikiMsg('maintenance-memc-fake');
                 return;
             }
             $wgOut->addWikiText('<h2>' . wfMsg('maintenance-memc-requests') . '</h2>');
             $session = intval($wgMemc->get(wfMemcKey('stats', 'request_with_session')));
             $noSession = intval($wgMemc->get(wfMemcKey('stats', 'request_without_session')));
             $total = $session + $noSession;
             $requests = sprintf(wfMsg('maintenance-memc-withsession') . "      %-10d %6.2f%%\n", $session, $session / $total * 100) . '<br />';
             $requests .= sprintf(wfMsg('maintenance-memc-withoutsession') . "   %-10d %6.2f%%\n", $noSession, $noSession / $total * 100) . '<br />';
             $requests .= sprintf(wfMsg('maintenance-memc-total') . "             %-10d %6.2f%%\n", $total, 100) . '<br />';
             $wgOut->addWikiText($requests);
             $wgOut->addWikiText('<h2>' . wfMsg('maintenance-memc-parsercache') . '</h2>');
             $hits = intval($wgMemc->get(wfMemcKey('stats', 'pcache_hit')));
             $invalid = intval($wgMemc->get(wfMemcKey('stats', 'pcache_miss_invalid')));
             $expired = intval($wgMemc->get(wfMemcKey('stats', 'pcache_miss_expired')));
             $absent = intval($wgMemc->get(wfMemcKey('stats', 'pcache_miss_absent')));
             $stub = intval($wgMemc->get(wfMemcKey('stats', 'pcache_miss_stub')));
             $total = $hits + $invalid + $expired + $absent + $stub;
             $pcache = sprintf(wfMsg('maintenance-memc-hits') . "              %-10d %6.2f%%\n", $hits, $hits / $total * 100) . '<br />';
             $pcache .= sprintf(wfMsg('maintenance-memc-invalid') . "           %-10d %6.2f%%\n", $invalid, $invalid / $total * 100) . '<br />';
             $pcache .= sprintf(wfMsg('maintenance-memc-expired') . "           %-10d %6.2f%%\n", $expired, $expired / $total * 100) . '<br />';
             $pcache .= sprintf(wfMsg('maintenance-memc-absent') . "            %-10d %6.2f%%\n", $absent, $absent / $total * 100) . '<br />';
             $pcache .= sprintf(wfMsg('maintenance-memc-stub') . "    %-10d %6.2f%%\n", $stub, $stub / $total * 100) . '<br />';
             $pcache .= sprintf(wfMsg('maintenance-memc-total') . "             %-10d %6.2f%%\n", $total, 100) . '<br />';
             $wgOut->addWikiText($pcache);
             $hits = intval($wgMemc->get(wfMemcKey('stats', 'image_cache_hit')));
             $misses = intval($wgMemc->get(wfMemcKey('stats', 'image_cache_miss')));
             $updates = intval($wgMemc->get(wfMemcKey('stats', 'image_cache_update')));
             $total = $hits + $misses;
             $wgOut->addWikiText('<h2>' . wfMsg('maintenance-memc-imagecache') . '</h2>');
             $icache = sprintf(wfMsg('maintenance-memc-hits') . "              %-10d %6.2f%%\n", $hits, $hits / $total * 100) . '<br />';
             $icache .= sprintf(wfMsg('maintenance-memc-misses') . "            %-10d %6.2f%%\n", $misses, $misses / $total * 100) . '<br />';
             $icache .= sprintf(wfMsg('maintenance-memc-updates') . "           %-10d\n", $updates) . '<br />';
             $wgOut->addWikiText($icache);
             $hits = intval($wgMemc->get(wfMemcKey('stats', 'diff_cache_hit')));
             $misses = intval($wgMemc->get(wfMemcKey('stats', 'diff_cache_miss')));
             $uncacheable = intval($wgMemc->get(wfMemcKey('stats', 'diff_uncacheable')));
             $total = $hits + $misses + $uncacheable;
             $wgOut->addWikiText('<h2>' . wfMsg('maintenance-memc-diffcache') . '</h2>');
             $dcache = sprintf(wfMsg('maintenance-memc-hits') . "              %-10d %6.2f%%\n", $hits, $hits / $total * 100) . '<br />';
             $dcache .= sprintf(wfMsg('maintenance-memc-misses') . "            %-10d %6.2f%%\n", $misses, $misses / $total * 100) . '<br />';
             $dcache .= sprintf(wfMsg('maintenance-memc-uncacheable') . "       %-10d %6.2f%%\n", $uncacheable, $uncacheable / $total * 100) . '<br />';
             $wgOut->addWikiText($dcache);
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         case 'sql':
             $db = wfGetDB(DB_MASTER);
             $q = $wgRequest->getText('wpQuery', '');
             $db->begin();
             try {
                 $r = $db->query($q, 'Maintenance::sql.php');
             } catch (DBQueryError $e) {
                 global $wgShowSQLErrors;
                 $temp = $wgShowSQLErrors;
                 $wgShowSQLErrors = true;
                 $wgOut->addWikiText('<pre style="overflow: auto">' . $e->getText() . '</pre>');
                 $wgShowSQLErrors = $temp;
                 $r = false;
             }
             if ($r === true) {
                 $wgOut->addWikiMsg('maintenance-sql-aff', $db->affectedRows());
             } elseif ($r instanceof ResultWrapper) {
                 $res = array();
                 for ($i = 0; $i < $r->numRows(); $i++) {
                     $row = $r->fetchRow();
                     $res[] = $row;
                     foreach ($row as $key => $meh) {
                         $names[] = $key;
                     }
                 }
                 $names = array_unique($names);
                 $rtable = '<table class="wikitable"><tr>';
                 foreach ($names as $name) {
                     if (is_numeric($name)) {
                         continue;
                     }
                     $rtable .= '<th>' . $name . '</th>';
                 }
                 $rtable .= '</tr>';
                 foreach ($res as $data) {
                     $rtable .= '<tr>';
                     foreach ($data as $key => $value) {
                         if (is_numeric($key)) {
                             continue;
                         }
                         $rtable .= '<td><nowiki>' . $value . '</nowiki></td>';
                     }
                     $rtable .= '</tr>';
                 }
                 $rtable .= '</table>';
                 $wgOut->addWikiMsg('maintenance-sql-res', $r->numRows(), $rtable);
                 $db->freeResult($r);
             }
             $db->commit();
             $wgOut->addWikiMsg('maintenance-success', $type);
             break;
         default:
             $wgOut->addWikiMsg('maintenance-invalidtype');
             return;
     }
 }
 public function checkI18N($sGroup, $bValue = true)
 {
     $oTitle = Title::newFromText('group-' . $sGroup, NS_MEDIAWIKI);
     $oArticle = null;
     if ($bValue === false) {
         if ($oTitle->exists()) {
             $oArticle = new Article($oTitle);
             $oArticle->doDeleteArticle('Group does no more exist');
         }
     } else {
         if (!$oTitle->exists()) {
             $oArticle = new Article($oTitle);
             $oArticle->doEdit($sGroup, '', EDIT_NEW);
         }
     }
 }
 public function removeTemplate($name)
 {
     $id = SpecialNoticeTemplate::getTemplateId($name);
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('cn_assignments', 'asn_id', array('tmp_id' => $id), __METHOD__);
     if ($dbr->numRows($res) > 0) {
         $this->showError('centralnotice-template-still-bound');
         return;
     } else {
         // Log the removal of the banner
         $this->logBannerChange('removed', $id);
         $dbw = wfGetDB(DB_MASTER);
         $dbw->begin();
         $dbw->delete('cn_templates', array('tmp_id' => $id), __METHOD__);
         $dbw->commit();
         $article = new Article(Title::newFromText("centralnotice-template-{$name}", NS_MEDIAWIKI));
         $article->doDeleteArticle('CentralNotice automated removal');
     }
 }
Example #18
0
 /**
  * Function to merge user pages
  *
  * Deletes all pages when merging to Anon
  * Moves user page when the target user page does not exist or is empty
  * Deletes redirect if nothing links to old page
  * Deletes the old user page when the target user page exists
  *
  * @param $newuser_text string Username to merge pages TO
  * @param $olduser_text string Username of user to remove pages FROM
  *
  * @return bool True on completion
  *
  * @author Matthew April <*****@*****.**>
  */
 private function movePages($newuser_text, $olduser_text)
 {
     global $wgContLang;
     $oldusername = trim(str_replace('_', ' ', $olduser_text));
     $oldusername = Title::makeTitle(NS_USER, $oldusername);
     $newusername = Title::makeTitleSafe(NS_USER, $wgContLang->ucfirst($newuser_text));
     # select all user pages and sub-pages
     $dbr = wfGetDB(DB_SLAVE);
     $pages = $dbr->select('page', array('page_namespace', 'page_title'), array('page_namespace' => array(NS_USER, NS_USER_TALK), $dbr->makeList(array('page_title' => $dbr->buildLike($oldusername->getDBkey() . '/', $dbr->anyString()), 'page_title' => $oldusername->getDBkey()), LIST_OR)));
     $output = '';
     foreach ($pages as $row) {
         $oldPage = Title::makeTitleSafe($row->page_namespace, $row->page_title);
         $newPage = Title::makeTitleSafe($row->page_namespace, preg_replace('!^[^/]+!', $newusername->getDBkey(), $row->page_title));
         if ($newuser_text === "Anonymous") {
             # delete ALL old pages
             if ($oldPage->exists()) {
                 $oldPageArticle = new Article($oldPage, 0);
                 $oldPageArticle->doDeleteArticle($this->msg('usermerge-autopagedelete')->inContentLanguage()->text());
                 $oldLink = Linker::linkKnown($oldPage);
                 $output .= Html::rawElement('li', array('class' => 'mw-renameuser-pe'), $this->msg('usermerge-page-deleted')->rawParams($oldLink)->escaped());
             }
         } elseif ($newPage->exists() && !$oldPage->isValidMoveTarget($newPage) && $newPage->getLength() > 0) {
             # delete old pages that can't be moved
             $oldPageArticle = new Article($oldPage, 0);
             $oldPageArticle->doDeleteArticle($this->msg('usermerge-autopagedelete')->text());
             $link = Linker::linkKnown($oldPage);
             $output .= Html::rawElement('li', array('class' => 'mw-renameuser-pe'), $this->msg('usermerge-page-deleted')->rawParams($link)->escaped());
         } else {
             # move content to new page
             # delete target page if it exists and is blank
             if ($newPage->exists()) {
                 $newPageArticle = new Article($newPage, 0);
                 $newPageArticle->doDeleteArticle($this->msg('usermerge-autopagedelete')->inContentLanguage()->text());
             }
             # move to target location
             $success = $oldPage->moveTo($newPage, false, $this->msg('usermerge-move-log', $oldusername->getText(), $newusername->getText())->inContentLanguage()->text());
             if ($success === true) {
                 $oldLink = Linker::linkKnown($oldPage, null, array(), array('redirect' => 'no'));
                 $newLink = Linker::linkKnown($newPage);
                 $output .= Html::rawElement('li', array('class' => 'mw-renameuser-pm'), $this->msg('usermerge-page-moved')->rawParams($oldLink, $newLink)->escaped());
             } else {
                 $oldLink = Linker::linkKnown($oldPage);
                 $newLink = Linker::linkKnown($newPage);
                 $output .= Html::rawElement('li', array('class' => 'mw-renameuser-pu'), $this->msg('usermerge-page-unmoved')->rawParams($oldLink, $newLink)->escaped());
             }
             # check if any pages link here
             $res = $dbr->selectField('pagelinks', 'pl_title', array('pl_title' => $olduser_text), __METHOD__);
             if (!$dbr->numRows($res)) {
                 # nothing links here, so delete unmoved page/redirect
                 $oldPageArticle = new Article($oldPage, 0);
                 $oldPageArticle->doDeleteArticle($this->msg('usermerge-autopagedelete')->inContentLanguage()->text());
             }
         }
     }
     if ($output) {
         $this->getOutput()->addHTML(Html::rawElement('ul', array(), $output));
     }
     return true;
 }
Example #19
0
 /**
  * Function to merge user pages
  *
  * Deletes all pages when merging to Anon
  * Moves user page when the target user page does not exist or is empty
  * Deletes redirect if nothing links to old page
  * Deletes the old user page when the target user page exists
  *
  * @param $newuser_text string Username to merge pages TO
  * @param $olduser_text string Username of user to remove pages FROM
  *
  * @return returns true on completion
  *
  * @author Matthew April <*****@*****.**>
  */
 private function movePages($newuser_text, $olduser_text)
 {
     global $wgOut, $wgContLang, $wgUser;
     $oldusername = trim(str_replace('_', ' ', $olduser_text));
     $oldusername = Title::makeTitle(NS_USER, $oldusername);
     $newusername = Title::makeTitleSafe(NS_USER, $wgContLang->ucfirst($newuser_text));
     # select all user pages and sub-pages
     $dbr = wfGetDB(DB_SLAVE);
     $oldkey = $oldusername->getDBkey();
     $pages = $dbr->select('page', array('page_namespace', 'page_title'), array('page_namespace IN (' . NS_USER . ',' . NS_USER_TALK . ')', 'page_title' . $dbr->buildLike($oldusername->getDBkey() . '/', $dbr->anyString()) . ' OR page_title = ' . $dbr->addQuotes($oldusername->getDBkey())));
     $output = '';
     $skin = $wgUser->getSkin();
     foreach ($pages as $row) {
         $oldPage = Title::makeTitleSafe($row->page_namespace, $row->page_title);
         $newPage = Title::makeTitleSafe($row->page_namespace, preg_replace('!^[^/]+!', $newusername->getDBkey(), $row->page_title));
         if ($newuser_text === "Anonymous") {
             # delete ALL old pages
             if ($oldPage->exists()) {
                 $oldPageArticle = new Article($oldPage, 0);
                 $oldPageArticle->doDeleteArticle(wfMsgHtml('usermerge-autopagedelete'));
                 $oldLink = $skin->linkKnown($oldPage);
                 $output .= '<li class="mw-renameuser-pe">' . wfMsgHtml('usermerge-page-deleted', $oldLink) . '</li>';
             }
         } elseif ($newPage->exists() && !$oldPage->isValidMoveTarget($newPage) && $newPage->getLength() > 0) {
             # delete old pages that can't be moved
             $oldPageArticle = new Article($oldPage, 0);
             $oldPageArticle->doDeleteArticle(wfMsgHtml('usermerge-autopagedelete'));
             $link = $skin->linkKnown($oldPage);
             $output .= '<li class="mw-renameuser-pe">' . wfMsgHtml('usermerge-page-deleted', $link) . '</li>';
         } else {
             # move content to new page
             # delete target page if it exists and is blank
             if ($newPage->exists()) {
                 $newPageArticle = new Article($newPage, 0);
                 $newPageArticle->doDeleteArticle('usermerge-autopagedelete');
             }
             # move to target location
             $success = $oldPage->moveTo($newPage, false, wfMsgForContent('usermerge-move-log', $oldusername->getText(), $newusername->getText()));
             if ($success === true) {
                 $oldLink = $skin->linkKnown($oldPage, null, array(), array('redirect' => 'no'));
                 $newLink = $skin->linkKnown($newPage);
                 $output .= '<li class="mw-renameuser-pm">' . wfMsgHtml('usermerge-page-moved', $oldLink, $newLink) . '</li>';
             } else {
                 $oldLink = $skin->linkKnown($oldPage);
                 $newLink = $skin->linkKnown($newPage);
                 $output .= '<li class="mw-renameuser-pu">' . wfMsgHtml('usermerge-page-unmoved', $oldLink, $newLink) . '</li>';
             }
             # check if any pages link here
             $res = $dbr->selectField('pagelinks', 'pl_title', array('pl_title' => $olduser_text), __METHOD__);
             if (!$dbr->numRows($res)) {
                 # nothing links here, so delete unmoved page/redirect
                 $oldPageArticle = new Article($oldPage, 0);
                 $oldPageArticle->doDeleteArticle(wfMsgHtml('usermerge-autopagedelete'));
             }
         }
     }
     if ($output) {
         $wgOut->addHTML('<ul>' . $output . '</ul>');
     }
     return true;
 }
Example #20
0
 public static function doDelete(&$title, &$file, &$oldimage, $reason, $suppress)
 {
     $article = null;
     if ($oldimage) {
         $status = $file->deleteOld($oldimage, $reason, $suppress);
         if ($status->ok) {
             // Need to do a log item
             $log = new LogPage('delete');
             $logComment = wfMsgForContent('deletedrevision', $oldimage);
             if (trim($reason) != '') {
                 $logComment .= ": {$reason}";
             }
             $log->addEntry('delete', $title, $logComment);
         }
     } else {
         $status = $file->delete($reason, $suppress);
         if ($status->ok) {
             $id = $title->getArticleID(GAID_FOR_UPDATE);
             // Need to delete the associated article
             $article = new Article($title);
             if (wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason))) {
                 if ($article->doDeleteArticle($reason, $suppress, $id)) {
                     global $wgRequest;
                     if ($wgRequest->getCheck('wpWatch')) {
                         $article->doWatch();
                     } elseif ($title->userIsWatching()) {
                         $article->doUnwatch();
                     }
                     wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $id));
                 }
             }
         }
     }
     if ($status->isGood()) {
         wfRunHooks('FileDeleteComplete', array(&$file, &$oldimage, &$article, &$wgUser, &$reason));
     }
     return $status;
 }
    if (is_null($page)) {
        print "Invalid title '{$line}' on line {$linenum}\n";
        continue;
    }
    if (!$page->exists()) {
        print "Skipping nonexistent page '{$line}'\n";
        continue;
    }
    print $page->getPrefixedText();
    $dbw->begin();
    if ($page->getNamespace() == NS_IMAGE) {
        $art = new ImagePage($page);
        $img = wfFindFile($art->mTitle);
        if (!$img || !$img->delete($reason)) {
            print "FAILED to delete image file... ";
        }
    } else {
        $art = new Article($page);
    }
    $success = $art->doDeleteArticle($reason);
    $dbw->immediateCommit();
    if ($success) {
        print "\n";
    } else {
        print " FAILED to delete image page\n";
    }
    if ($interval) {
        sleep($interval);
    }
    wfWaitForSlaves(5);
}
Example #22
0
 public function execute($par)
 {
     global $wgUser, $wgRequest, $wgOut;
     $username = $wgUser->getName();
     $allowed = array('Reuben', 'Bridget8');
     $userGroups = $wgUser->getGroups();
     if ($wgUser->isBlocked() || !in_array('sysop', $userGroups) && !in_array($username, $allowed)) {
         $wgOut->setRobotpolicy('noindex,nofollow');
         $wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext');
         return;
     }
     if (empty($par)) {
         $html = self::html();
         $wgOut->addHTML($html);
     } else {
         $terms = $wgRequest->getVal('terms');
         $article = $wgRequest->getVal('article');
         $error = '';
         $wgOut->setArticleBodyOnly(true);
         if ($par == 'search') {
             $html = self::searchHTML($terms);
             $wgOut->addHTML($html);
         } elseif ($par == 'rename') {
             if (!$article) {
                 $error = 'no article ID';
             }
             $response = array('error' => $error);
             $wgOut->addHTML(json_encode($response));
         } elseif ($par == 'delete') {
             $id = intval($article);
             $title = Title::newFromID($id);
             if (!$title) {
                 $error = 'no article ID';
             } else {
                 $article = new Article($title);
                 if (!$article) {
                     $error = 'no article';
                 } else {
                     $reason = 'Anomalous article title';
                     $article->doDeleteArticle($reason);
                 }
             }
             $response = array('error' => $error);
             $wgOut->clearHTML();
             $wgOut->addHTML(json_encode($response));
         }
     }
 }
 static function removeAd($name, $user)
 {
     $adObj = Ad::fromName($name);
     $id = $adObj->getId();
     $dbr = PRDatabase::getDb();
     $res = $dbr->select('pr_adlinks', 'adl_id', array('ad_id' => $id), __METHOD__);
     if ($dbr->numRows($res) > 0) {
         throw new MWException('Cannot remove an ad still bound to a campaign!');
     } else {
         // Log the removal of the ad
         // FIXME: this log line will display changes with inverted sense
         $adObj->logAdChange('removed', $user);
         // Delete ad record from the Promoter pr_ads table
         $dbw = PRDatabase::getDb();
         $dbw->begin();
         $dbw->delete('pr_ads', array('ad_id' => $id), __METHOD__);
         $dbw->commit();
         // Delete the MediaWiki page that contains the ad source
         $article = new Article(Title::newFromText("promoter-ad-{$name}", NS_MEDIAWIKI));
         $article->doDeleteArticle('Promoter automated removal');
     }
 }
 /**
  * Fulfil the request; shows the form or deletes the file,
  * pending authentication, confirmation, etc.
  */
 public function execute()
 {
     global $wgOut, $wgRequest, $wgUser;
     $this->setHeaders();
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     } elseif (!$wgUser->isLoggedIn()) {
         $wgOut->showErrorPage('uploadnologin', 'uploadnologintext');
         return;
     } elseif (!$wgUser->isAllowed('delete')) {
         $wgOut->permissionRequired('delete');
         return;
     } elseif ($wgUser->isBlocked()) {
         $wgOut->blockedPage();
         return;
     }
     $this->oldimage = $wgRequest->getText('oldimage', false);
     $token = $wgRequest->getText('wpEditToken');
     if ($this->oldimage && !$this->isValidOldSpec()) {
         $wgOut->showUnexpectedValueError('oldimage', htmlspecialchars($this->oldimage));
         return;
     }
     if ($this->oldimage) {
         $this->oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName($this->title, $this->oldimage);
     }
     if (!$this->haveDeletableFile()) {
         $wgOut->addHtml($this->prepareMessage('filedelete-nofile'));
         $wgOut->addReturnTo($this->title);
         return;
     }
     // Perform the deletion if appropriate
     if ($wgRequest->wasPosted() && $wgUser->matchEditToken($token, $this->oldimage)) {
         $this->DeleteReasonList = $wgRequest->getText('wpDeleteReasonList');
         $this->DeleteReason = $wgRequest->getText('wpReason');
         $reason = $this->DeleteReasonList;
         if ($reason != 'other' && $this->DeleteReason != '') {
             // Entry from drop down menu + additional comment
             $reason .= ': ' . $this->DeleteReason;
         } elseif ($reason == 'other') {
             $reason = $this->DeleteReason;
         }
         if ($this->oldimage) {
             $status = $this->file->deleteOld($this->oldimage, $reason);
             if ($status->ok) {
                 // Need to do a log item
                 $log = new LogPage('delete');
                 $logComment = wfMsgForContent('deletedrevision', $this->oldimage);
                 if (trim($reason) != '') {
                     $logComment .= ": {$reason}";
                 }
                 $log->addEntry('delete', $this->title, $logComment);
             }
         } else {
             $status = $this->file->delete($reason);
             if ($status->ok) {
                 // Need to delete the associated article
                 $article = new Article($this->title);
                 $article->doDeleteArticle($reason);
             }
         }
         if (!$status->isGood()) {
             $wgOut->addWikiText($status->getWikiText('filedeleteerror-short', 'filedeleteerror-long'));
         }
         if ($status->ok) {
             $wgOut->setPagetitle(wfMsg('actioncomplete'));
             $wgOut->addHtml($this->prepareMessage('filedelete-success'));
             // Return to the main page if we just deleted all versions of the
             // file, otherwise go back to the description page
             $wgOut->addReturnTo($this->oldimage ? $this->title : Title::newMainPage());
         }
         return;
     }
     $this->showForm();
     $this->showLogEntries();
 }
	/**
	 * Called via AJAX to delete an image out of the game.
	 */
	function adminPanelDelete() {
		global $wgRequest, $wgUser, $wgOut;

		$wgOut->setArticleBodyOnly( true );

		$id = $wgRequest->getInt( 'id' );
		$image1 = addslashes( $wgRequest->getVal( 'img1' ) );
		$image2 = addslashes( $wgRequest->getVal( 'img2' ) );

		$key = $wgRequest->getVal( 'key' );
		$now = $wgRequest->getVal( 'chain' );

		if(
			$key != md5( $now . $this->SALT ) ||
			( !$wgUser->isLoggedIn() || !$wgUser->isAllowed( 'picturegameadmin' ) )
		)
		{
			//echo wfMsg( 'picturegame-sysmsg-badkey' );
			//return;
		}

		$dbw = wfGetDB( DB_MASTER );
		$dbw->delete( 'picturegame_images', array( 'id' => $id ), __METHOD__ );
		$dbw->commit();

		global $wgMemc;
		$key = wfMemcKey( 'user', 'profile', 'picgame', $wgUser->getID() );
		$wgMemc->delete( $key );

		/* Pop the images out of MediaWiki also */
		//$img_one = wfFindFile( $image1 );
		$oneResult = $twoResult = false;
		if( $image1 ) {
			$img_one = Title::makeTitle( NS_FILE, $image1 );
			$article = new Article( $img_one );
			$oneResult = $article->doDeleteArticle( 'Picture Game image 1 Delete' );
		}

		if( $image2 ) {
			$img_two = Title::makeTitle( NS_FILE, $image2 );
			$article = new Article( $img_two );
			$twoResult = $article->doDeleteArticle( 'Picture Game image 2 Delete' );
		}

		if( $oneResult && $twoResult ) {
			echo wfMsg( 'picturegame-sysmsg-successfuldelete' );
			return;
		}

		if( $oneResult ) {
			echo wfMsg( 'picturegame-sysmsg-unsuccessfuldelete', $image1 );
		}
		if( $twoResult ) {
			echo wfMsg( 'picturegame-sysmsg-unsuccessfuldelete', $image2 );
		}
	}
 /**
  * We have our own delete() function, since Article.php's implementation is split in two phases
  *
  * @param Article $article - Article object to work on
  * @param string $token - Delete token (same as edit token)
  * @param string $reason - Reason for the deletion. Autogenerated if NULL
  * @return Title::getUserPermissionsErrors()-like array
  */
 public static function delete(&$article, $token, &$reason = null)
 {
     global $wgUser;
     if ($article->isBigDeletion() && !$wgUser->isAllowed('bigdelete')) {
         global $wgDeleteRevisionsLimit;
         return array(array('delete-toobig', $wgDeleteRevisionsLimit));
     }
     $title = $article->getTitle();
     $errors = self::getPermissionsError($title, $token);
     if (count($errors)) {
         return $errors;
     }
     // Auto-generate a summary, if necessary
     if (is_null($reason)) {
         // Need to pass a throwaway variable because generateReason expects
         // a reference
         $hasHistory = false;
         $reason = $article->generateReason($hasHistory);
         if ($reason === false) {
             return array(array('cannotdelete'));
         }
     }
     $error = '';
     if (!wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason, $error))) {
         $this->dieUsageMsg(array('hookaborted', $error));
     }
     // Luckily, Article.php provides a reusable delete function that does the hard work for us
     if ($article->doDeleteArticle($reason)) {
         wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $article->getId()));
         return array();
     }
     return array(array('cannotdelete', $article->mTitle->getPrefixedText()));
 }
Example #27
0
 function doDelete()
 {
     global $wgOut, $wgRequest, $wgUseSquid;
     global $wgPostCommitUpdateList;
     $fname = 'ImagePage::doDelete';
     $reason = $wgRequest->getVal('wpReason');
     $oldimage = $wgRequest->getVal('oldimage');
     $dbw =& wfGetDB(DB_MASTER);
     if (!is_null($oldimage)) {
         if (strlen($oldimage) < 16) {
             $wgOut->showUnexpectedValueError('oldimage', htmlspecialchars($oldimage));
             return;
         }
         if (strstr($oldimage, "/") || strstr($oldimage, "\\")) {
             $wgOut->showUnexpectedValueError('oldimage', htmlspecialchars($oldimage));
             return;
         }
         if (!$this->doDeleteOldImage($oldimage)) {
             return;
         }
         $deleted = $oldimage;
     } else {
         $ok = $this->img->delete($reason);
         if (!$ok) {
             # If the deletion operation actually failed, bug out:
             $wgOut->showFileDeleteError($this->img->getName());
             return;
         }
         # Image itself is now gone, and database is cleaned.
         # Now we remove the image description page.
         $article = new Article($this->mTitle);
         // WERELATE: added calls to ArticleDelete and ArticleDeleteComplete hooks
         global $wgUser;
         if (wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason))) {
             if ($article->doDeleteArticle($reason)) {
                 wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason));
             }
         }
         $deleted = $this->img->getName();
     }
     $wgOut->setPagetitle(wfMsg('actioncomplete'));
     $wgOut->setRobotpolicy('noindex,nofollow');
     $loglink = '[[Special:Log/delete|' . wfMsg('deletionlog') . ']]';
     $text = wfMsg('deletedtext', $deleted, $loglink);
     $wgOut->addWikiText($text);
     $wgOut->returnToMain(false, $this->mTitle->getPrefixedText());
 }
function do_rm_congress_persons()
{
    $dbr = wfGetDB(DB_SLAVE);
    $result = $dbr->query(" SELECT *\n\tFROM `categorylinks`\n\tWHERE `cl_to` LIKE 'Congress_Person' ");
    while ($row = $dbr->fetchObject($result)) {
        $pTitle = Title::makeTitle(NS_MAIN, $row->cl_sortkey);
        $pArticle = new Article($pTitle);
        $pArticle->doDeleteArticle('removed reason');
        print "removed title: " . $pTitle->getText() . "\n";
    }
}
Example #29
0
 /**
  * Does the actual deletion of the pages.
  *
  * @param array $pages The pages to delete
  * @param string $reason
  */
 protected function doDelete(array $pages, $reason)
 {
     $res = array();
     foreach ($pages as $page) {
         $title = Title::newFromURL($page);
         $file = $title->getNamespace() == NS_FILE ? wfLocalFile($title) : false;
         $permission_errors = $title->getUserPermissionsErrors('delete', $this->getUser());
         if (count($permission_errors)) {
             throw new PermissionsError('delete', $permission_errors);
         }
         if ($file) {
             $oldimage = null;
             // Must be passed by reference
             $ok = FileDeleteForm::doDelete($title, $file, $oldimage, $reason, false)->isOK();
         } else {
             $article = new Article($title, 0);
             $ok = $article->doDeleteArticle($reason);
         }
         if ($ok) {
             $res[] = wfMsgExt('nuke-deleted', array('parseinline'), $title->getPrefixedText());
         } else {
             $res[] = wfMsgExt('nuke-not-deleted', array('parseinline'), $title->getPrefixedText());
         }
     }
     $this->getOutput()->addHTML("<ul>\n<li>" . implode("</li>\n<li>", $res) . "</li>\n</ul>\n");
     $this->getOutput()->addWikiMsg('nuke-delete-more');
 }
Example #30
0
 /**
  * Really delete the file
  *
  * @param $title Title object
  * @param $file File object
  * @param $oldimage String: archive name
  * @param $reason String: reason of the deletion
  * @param $suppress Boolean: whether to mark all deleted versions as restricted
  */
 public static function doDelete(&$title, &$file, &$oldimage, $reason, $suppress)
 {
     global $wgUser;
     $article = null;
     $status = Status::newFatal('error');
     if ($oldimage) {
         $status = $file->deleteOld($oldimage, $reason, $suppress);
         if ($status->ok) {
             // Need to do a log item
             $log = new LogPage('delete');
             $logComment = wfMsgForContent('deletedrevision', $oldimage);
             if (trim($reason) != '') {
                 $logComment .= wfMsgForContent('colon-separator') . $reason;
             }
             $log->addEntry('delete', $title, $logComment);
         }
     } else {
         $id = $title->getArticleID(Title::GAID_FOR_UPDATE);
         $article = new Article($title);
         $dbw = wfGetDB(DB_MASTER);
         try {
             // delete the associated article first
             if ($article->doDeleteArticle($reason, $suppress, $id, false)) {
                 global $wgRequest;
                 if ($wgRequest->getCheck('wpWatch') && $wgUser->isLoggedIn()) {
                     WatchAction::doWatch($title, $wgUser);
                 } elseif ($title->userIsWatching()) {
                     WatchAction::doUnwatch($title, $wgUser);
                 }
                 $status = $file->delete($reason, $suppress);
                 if ($status->ok) {
                     $dbw->commit();
                 } else {
                     $dbw->rollback();
                 }
             }
         } catch (MWException $e) {
             // rollback before returning to prevent UI from displaying incorrect "View or restore N deleted edits?"
             $dbw->rollback();
             throw $e;
         }
     }
     if ($status->isGood()) {
         wfRunHooks('FileDeleteComplete', array(&$file, &$oldimage, &$article, &$wgUser, &$reason));
     }
     return $status;
 }