]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - maintenance/nukePage.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / maintenance / nukePage.php
index 4a073a5e856ecfcb598c1a7ac9a828bd90848bd7..e27324a7588bc822904364238584d01bfa4c91bd 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
+ * @file
  * @ingroup Maintenance
  * @author Rob Church <robchur@gmail.com>
  */
 
-require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+require_once __DIR__ . '/Maintenance.php';
 
+/**
+ * Maintenance script that erases a page record from the database.
+ *
+ * @ingroup Maintenance
+ */
 class NukePage extends Maintenance {
        public function __construct() {
                parent::__construct();
-               $this->mDescription = "Remove a page record from the database";
+               $this->addDescription( 'Remove a page record from the database' );
                $this->addOption( 'delete', "Actually delete the page" );
                $this->addArg( 'title', 'Title to delete' );
        }
 
        public function execute() {
-
                $name = $this->getArg();
-               $delete = $this->getOption( 'delete', false );
+               $delete = $this->hasOption( 'delete' );
 
-               $dbw = wfGetDB( DB_MASTER );
-               $dbw->begin();
+               $dbw = $this->getDB( DB_MASTER );
+               $this->beginTransaction( $dbw, __METHOD__ );
 
                $tbl_pag = $dbw->tableName( 'page' );
                $tbl_rec = $dbw->tableName( 'recentchanges' );
@@ -48,7 +53,7 @@ class NukePage extends Maintenance {
                $this->output( "Searching for \"$name\"..." );
                $title = Title::newFromText( $name );
                if ( $title ) {
-                       $id   = $title->getArticleID();
+                       $id = $title->getArticleID();
                        $real = $title->getPrefixedText();
                        $isGoodArticle = $title->isContentPage();
                        $this->output( "found \"$real\" with ID $id.\n" );
@@ -56,6 +61,7 @@ class NukePage extends Maintenance {
                        # Get corresponding revisions
                        $this->output( "Searching for revisions..." );
                        $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
+                       $revs = [];
                        foreach ( $res as $row ) {
                                $revs[] = $row->rev_id;
                        }
@@ -72,7 +78,7 @@ class NukePage extends Maintenance {
                                $this->output( "done.\n" );
                        }
 
-                       $dbw->commit();
+                       $this->commitTransaction( $dbw, __METHOD__ );
 
                        # Delete revisions as appropriate
                        if ( $delete && $count ) {
@@ -92,22 +98,22 @@ class NukePage extends Maintenance {
                        }
                } else {
                        $this->output( "not found in database.\n" );
-                       $dbw->commit();
+                       $this->commitTransaction( $dbw, __METHOD__ );
                }
        }
 
        public function deleteRevisions( $ids ) {
-               $dbw = wfGetDB( DB_MASTER );
-               $dbw->begin();
+               $dbw = $this->getDB( DB_MASTER );
+               $this->beginTransaction( $dbw, __METHOD__ );
 
                $tbl_rev = $dbw->tableName( 'revision' );
 
                $set = implode( ', ', $ids );
                $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" );
 
-               $dbw->commit();
+               $this->commitTransaction( $dbw, __METHOD__ );
        }
 }
 
 $maintClass = "NukePage";
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;