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