Handle missing titles and usernames when importing log items
authorgeorggi <bmp2558@gmail.com>
Sat, 19 Dec 2015 09:06:26 +0000 (11:06 +0200)
committerTTO <at.light@live.com.au>
Sat, 19 Dec 2015 09:50:22 +0000 (09:50 +0000)
Bug: T121338
Change-Id: Idf95263e4f22225509da4ee07fcb14383028894b

includes/Import.php
maintenance/importDump.php

index 519f74a..ee1cab5 100644 (file)
@@ -660,14 +660,26 @@ class WikiImporter {
         * @return bool|mixed
         */
        private function processLogItem( $logInfo ) {
         * @return bool|mixed
         */
        private function processLogItem( $logInfo ) {
+
                $revision = new WikiRevision( $this->config );
 
                $revision = new WikiRevision( $this->config );
 
-               $revision->setID( $logInfo['id'] );
+               if ( isset( $logInfo['id'] ) ) {
+                       $revision->setID( $logInfo['id'] );
+               }
                $revision->setType( $logInfo['type'] );
                $revision->setAction( $logInfo['action'] );
                $revision->setType( $logInfo['type'] );
                $revision->setAction( $logInfo['action'] );
-               $revision->setTimestamp( $logInfo['timestamp'] );
-               $revision->setParams( $logInfo['params'] );
-               $revision->setTitle( Title::newFromText( $logInfo['logtitle'] ) );
+               if ( isset( $logInfo['timestamp'] ) ) {
+                       $revision->setTimestamp( $logInfo['timestamp'] );
+               }
+               if ( isset( $logInfo['params'] ) ) {
+                       $revision->setParams( $logInfo['params'] );
+               }
+               if ( isset( $logInfo['logtitle'] ) ) {
+                       // @todo Using Title for non-local titles is a recipe for disaster.
+                       // We should use ForeignTitle here instead.
+                       $revision->setTitle( Title::newFromText( $logInfo['logtitle'] ) );
+               }
+
                $revision->setNoUpdates( $this->mNoUpdates );
 
                if ( isset( $logInfo['comment'] ) ) {
                $revision->setNoUpdates( $this->mNoUpdates );
 
                if ( isset( $logInfo['comment'] ) ) {
@@ -677,7 +689,10 @@ class WikiImporter {
                if ( isset( $logInfo['contributor']['ip'] ) ) {
                        $revision->setUserIP( $logInfo['contributor']['ip'] );
                }
                if ( isset( $logInfo['contributor']['ip'] ) ) {
                        $revision->setUserIP( $logInfo['contributor']['ip'] );
                }
-               if ( isset( $logInfo['contributor']['username'] ) ) {
+
+               if ( !isset( $logInfo['contributor']['username'] ) ) {
+                       $revision->setUsername( 'Unknown user' );
+               } else {
                        $revision->setUserName( $logInfo['contributor']['username'] );
                }
 
                        $revision->setUserName( $logInfo['contributor']['username'] );
                }
 
@@ -1655,6 +1670,16 @@ class WikiRevision {
 
        function importLogItem() {
                $dbw = wfGetDB( DB_MASTER );
 
        function importLogItem() {
                $dbw = wfGetDB( DB_MASTER );
+
+               $user = User::newFromName( $this->getUser() );
+               if ( $user ) {
+                       $userId = intval( $user->getId() );
+                       $userText = $user->getName();
+               } else {
+                       $userId = 0;
+                       $userText = $this->getUser();
+               }
+
                # @todo FIXME: This will not record autoblocks
                if ( !$this->getTitle() ) {
                        wfDebug( __METHOD__ . ": skipping invalid {$this->type}/{$this->action} log time, timestamp " .
                # @todo FIXME: This will not record autoblocks
                if ( !$this->getTitle() ) {
                        wfDebug( __METHOD__ . ": skipping invalid {$this->type}/{$this->action} log time, timestamp " .
@@ -1687,8 +1712,8 @@ class WikiRevision {
                        'log_type' => $this->type,
                        'log_action' => $this->action,
                        'log_timestamp' => $dbw->timestamp( $this->timestamp ),
                        'log_type' => $this->type,
                        'log_action' => $this->action,
                        'log_timestamp' => $dbw->timestamp( $this->timestamp ),
-                       'log_user' => User::idFromName( $this->user_text ),
-                       # 'log_user_text' => $this->user_text,
+                       'log_user' =>  $userId,
+                       'log_user_text' => $userText,
                        'log_namespace' => $this->getTitle()->getNamespace(),
                        'log_title' => $this->getTitle()->getDBkey(),
                        'log_comment' => $this->getComment(),
                        'log_namespace' => $this->getTitle()->getNamespace(),
                        'log_title' => $this->getTitle()->getDBkey(),
                        'log_comment' => $this->getComment(),
index 8cea5a2..6b7cfb6 100644 (file)
@@ -135,16 +135,24 @@ TEXT;
         * @return bool
         */
        private function skippedNamespace( $obj ) {
         * @return bool
         */
        private function skippedNamespace( $obj ) {
+               $title = null;
                if ( $obj instanceof Title ) {
                if ( $obj instanceof Title ) {
-                       $ns = $obj->getNamespace();
+                       $title = $obj;
                } elseif ( $obj instanceof Revision ) {
                } elseif ( $obj instanceof Revision ) {
-                       $ns = $obj->getTitle()->getNamespace();
+                       $title = $obj->getTitle();
                } elseif ( $obj instanceof WikiRevision ) {
                } elseif ( $obj instanceof WikiRevision ) {
-                       $ns = $obj->title->getNamespace();
+                       $title = $obj->title;
                } else {
                        throw new MWException( "Cannot get namespace of object in " . __METHOD__ );
                }
 
                } else {
                        throw new MWException( "Cannot get namespace of object in " . __METHOD__ );
                }
 
+               if ( is_null( $title ) ) {
+                       // Probably a log entry
+                       return false;
+               }
+
+               $ns = $title->getNamespace();
+
                return is_array( $this->nsFilter ) && !in_array( $ns, $this->nsFilter );
        }
 
                return is_array( $this->nsFilter ) && !in_array( $ns, $this->nsFilter );
        }