RevDel: Avoid log_search rows with empty values for target_author_actor
[lhc/web/wiklou.git] / maintenance / Maintenance.php
index e76426d..ad748f3 100644 (file)
@@ -1251,7 +1251,7 @@ abstract class Maintenance {
                        $settingsFile = "$IP/LocalSettings.php";
                }
                if ( isset( $this->mOptions['wiki'] ) ) {
-                       $bits = explode( '-', $this->mOptions['wiki'] );
+                       $bits = explode( '-', $this->mOptions['wiki'], 2 );
                        if ( count( $bits ) == 1 ) {
                                $bits[] = '';
                        }
@@ -1281,27 +1281,45 @@ abstract class Maintenance {
         * @author Rob Church <robchur@gmail.com>
         */
        public function purgeRedundantText( $delete = true ) {
+               global $wgMultiContentRevisionSchemaMigrationStage;
+
                # Data should come off the master, wrapped in a transaction
                $dbw = $this->getDB( DB_MASTER );
                $this->beginTransaction( $dbw, __METHOD__ );
 
-               # Get "active" text records from the revisions table
-               $cur = [];
-               $this->output( 'Searching for active text records in revisions table...' );
-               $res = $dbw->select( 'revision', 'rev_text_id', [], __METHOD__, [ 'DISTINCT' ] );
-               foreach ( $res as $row ) {
-                       $cur[] = $row->rev_text_id;
-               }
-               $this->output( "done.\n" );
+               if ( $wgMultiContentRevisionSchemaMigrationStage & SCHEMA_COMPAT_READ_OLD ) {
+                       # Get "active" text records from the revisions table
+                       $cur = [];
+                       $this->output( 'Searching for active text records in revisions table...' );
+                       $res = $dbw->select( 'revision', 'rev_text_id', [], __METHOD__, [ 'DISTINCT' ] );
+                       foreach ( $res as $row ) {
+                               $cur[] = $row->rev_text_id;
+                       }
+                       $this->output( "done.\n" );
 
-               # Get "active" text records from the archive table
-               $this->output( 'Searching for active text records in archive table...' );
-               $res = $dbw->select( 'archive', 'ar_text_id', [], __METHOD__, [ 'DISTINCT' ] );
-               foreach ( $res as $row ) {
-                       # old pre-MW 1.5 records can have null ar_text_id's.
-                       if ( $row->ar_text_id !== null ) {
-                               $cur[] = $row->ar_text_id;
+                       # Get "active" text records from the archive table
+                       $this->output( 'Searching for active text records in archive table...' );
+                       $res = $dbw->select( 'archive', 'ar_text_id', [], __METHOD__, [ 'DISTINCT' ] );
+                       foreach ( $res as $row ) {
+                               # old pre-MW 1.5 records can have null ar_text_id's.
+                               if ( $row->ar_text_id !== null ) {
+                                       $cur[] = $row->ar_text_id;
+                               }
                        }
+                       $this->output( "done.\n" );
+               } else {
+                       # Get "active" text records via the content table
+                       $cur = [];
+                       $this->output( 'Searching for active text records via contents table...' );
+                       $res = $dbw->select( 'content', 'content_address', [], __METHOD__, [ 'DISTINCT' ] );
+                       $blobStore = MediaWikiServices::getInstance()->getBlobStore();
+                       foreach ( $res as $row ) {
+                               $textId = $blobStore->getTextIdFromAddress( $row->content_address );
+                               if ( $textId ) {
+                                       $cur[] = $textId;
+                               }
+                       }
+                       $this->output( "done.\n" );
                }
                $this->output( "done.\n" );
 
@@ -1326,7 +1344,6 @@ abstract class Maintenance {
                        $this->output( "done.\n" );
                }
 
-               # Done
                $this->commitTransaction( $dbw, __METHOD__ );
        }
 
@@ -1349,11 +1366,10 @@ abstract class Maintenance {
         * @return IMaintainableDatabase
         */
        protected function getDB( $db, $groups = [], $wiki = false ) {
-               if ( is_null( $this->mDb ) ) {
+               if ( $this->mDb === null ) {
                        return wfGetDB( $db, $groups, $wiki );
-               } else {
-                       return $this->mDb;
                }
+               return $this->mDb;
        }
 
        /**