function NukeNS($ns_no, $delete) { $dbw = wfGetDB(DB_MASTER); $dbw->begin(); $tbl_pag = $dbw->tableName('page'); $tbl_rev = $dbw->tableName('revision'); $res = $dbw->query("SELECT page_title FROM {$tbl_pag} WHERE page_namespace = {$ns_no}"); $n_deleted = 0; while ($row = $dbw->fetchObject($res)) { //echo "$ns_name:".$row->page_title, "\n"; $title = Title::newFromText($row->page_title, $ns_no); $id = $title->getArticleID(); // Get corresponding revisions $res2 = $dbw->query("SELECT rev_id FROM {$tbl_rev} WHERE rev_page = {$id}"); $revs = array(); while ($row2 = $dbw->fetchObject($res2)) { $revs[] = $row2->rev_id; } $count = count($revs); //skip anything that looks modified (i.e. multiple revs) if ($count == 1) { #echo $title->getPrefixedText(), "\t", $count, "\n"; echo "delete: ", $title->getPrefixedText(), "\n"; //as much as I hate to cut & paste this, it's a little different, and //I already have the id & revs if ($delete) { $dbw->query("DELETE FROM {$tbl_pag} WHERE page_id = {$id}"); $dbw->commit(); // Delete revisions as appropriate DeleteRevisions($revs); PurgeRedundantText(true); $n_deleted++; } } else { echo "skip: ", $title->getPrefixedText(), "\n"; } } $dbw->commit(); if ($n_deleted > 0) { #update statistics - better to decrement existing count, or just count #the page table? $pages = $dbw->selectField('site_stats', 'ss_total_pages'); $pages -= $n_deleted; $dbw->update('site_stats', array('ss_total_pages' => $pages), array('ss_row_id' => 1), __METHOD__); } if (!$delete) { echo "To update the database, run the script with the --delete option.\n"; } }
<?php /** * Purge old text records from the database * * @package MediaWiki * @subpackage Maintenance * @author Rob Church <*****@*****.**> */ $options = array('purge', 'help'); require_once 'commandLine.inc'; require_once 'purgeOldText.inc'; echo "Purge Old Text\n\n"; if (@$options['help']) { ShowUsage(); } else { PurgeRedundantText(@$options['purge']); } function ShowUsage() { echo "Prunes unused text records from the database.\n\n"; echo "Usage: php purgeOldText.php [--purge]\n\n"; echo "purge : Performs the deletion\n"; echo " help : Show this usage information\n"; }
showUsage(); } $report = isset($options['report']); $dbw =& wfGetDB(DB_MASTER); $dbw->immediateBegin(); extract($dbw->tableNames('page', 'revision')); # Find all the orphaned revisions echo "Checking for orphaned revisions..."; $sql = "SELECT rev_id FROM {$revision} LEFT JOIN {$page} ON rev_page = page_id WHERE page_namespace IS NULL"; $res = $dbw->query($sql, 'deleteOrphanedRevisions'); # Stash 'em all up for deletion (if needed) while ($row = $dbw->fetchObject($res)) { $revisions[] = $row->rev_id; } $dbw->freeResult($res); $count = count($revisions); echo "found {$count}.\n"; # Nothing to do? if ($report || $count == 0) { $dbw->immediateCommit(); exit; } # Delete each revision echo "Deleting..."; deleteRevisions($revisions, $dbw); echo "done.\n"; # Close the transaction and call the script to purge unused text records $dbw->immediateCommit(); require_once 'purgeOldText.inc'; PurgeRedundantText(true);