MediaWiki
REL1_22
|
00001 <?php 00026 require_once __DIR__ . '/Maintenance.php'; 00027 00033 class NukePage extends Maintenance { 00034 public function __construct() { 00035 parent::__construct(); 00036 $this->mDescription = "Remove a page record from the database"; 00037 $this->addOption( 'delete', "Actually delete the page" ); 00038 $this->addArg( 'title', 'Title to delete' ); 00039 } 00040 00041 public function execute() { 00042 00043 $name = $this->getArg(); 00044 $delete = $this->getOption( 'delete', false ); 00045 00046 $dbw = wfGetDB( DB_MASTER ); 00047 $dbw->begin( __METHOD__ ); 00048 00049 $tbl_pag = $dbw->tableName( 'page' ); 00050 $tbl_rec = $dbw->tableName( 'recentchanges' ); 00051 $tbl_rev = $dbw->tableName( 'revision' ); 00052 00053 # Get page ID 00054 $this->output( "Searching for \"$name\"..." ); 00055 $title = Title::newFromText( $name ); 00056 if ( $title ) { 00057 $id = $title->getArticleID(); 00058 $real = $title->getPrefixedText(); 00059 $isGoodArticle = $title->isContentPage(); 00060 $this->output( "found \"$real\" with ID $id.\n" ); 00061 00062 # Get corresponding revisions 00063 $this->output( "Searching for revisions..." ); 00064 $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" ); 00065 $revs = array(); 00066 foreach ( $res as $row ) { 00067 $revs[] = $row->rev_id; 00068 } 00069 $count = count( $revs ); 00070 $this->output( "found $count.\n" ); 00071 00072 # Delete the page record and associated recent changes entries 00073 if ( $delete ) { 00074 $this->output( "Deleting page record..." ); 00075 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" ); 00076 $this->output( "done.\n" ); 00077 $this->output( "Cleaning up recent changes..." ); 00078 $dbw->query( "DELETE FROM $tbl_rec WHERE rc_cur_id = $id" ); 00079 $this->output( "done.\n" ); 00080 } 00081 00082 $dbw->commit( __METHOD__ ); 00083 00084 # Delete revisions as appropriate 00085 if ( $delete && $count ) { 00086 $this->output( "Deleting revisions..." ); 00087 $this->deleteRevisions( $revs ); 00088 $this->output( "done.\n" ); 00089 $this->purgeRedundantText( true ); 00090 } 00091 00092 # Update stats as appropriate 00093 if ( $delete ) { 00094 $this->output( "Updating site stats..." ); 00095 $ga = $isGoodArticle ? -1 : 0; // if it was good, decrement that too 00096 $stats = new SiteStatsUpdate( 0, -$count, $ga, -1 ); 00097 $stats->doUpdate(); 00098 $this->output( "done.\n" ); 00099 } 00100 } else { 00101 $this->output( "not found in database.\n" ); 00102 $dbw->commit( __METHOD__ ); 00103 } 00104 } 00105 00106 public function deleteRevisions( $ids ) { 00107 $dbw = wfGetDB( DB_MASTER ); 00108 $dbw->begin( __METHOD__ ); 00109 00110 $tbl_rev = $dbw->tableName( 'revision' ); 00111 00112 $set = implode( ', ', $ids ); 00113 $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" ); 00114 00115 $dbw->commit( __METHOD__ ); 00116 } 00117 } 00118 00119 $maintClass = "NukePage"; 00120 require_once RUN_MAINTENANCE_IF_MAIN;