Siebrand has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/243119

Change subject: Add tests
......................................................................

Add tests

Fix all issues so tests pass.

Change-Id: I4545276d84fc0d0405d7c16ab179332298eb682b
---
M .gitignore
M Gruntfile.js
M RenameUserJob.php
M Renameuser.hooks.php
M Renameuser.php
M RenameuserLogFormatter.php
M RenameuserSQL.php
M cleanupArchiveUserText.php
A composer.json
M i18n/en.json
A phpcs.xml
M renameUserCleanup.php
M specials/SpecialRenameuser.php
13 files changed, 318 insertions(+), 242 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Renameuser 
refs/changes/19/243119/1

diff --git a/.gitignore b/.gitignore
index 4bf4869..854a2d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
-.svn
 *~
 *.kate-swp
 .*.swp
 node_modules/
+/composer.lock
+/vendor/
diff --git a/Gruntfile.js b/Gruntfile.js
index 5a87e7b..9c56558 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -3,9 +3,10 @@
        grunt.loadNpmTasks( 'grunt-banana-checker' );
        grunt.loadNpmTasks( 'grunt-jsonlint' );
 
-       var conf = grunt.file.readJSON( 'extension.json' );
        grunt.initConfig( {
-               banana: conf.MessagesDirs,
+               banana: {
+                       all: 'i18n/'
+               },
                jsonlint: {
                        all: [
                                '**/*.json',
diff --git a/RenameUserJob.php b/RenameUserJob.php
index d2dc14c..086678d 100644
--- a/RenameUserJob.php
+++ b/RenameUserJob.php
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Custom job to perform updates on tables in busier environments
  */
@@ -27,7 +28,9 @@
                $oldname = $this->params['oldname'];
                $userID = isset( $this->params['userID'] ) ? 
$this->params['userID'] : null;
                $uidColumn = isset( $this->params['uidColumn'] ) ? 
$this->params['uidColumn'] : null;
-               $timestampColumn = isset( $this->params['timestampColumn'] ) ? 
$this->params['timestampColumn'] : null;
+               $timestampColumn = isset( $this->params['timestampColumn'] ) ?
+                       $this->params['timestampColumn'] :
+                       null;
                $minTimestamp = $this->params['minTimestamp'];
                $maxTimestamp = $this->params['maxTimestamp'];
                $uniqueKey = isset( $this->params['uniqueKey'] ) ? 
$this->params['uniqueKey'] : null;
@@ -45,7 +48,7 @@
                if ( isset( $timestampColumn ) ) {
                        $conds[] = "$timestampColumn >= '$minTimestamp'";
                        $conds[] = "$timestampColumn <= '$maxTimestamp'";
-               # Otherwise, bound by key (B/C)
+                       # Otherwise, bound by key (B/C)
                } elseif ( isset( $uniqueKey ) ) {
                        $conds[$uniqueKey] = $keyId;
                } else {
@@ -94,6 +97,7 @@
                                );
                        }
                }
+
                return true;
        }
 }
diff --git a/Renameuser.hooks.php b/Renameuser.hooks.php
index 846f913..a9dfb01 100644
--- a/Renameuser.hooks.php
+++ b/Renameuser.hooks.php
@@ -11,9 +11,12 @@
        public static function onShowMissingArticle( $article ) {
                $title = $article->getTitle();
                $oldUser = User::newFromName( $title->getBaseText() );
-               if ( ($title->getNamespace() == NS_USER || 
$title->getNamespace() == NS_USER_TALK ) && ($oldUser && $oldUser->isAnon() )) {
+               if ( ( $title->getNamespace() == NS_USER || 
$title->getNamespace() == NS_USER_TALK ) &&
+                       ( $oldUser && $oldUser->isAnon() )
+               ) {
                        // Get the title for the base userpage
-                       $page = Title::makeTitle( NS_USER, str_replace( ' ', 
'_', $title->getBaseText() ) )->getPrefixedDBkey();
+                       $page = Title::makeTitle( NS_USER, str_replace( ' ', 
'_', $title->getBaseText() ) )
+                               ->getPrefixedDBkey();
                        $out = $article->getContext()->getOutput();
                        LogEventsList::showLogExtract(
                                $out,
@@ -51,6 +54,7 @@
                                array( 'oldusername' => $nt->getText() )
                        );
                }
+
                return true;
        }
 
@@ -61,6 +65,7 @@
         */
        public static function onGetLogTypesOnUser( array &$types ) {
                $types[] = 'renameuser';
+
                return true;
        }
 }
diff --git a/Renameuser.php b/Renameuser.php
index 441b571..738ca0d 100755
--- a/Renameuser.php
+++ b/Renameuser.php
@@ -5,10 +5,12 @@
        // Keep i18n globals so mergeMessageFileList.php doesn't break
        $wgMessagesDirs['Renameuser'] = __DIR__ . '/i18n';
        $wgExtensionMessagesFiles['RenameuserAliases'] = __DIR__ . 
'/Renameuser.alias.php';
+
        /* wfWarn(
                'Deprecated PHP entry point used for Renameuser extension. 
Please use wfLoadExtension instead, ' .
                'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
        ); */
+
        return true;
 } else {
        die( 'This version of the Renameuser extension requires MediaWiki 
1.25+' );
diff --git a/RenameuserLogFormatter.php b/RenameuserLogFormatter.php
index 3707884..2728902 100644
--- a/RenameuserLogFormatter.php
+++ b/RenameuserLogFormatter.php
@@ -1,8 +1,8 @@
 <?php
+
 /**
  * LogFormatter for renameuser/renameuser logs
  */
-
 class RenameuserLogFormatter extends LogFormatter {
 
        protected function getMessageParameters() {
@@ -52,6 +52,7 @@
                                $link = '[[' . $title->getPrefixedText() . ']]';
                        }
                }
+
                return $link;
        }
 
diff --git a/RenameuserSQL.php b/RenameuserSQL.php
index 0f94b47..386c873 100755
--- a/RenameuserSQL.php
+++ b/RenameuserSQL.php
@@ -1,48 +1,48 @@
 <?php
+
 /**
  * Class which performs the actual renaming of users
  */
-
 class RenameuserSQL {
        /**
-         * The old username
-         *
-         * @var string
-         * @access private
-         */
+        * The old username
+        *
+        * @var string
+        * @access private
+        */
        public $old;
 
        /**
-         * The new username
-         *
-         * @var string
-         * @access private
-         */
+        * The new username
+        *
+        * @var string
+        * @access private
+        */
        public $new;
 
        /**
-         * The user ID
-         *
-         * @var integer
-         * @access private
-         */
+        * The user ID
+        *
+        * @var integer
+        * @access private
+        */
        public $uid;
 
        /**
-         * The the tables => fields to be updated
-         *
-         * @var array
-         * @access private
-         */
+        * The the tables => fields to be updated
+        *
+        * @var array
+        * @access private
+        */
        public $tables;
 
        /**
-         * Flag that can be set to false, in case another process has already 
started
-         * the updates and the old username may have already been renamed in 
the user table.
-         *
-         * @var bool
-         * @access private
-         */
+        * Flag that can be set to false, in case another process has already 
started
+        * the updates and the old username may have already been renamed in 
the user table.
+        *
+        * @var bool
+        * @access private
+        */
        public $checkIfUserExists;
 
        /**
@@ -80,7 +80,7 @@
         * @param $uid
         * @param User $renamer
         * @param $options Array of options
-        *      'checkIfUserExists' - bool, whether to update the user table
+        *    'checkIfUserExists' - bool, whether to update the user table
         */
        function __construct( $old, $new, $uid, User $renamer, $options = 
array() ) {
                $this->old = $old;
@@ -104,7 +104,7 @@
                $this->tables = array(); // Immediate updates
                $this->tables['image'] = array( 'img_user_text', 'img_user' );
                $this->tables['oldimage'] = array( 'oi_user_text', 'oi_user' );
-               $this->tables['filearchive'] = array('fa_user_text','fa_user');
+               $this->tables['filearchive'] = array( 'fa_user_text', 'fa_user' 
);
                $this->tablesJob = array(); // Slow updates
                // If this user has a large number of edits, use the jobqueue
                if ( User::newFromId( $uid )->getEditCount() > 
self::CONTRIB_JOB ) {
@@ -159,6 +159,7 @@
                if ( !$dbw->affectedRows() && $this->checkIfUserExists ) {
                        $dbw->rollback();
                        $this->debug( "User {$this->old} does not exist, 
bailing out" );
+
                        return false;
                }
 
@@ -303,7 +304,6 @@
                ) );
                $logid = $logEntry->insert();
                $logEntry->publish( $logid );
-
 
                $this->debug( "Finished rename for {$this->old} to 
{$this->new}" );
 
diff --git a/cleanupArchiveUserText.php b/cleanupArchiveUserText.php
index 8599f3c..c24c152 100644
--- a/cleanupArchiveUserText.php
+++ b/cleanupArchiveUserText.php
@@ -5,7 +5,7 @@
        $IP = __DIR__ . '/../..';
 }
 
-require_once( "$IP/maintenance/Maintenance.php" );
+require_once "$IP/maintenance/Maintenance.php";
 
 /**
  * @ingroup Maintenance
@@ -13,7 +13,8 @@
 class CleanupArchiveUserText extends Maintenance {
        public function __construct() {
                parent::__construct();
-               $this->mDescription = "Update the archive table where users 
were previously renamed, but their archive contributions were not";
+               $this->mDescription = 'Update the archive table where users 
were ' .
+                       'previously renamed, but their archive contributions 
were not';
        }
 
        public function execute() {
@@ -30,7 +31,7 @@
                                array( 'LIMIT' => 50 )
                        );
                        $results = 0;
-                       foreach( $res as $row ) {
+                       foreach ( $res as $row ) {
                                $results++;
                                $this->output( "User:{$row->ar_user_text} => 
User:{$row->user_name} " );
                                $dbw->update(
@@ -55,5 +56,5 @@
        }
 }
 
-$maintClass = "CleanupArchiveUserText";
-require_once( RUN_MAINTENANCE_IF_MAIN );
+$maintClass = 'CleanupArchiveUserText';
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..4365e8a
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,12 @@
+{
+       "require-dev": {
+               "jakub-onderka/php-parallel-lint": "0.9",
+               "mediawiki/mediawiki-codesniffer": "0.4.0"
+       },
+       "scripts": {
+               "test": [
+                       "parallel-lint . --exclude vendor",
+                       "phpcs -p -s"
+               ]
+       }
+}
diff --git a/i18n/en.json b/i18n/en.json
index 40c7a11..fb33073 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -1,38 +1,38 @@
 {
-    "@metadata": {
-        "authors": []
-    },
-    "renameuser": "Rename user",
-    "renameuser-linkoncontribs": "rename user",
-    "renameuser-linkoncontribs-text": "Rename this user",
-    "renameuser-desc": "Adds a [[Special:RenameUser|special page]] to rename a 
user (need ''renameuser'' right)",
-    "renameuser-summary": "",
-    "renameuserold": "Current username:",
-    "renameusernew": "New username:",
-    "renameuserreason": "Reason:",
-    "renameusermove": "Move user and talk pages (and their subpages) to new 
name",
-    "renameusersuppress": "Do not create redirects to the new name",
-    "renameuserreserve": "Block the old username from future use",
-    "renameuserwarnings": "Warnings:",
-    "renameuserconfirm": "Yes, rename the user",
-    "renameusersubmit": "Submit",
-    "renameuser-submit-blocklog": "Show block log for user",
-    "renameusererrordoesnotexist": "The user \"<nowiki>$1</nowiki>\" does not 
exist.",
-    "renameusererrorexists": "The user \"<nowiki>$1</nowiki>\" already 
exists.",
-    "renameusererrorinvalid": "The username \"<nowiki>$1</nowiki>\" is 
invalid.",
-    "renameuser-error-request": "There was a problem with receiving the 
request.\nPlease go back and try again.",
-    "renameuser-error-same-user": "You cannot rename a user to the same thing 
as before.",
-    "renameusersuccess": "The user \"<nowiki>$1</nowiki>\" has been renamed to 
\"<nowiki>$2</nowiki>\".",
-    "renameuser-page-exists": "The page $1 already exists and cannot be 
automatically overwritten.",
-    "renameuser-page-moved": "The page $1 has been moved to $2.",
-    "renameuser-page-unmoved": "The page $1 could not be moved to $2.",
-    "log-name-renameuser": "User rename log",
-    "log-description-renameuser": "This is a log of changes to user names.",
-    "logentry-renameuser-renameuser": "$1 {{GENDER:$2|renamed}} user $4 
({{PLURAL:$6|$6 edit|$6 edits}}) to $5",
-    "logentry-renameuser-renameuser-legacier": "$1 renamed user $4 to $5",
-    "logentry-renameuser-renameuser-legaciest": "$1",
-    "renameuser-move-log": "Automatically moved page while renaming the user 
\"[[User:$1|$1]]\" to \"[[User:$2|$2]]\"",
-    "action-renameuser": "rename users",
-    "right-renameuser": "Rename users",
-    "renameuser-renamed-notice": "This user has been renamed.\nThe rename log 
is provided below for reference."
+       "@metadata": {
+               "authors": []
+       },
+       "renameuser": "Rename user",
+       "renameuser-linkoncontribs": "rename user",
+       "renameuser-linkoncontribs-text": "Rename this user",
+       "renameuser-desc": "Adds a [[Special:RenameUser|special page]] to 
rename a user (need ''renameuser'' right)",
+       "renameuser-summary": "",
+       "renameuserold": "Current username:",
+       "renameusernew": "New username:",
+       "renameuserreason": "Reason:",
+       "renameusermove": "Move user and talk pages (and their subpages) to new 
name",
+       "renameusersuppress": "Do not create redirects to the new name",
+       "renameuserreserve": "Block the old username from future use",
+       "renameuserwarnings": "Warnings:",
+       "renameuserconfirm": "Yes, rename the user",
+       "renameusersubmit": "Submit",
+       "renameuser-submit-blocklog": "Show block log for user",
+       "renameusererrordoesnotexist": "The user \"<nowiki>$1</nowiki>\" does 
not exist.",
+       "renameusererrorexists": "The user \"<nowiki>$1</nowiki>\" already 
exists.",
+       "renameusererrorinvalid": "The username \"<nowiki>$1</nowiki>\" is 
invalid.",
+       "renameuser-error-request": "There was a problem with receiving the 
request.\nPlease go back and try again.",
+       "renameuser-error-same-user": "You cannot rename a user to the same 
thing as before.",
+       "renameusersuccess": "The user \"<nowiki>$1</nowiki>\" has been renamed 
to \"<nowiki>$2</nowiki>\".",
+       "renameuser-page-exists": "The page $1 already exists and cannot be 
automatically overwritten.",
+       "renameuser-page-moved": "The page $1 has been moved to $2.",
+       "renameuser-page-unmoved": "The page $1 could not be moved to $2.",
+       "log-name-renameuser": "User rename log",
+       "log-description-renameuser": "This is a log of changes to user names.",
+       "logentry-renameuser-renameuser": "$1 {{GENDER:$2|renamed}} user $4 
({{PLURAL:$6|$6 edit|$6 edits}}) to $5",
+       "logentry-renameuser-renameuser-legacier": "$1 renamed user $4 to $5",
+       "logentry-renameuser-renameuser-legaciest": "$1",
+       "renameuser-move-log": "Automatically moved page while renaming the 
user \"[[User:$1|$1]]\" to \"[[User:$2|$2]]\"",
+       "action-renameuser": "rename users",
+       "right-renameuser": "Rename users",
+       "renameuser-renamed-notice": "This user has been renamed.\nThe rename 
log is provided below for reference."
 }
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..d81a292
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<ruleset>
+       <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
+       <file>.</file>
+       <arg name="extensions" value="php,php5,inc"/>
+       <arg name="encoding" value="utf8"/>
+       <exclude-pattern>vendor</exclude-pattern>
+</ruleset>
diff --git a/renameUserCleanup.php b/renameUserCleanup.php
index 25c4a1f..3a22e29 100644
--- a/renameUserCleanup.php
+++ b/renameUserCleanup.php
@@ -27,12 +27,13 @@
 if ( $IP === false ) {
        $IP = __DIR__ . '/../..';
 }
-require_once( "$IP/maintenance/Maintenance.php" );
+require_once "$IP/maintenance/Maintenance.php";
 
 class RenameUserCleanup extends Maintenance {
        public function __construct() {
                parent::__construct();
-               $this->mDescription = "Maintenance script to finish incomplete 
rename user, in particular to reassign edits that were missed";
+               $this->mDescription = 'Maintenance script to finish incomplete 
rename user, ' .
+                       'in particular to reassign edits that were missed';
                $this->addOption( 'olduser', 'Old user name', true, true );
                $this->addOption( 'newuser', 'New user name', true, true );
                $this->addOption( 'olduid', 'Old user id in revision records 
(DANGEROUS)', false, true );
@@ -53,9 +54,9 @@
                }
                $this->doUpdates( $olduser, $newuser, $newuser->getId() );
                $this->doUpdates( $olduser, $newuser, 0 );
-               
+
                print "Done!\n";
-               exit(0);
+               exit( 0 );
        }
 
        /**
@@ -64,19 +65,19 @@
         */
        public function checkUserExistence( $olduser, $newuser ) {
                if ( !$newuser->getId() ) {
-                       $this->error( "No such user: " . $this->getOption( 
'newuser' ), true );
-                       exit(1);
+                       $this->error( 'No such user: ' . $this->getOption( 
'newuser' ), true );
+                       exit( 1 );
                }
-               if ($olduser->getId() ) {
-                       print "WARNING!!: Old user still exists: " . 
$this->getOption( 'olduser' ) . "\n";
+               if ( $olduser->getId() ) {
+                       print 'WARNING!!: Old user still exists: ' . 
$this->getOption( 'olduser' ) . "\n";
                        print "proceed anyways? We'll only re-attribute edits 
that have the new user uid (or 0)";
-                       print " or the uid specified by the caller, and the old 
user name.  [N/y]   ";
-                       $stdin = fopen ("php://stdin","rt");
-                       $line = fgets($stdin);
-                       fclose($stdin);
-                       if ( $line[0] != "Y" && $line[0] != "y" ) {
+                       print ' or the uid specified by the caller, and the old 
user name.  [N/y]   ';
+                       $stdin = fopen( 'php://stdin', 'rt' );
+                       $line = fgets( $stdin );
+                       fclose( $stdin );
+                       if ( $line[0] !== 'Y' && $line[0] !== 'y' ) {
                                print "Exiting at user's request\n";
-                               exit(0);
+                               exit( 0 );
                        }
                }
        }
@@ -92,50 +93,55 @@
 
                $result = $dbr->select( 'logging', '*',
                        array( 'log_type' => 'renameuser',
-                               'log_action'    => 'renameuser',
+                               'log_action' => 'renameuser',
                                'log_namespace' => NS_USER,
-                               'log_title'     => $oldTitle->getDBkey(),
-                               'log_params'    => $newuser->getName()
-                            ),
+                               'log_title' => $oldTitle->getDBkey(),
+                               'log_params' => $newuser->getName()
+                       ),
                        __METHOD__
                );
-               if (! $result || ! $result->numRows() ) {
+               if ( !$result || !$result->numRows() ) {
                        // try the old format
                        $result = $dbr->select( 'logging', '*',
-                       array( 'log_type' => 'renameuser',
-                               'log_action'    => 'renameuser',
-                               'log_namespace' => NS_USER,
-                               'log_title'     => $olduser->getName(),
-                            ),
+                               array( 'log_type' => 'renameuser',
+                                       'log_action' => 'renameuser',
+                                       'log_namespace' => NS_USER,
+                                       'log_title' => $olduser->getName(),
+                               ),
                                __METHOD__
                        );
-                       if (! $result ||  ! $result->numRows() ) {
-                               print "No log entry found for a rename of 
".$olduser->getName()." to ".$newuser->getName().", proceed anyways??? [N/y] ";
-                               $stdin = fopen ("php://stdin","rt");
-                               $line = fgets($stdin);
-                               fclose($stdin);
-                               if ( $line[0] != "Y" && $line[0] != "y" ) {
+                       if ( !$result || !$result->numRows() ) {
+                               print 'No log entry found for a rename of ' . 
$olduser->getName() .
+                                       ' to ' . $newuser->getName() . ', 
proceed anyways??? [N/y] ';
+                               $stdin = fopen( 'php://stdin', 'rt' );
+                               $line = fgets( $stdin );
+                               fclose( $stdin );
+                               if ( $line[0] !== 'Y' && $line[0] !== 'y' ) {
                                        print "Exiting at user's request\n";
-                                       exit(1);
+                                       exit( 1 );
                                }
                        } else {
                                foreach ( $result as $row ) {
-                                       print "Found possible log entry of the 
rename, please check: ".$row->log_title." with comment ".$row->log_comment." on 
$row->log_timestamp\n";
+                                       print 'Found possible log entry of the 
rename, please check: ' .
+                                               $row->log_title . ' with 
comment ' . $row->log_comment .
+                                               " on $row->log_timestamp\n";
                                }
                        }
                } else {
                        foreach ( $result as $row ) {
-                               print "Found log entry of the rename: 
".$olduser->getName()." to ".$newuser->getName()." on $row->log_timestamp\n";
+                               print 'Found log entry of the rename: ' . 
$olduser->getName() .
+                                       ' to ' . $newuser->getName() . " on 
$row->log_timestamp\n";
                        }
                }
-               if ($result && $result->numRows() > 1) {
-                       print "More than one rename entry found in the log, not 
sure what to do. Continue anyways? [N/y]  ";
-                       $stdin = fopen ("php://stdin","rt");
-                       $line = fgets($stdin);
-                       fclose($stdin);
-                       if ( $line[0] != "Y" && $line[0] != "y" ) {
+               if ( $result && $result->numRows() > 1 ) {
+                       print 'More than one rename entry found in the log, not 
sure ' .
+                               'what to do. Continue anyways? [N/y]  ';
+                       $stdin = fopen( 'php://stdin', 'rt' );
+                       $line = fgets( $stdin );
+                       fclose( $stdin );
+                       if ( $line[0] !== 'Y' && $line[0] !== 'y' ) {
                                print "Exiting at user's request\n";
-                               exit(1);
+                               exit( 1 );
                        }
                }
        }
@@ -146,12 +152,18 @@
         * @param $uid
         */
        public function doUpdates( $olduser, $newuser, $uid ) {
-               $this->updateTable( 'revision', 'rev_user_text', 'rev_user', 
'rev_timestamp', $olduser, $newuser, $uid );
-               $this->updateTable( 'archive', 'ar_user_text', 'ar_user', 
'ar_timestamp',  $olduser, $newuser, $uid );
-               $this->updateTable( 'logging', 'log_user_text', 'log_user', 
'log_timestamp', $olduser, $newuser, $uid );
-               $this->updateTable( 'image', 'img_user_text', 'img_user', 
'img_timestamp', $olduser, $newuser, $uid );
-               $this->updateTable( 'oldimage', 'oi_user_text', 'oi_user', 
'oi_timestamp', $olduser, $newuser, $uid );
-               $this->updateTable( 'filearchive', 'fa_user_text','fa_user', 
'fa_timestamp', $olduser, $newuser, $uid );
+               $this->updateTable( 'revision', 'rev_user_text', 'rev_user', 
'rev_timestamp',
+                       $olduser, $newuser, $uid );
+               $this->updateTable( 'archive', 'ar_user_text', 'ar_user', 
'ar_timestamp',
+                       $olduser, $newuser, $uid );
+               $this->updateTable( 'logging', 'log_user_text', 'log_user', 
'log_timestamp',
+                       $olduser, $newuser, $uid );
+               $this->updateTable( 'image', 'img_user_text', 'img_user', 
'img_timestamp',
+                       $olduser, $newuser, $uid );
+               $this->updateTable( 'oldimage', 'oi_user_text', 'oi_user', 
'oi_timestamp',
+                       $olduser, $newuser, $uid );
+               $this->updateTable( 'filearchive', 'fa_user_text', 'fa_user', 
'fa_timestamp',
+                       $olduser, $newuser, $uid );
        }
 
        /**
@@ -164,56 +176,63 @@
         * @param $uid
         * @return int
         */
-       public function updateTable( $table, $usernamefield, $useridfield, 
$timestampfield, $olduser, $newuser, $uid ) {
+       public function updateTable( $table, $usernamefield, $useridfield,
+               $timestampfield, $olduser, $newuser, $uid
+       ) {
                $dbw = wfGetDB( DB_MASTER );
 
                $contribs = $dbw->selectField( $table, 'count(*)',
                        array( $usernamefield => $olduser->getName(), 
$useridfield => $uid ), __METHOD__ );
 
                if ( $contribs == 0 ) {
-                       print "No edits to be re-attributed from table $table 
for uid $uid\n" ;
-                       return(0);
+                       print "No edits to be re-attributed from table $table 
for uid $uid\n";
+
+                       return ( 0 );
                }
 
                print "Found $contribs edits to be re-attributed from table 
$table for uid $uid\n";
                if ( $uid != $newuser->getId() ) {
-                       print "If you proceed, the uid field will be set to 
that of the new user name (i.e. ".$newuser->getId().") in these rows.\n";
+                       print 'If you proceed, the uid field will be set to 
that ' .
+                               'of the new user name (i.e. ' . 
$newuser->getId() . ") in these rows.\n";
                }
 
-               print "Proceed? [N/y]  ";
-               $stdin = fopen ("php://stdin","rt");
-               $line = fgets($stdin);
-               fclose($stdin);
-               if ( $line[0] != "Y" && $line[0] != "y" ) {
+               print 'Proceed? [N/y]  ';
+               $stdin = fopen( 'php://stdin', 'rt' );
+               $line = fgets( $stdin );
+               fclose( $stdin );
+               if ( $line[0] !== 'Y' && $line[0] !== 'y' ) {
                        print "Skipping at user's request\n";
-                       return(0);
+
+                       return ( 0 );
                }
 
                $selectConds = array( $usernamefield => $olduser->getName(), 
$useridfield => $uid );
                $updateFields = array( $usernamefield => $newuser->getName(), 
$useridfield => $newuser->getId() );
 
                while ( $contribs > 0 ) {
-                       print "Doing batch of up to approximately 
".$this->mBatchSize."\n";
-                       print "Do this batch? [N/y]  ";
-                       $stdin = fopen ("php://stdin","rt");
-                       $line = fgets($stdin);
-                       fclose($stdin);
-                       if ( $line[0] != "Y" && $line[0] != "y" ) {
+                       print 'Doing batch of up to approximately ' . 
$this->mBatchSize . "\n";
+                       print 'Do this batch? [N/y]  ';
+                       $stdin = fopen( 'php://stdin', 'rt' );
+                       $line = fgets( $stdin );
+                       fclose( $stdin );
+                       if ( $line[0] !== 'Y' && $line[0] !== 'y' ) {
                                print "Skipping at user's request\n";
-                               return(0);
+
+                               return ( 0 );
                        }
                        $dbw->begin();
-                       $result = $dbw->select( $table, $timestampfield, 
$selectConds , __METHOD__,
-                               array( 'ORDER BY' => $timestampfield.' DESC', 
'LIMIT' => $this->mBatchSize ) );
-                       if (! $result) {
+                       $result = $dbw->select( $table, $timestampfield, 
$selectConds, __METHOD__,
+                               array( 'ORDER BY' => $timestampfield . ' DESC', 
'LIMIT' => $this->mBatchSize ) );
+                       if ( !$result ) {
                                print "There were rows for updating but now 
they are gone. Skipping.\n";
                                $dbw->rollback();
-                               return(0);
+
+                               return ( 0 );
                        }
-                       $result->seek($result->numRows() -1 );
+                       $result->seek( $result->numRows() - 1 );
                        $row = $result->fetchObject();
                        $timestamp = $row->$timestampfield;
-                       $updateCondsWithTime = array_merge( $selectConds, array 
("$timestampfield >= $timestamp") );
+                       $updateCondsWithTime = array_merge( $selectConds, 
array( "$timestampfield >= $timestamp" ) );
                        $success = $dbw->update( $table, $updateFields, 
$updateCondsWithTime, __METHOD__ );
                        if ( $success ) {
                                $rowsDone = $dbw->affectedRows();
@@ -221,16 +240,17 @@
                        } else {
                                print "Problem with the update, rolling back 
and exiting\n";
                                $dbw->rollback();
-                               exit(1);
+                               exit( 1 );
                        }
-                       //$contribs = User::edits( $olduser->getId() );
+
+                       // $contribs = User::edits( $olduser->getId() );
                        $contribs = $dbw->selectField( $table, 'count(*)', 
$selectConds, __METHOD__ );
                        print "Updated $rowsDone edits; $contribs edits 
remaining to be re-attributed\n";
                }
-               return(0);
-       }
 
+               return ( 0 );
+       }
 }
 
-$maintClass = "RenameUserCleanup";
-require_once( RUN_MAINTENANCE_IF_MAIN );
+$maintClass = 'RenameUserCleanup';
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/specials/SpecialRenameuser.php b/specials/SpecialRenameuser.php
index 47c0ff3..74f19af 100644
--- a/specials/SpecialRenameuser.php
+++ b/specials/SpecialRenameuser.php
@@ -30,11 +30,10 @@
                }
 
                if ( wfReadOnly() ) {
-                       $out->readOnlyPage();
-                       return;
+                       throw new ReadOnlyError;
                }
 
-               if( $user->isBlocked() ){
+               if ( $user->isBlocked() ) {
                        throw new UserBlockedError( $this->getUser()->mBlock );
                }
 
@@ -45,50 +44,60 @@
                $oldusername = Title::makeTitle( NS_USER, $oldnamePar );
                $newnamePar = isset( $usernames[1] ) ? $usernames[1] : null;
                $newnamePar = trim( str_replace( '_', ' ', $request->getText( 
'newusername', $newnamePar ) ) );
-               // Force uppercase of newusername, otherwise wikis with 
wgCapitalLinks=false can create lc usernames
+               // Force uppercase of newusername, otherwise wikis
+               // with wgCapitalLinks=false can create lc usernames
                $newusername = Title::makeTitleSafe( NS_USER, 
$wgContLang->ucfirst( $newnamePar ) );
                $oun = is_object( $oldusername ) ? $oldusername->getText() : '';
                $nun = is_object( $newusername ) ? $newusername->getText() : '';
                $token = $user->getEditToken();
                $reason = $request->getText( 'reason' );
 
-               $move_checked = $request->getBool( 'movepages', 
!$request->wasPosted());
+               $move_checked = $request->getBool( 'movepages', 
!$request->wasPosted() );
                $suppress_checked = $request->getCheck( 'suppressredirect' );
 
                $warnings = array();
-               if ( $oun && $nun && !$request->getCheck( 'confirmaction' )  ) {
+               if ( $oun && $nun && !$request->getCheck( 'confirmaction' ) ) {
                        Hooks::run( 'RenameUserWarning', array( $oun, $nun, 
&$warnings ) );
                }
 
                $out->addHTML(
-                       Xml::openElement( 'form', array( 'method' => 'post', 
'action' => $this->getPageTitle()->getLocalUrl(), 'id' => 'renameuser' ) ) .
+                       Xml::openElement( 'form', array(
+                               'method' => 'post',
+                               'action' => 
$this->getPageTitle()->getLocalUrl(),
+                               'id' => 'renameuser'
+                       ) ) .
                        Xml::openElement( 'fieldset' ) .
                        Xml::element( 'legend', null, $this->msg( 'renameuser' 
)->text() ) .
                        Xml::openElement( 'table', array( 'id' => 
'mw-renameuser-table' ) ) .
                        "<tr>
                                <td class='mw-label'>" .
-                                       Xml::label( $this->msg( 'renameuserold' 
)->text(), 'oldusername' ) .
-                               "</td>
+                       Xml::label( $this->msg( 'renameuserold' )->text(), 
'oldusername' ) .
+                       "</td>
                                <td class='mw-input'>" .
-                                       Xml::input( 'oldusername', 20, $oun, 
array( 'type' => 'text', 'tabindex' => '1' ) ) . ' ' .
-                               "</td>
+                       Xml::input( 'oldusername', 20, $oun, array( 'type' => 
'text', 'tabindex' => '1' ) ) . ' ' .
+                       "</td>
                        </tr>
                        <tr>
                                <td class='mw-label'>" .
-                                       Xml::label( $this->msg( 'renameusernew' 
)->text(), 'newusername' ) .
-                               "</td>
+                       Xml::label( $this->msg( 'renameusernew' )->text(), 
'newusername' ) .
+                       "</td>
                                <td class='mw-input'>" .
-                                       Xml::input( 'newusername', 20, $nun, 
array( 'type' => 'text', 'tabindex' => '2' ) ) .
-                               "</td>
+                       Xml::input( 'newusername', 20, $nun, array( 'type' => 
'text', 'tabindex' => '2' ) ) .
+                       "</td>
                        </tr>
                        <tr>
                                <td class='mw-label'>" .
-                                       Xml::label( $this->msg( 
'renameuserreason' )->text(), 'reason' ) .
-                               "</td>
+                       Xml::label( $this->msg( 'renameuserreason' )->text(), 
'reason' ) .
+                       "</td>
                                <td class='mw-input'>" .
-                                       Xml::input( 'reason', 40, $reason, 
array( 'type' => 'text', 'tabindex' => '3', 'maxlength' => 255 ) ) .
-                               "</td>
-                       </tr>"
+                       Xml::input(
+                               'reason',
+                               40,
+                               $reason,
+                               array( 'type' => 'text', 'tabindex' => '3', 
'maxlength' => 255 )
+                       ) .
+                       '</td>
+                       </tr>'
                );
                if ( $user->isAllowed( 'move' ) ) {
                        $out->addHTML( "
@@ -96,10 +105,10 @@
                                        <td>&#160;
                                        </td>
                                        <td class='mw-input'>" .
-                                               Xml::checkLabel( $this->msg( 
'renameusermove' )->text(), 'movepages', 'movepages',
-                                                       $move_checked, array( 
'tabindex' => '4' ) ) .
-                                       "</td>
-                               </tr>"
+                               Xml::checkLabel( $this->msg( 'renameusermove' 
)->text(), 'movepages', 'movepages',
+                                       $move_checked, array( 'tabindex' => '4' 
) ) .
+                               '</td>
+                               </tr>'
                        );
 
                        if ( $user->isAllowed( 'suppressredirect' ) ) {
@@ -108,15 +117,15 @@
                                                <td>&#160;
                                                </td>
                                                <td class='mw-input'>" .
-                                                       Xml::checkLabel(
-                                                               $this->msg( 
'renameusersuppress' )->text(),
-                                                               
'suppressredirect',
-                                                               
'suppressredirect',
-                                                               
$suppress_checked,
-                                                               array( 
'tabindex' => '5' )
-                                                       ) .
-                                               "</td>
-                                       </tr>"
+                                       Xml::checkLabel(
+                                               $this->msg( 
'renameusersuppress' )->text(),
+                                               'suppressredirect',
+                                               'suppressredirect',
+                                               $suppress_checked,
+                                               array( 'tabindex' => '5' )
+                                       ) .
+                                       '</td>
+                                       </tr>'
                                );
                        }
                }
@@ -133,25 +142,25 @@
                                        <td class='mw-label'>" . $this->msg( 
'renameuserwarnings' )->escaped() . "
                                        </td>
                                        <td class='mw-input'>" .
-                                               '<ul style="color: red; 
font-weight: bold"><li>' .
-                                                       implode( '</li><li>', 
$warningsHtml ) . '</li></ul>' .
-                                       "</td>
-                               </tr>"
+                               '<ul style="color: red; font-weight: 
bold"><li>' .
+                               implode( '</li><li>', $warningsHtml ) . 
'</li></ul>' .
+                               '</td>
+                               </tr>'
                        );
                        $out->addHTML( "
                                <tr>
                                        <td>&#160;
                                        </td>
                                        <td class='mw-input'>" .
-                                               Xml::checkLabel(
-                                                       $this->msg( 
'renameuserconfirm' )->text(),
-                                                       'confirmaction',
-                                                       'confirmaction',
-                                                       false,
-                                                       array( 'tabindex' => 
'6' )
-                                               ) .
-                                       "</td>
-                               </tr>"
+                               Xml::checkLabel(
+                                       $this->msg( 'renameuserconfirm' 
)->text(),
+                                       'confirmaction',
+                                       'confirmaction',
+                                       false,
+                                       array( 'tabindex' => '6' )
+                               ) .
+                               '</td>
+                               </tr>'
                        );
                }
                $out->addHTML( "
@@ -159,25 +168,25 @@
                                <td>&#160;
                                </td>
                                <td class='mw-submit'>" .
-                                       Xml::submitButton(
-                                               $this->msg( 'renameusersubmit' 
)->text(),
-                                               array(
-                                                       'name' => 'submit',
-                                                       'tabindex' => '7',
-                                                       'id' => 'submit'
-                                               )
-                                       ) .
-                                       ' ' .
-                                       Xml::submitButton(
-                                               $this->msg( 
'renameuser-submit-blocklog' )->text(),
-                                               array (
-                                                       'name' => 
'submit-showBlockLog',
-                                                       'id' => 
'submit-showBlockLog',
-                                                       'tabindex' => '8'
-                                               )
-                                       ) .
-                               "</td>
-                       </tr>" .
+                       Xml::submitButton(
+                               $this->msg( 'renameusersubmit' )->text(),
+                               array(
+                                       'name' => 'submit',
+                                       'tabindex' => '7',
+                                       'id' => 'submit'
+                               )
+                       ) .
+                       ' ' .
+                       Xml::submitButton(
+                               $this->msg( 'renameuser-submit-blocklog' 
)->text(),
+                               array(
+                                       'name' => 'submit-showBlockLog',
+                                       'id' => 'submit-showBlockLog',
+                                       'tabindex' => '8'
+                               )
+                       ) .
+                       '</td>
+                       </tr>' .
                        Xml::closeElement( 'table' ) .
                        Xml::closeElement( 'fieldset' ) .
                        Html::hidden( 'token', $token ) .
@@ -186,7 +195,8 @@
 
                // Show block log if requested
                if ( $showBlockLog && is_object( $oldusername ) ) {
-                       $this->showLogExtract( $oldusername, 'block', $out ) ;
+                       $this->showLogExtract( $oldusername, 'block', $out );
+
                        return;
                }
 
@@ -198,17 +208,21 @@
                        return;
                } elseif ( !$request->wasPosted() || !$user->matchEditToken( 
$request->getVal( 'token' ) ) ) {
                        $out->wrapWikiMsg( "<div class=\"errorbox\">$1</div>", 
'renameuser-error-request' );
+
                        return;
                } elseif ( !is_object( $oldusername ) ) {
                        $out->wrapWikiMsg( "<div class=\"errorbox\">$1</div>",
                                array( 'renameusererrorinvalid', 
$request->getText( 'oldusername' ) ) );
+
                        return;
                } elseif ( !is_object( $newusername ) ) {
                        $out->wrapWikiMsg( "<div class=\"errorbox\">$1</div>",
                                array( 'renameusererrorinvalid', 
$request->getText( 'newusername' ) ) );
+
                        return;
                } elseif ( $oldusername->getText() == $newusername->getText() ) 
{
                        $out->wrapWikiMsg( "<div class=\"errorbox\">$1</div>", 
'renameuser-error-same-user' );
+
                        return;
                }
 
@@ -220,11 +234,13 @@
                if ( !is_object( $olduser ) ) {
                        $out->wrapWikiMsg( "<div class=\"errorbox\">$1</div>",
                                array( 'renameusererrorinvalid', 
$oldusername->getText() ) );
+
                        return;
                }
                if ( !is_object( $newuser ) || !User::isCreatableName( 
$newuser->getName() ) ) {
                        $out->wrapWikiMsg( "<div class=\"errorbox\">$1</div>",
                                array( 'renameusererrorinvalid', 
$newusername->getText() ) );
+
                        return;
                }
 
@@ -253,17 +269,22 @@
                if ( $uid == 0 ) {
                        $out->wrapWikiMsg( "<div class=\"errorbox\">$1</div>",
                                array( 'renameusererrordoesnotexist', 
$oldusername->getText() ) );
+
                        return;
                }
 
                if ( $newuser->idForName() != 0 ) {
                        $out->wrapWikiMsg( "<div class=\"errorbox\">$1</div>",
                                array( 'renameusererrorexists', 
$newusername->getText() ) );
+
                        return;
                }
 
                // Give other affected extensions a chance to validate or abort
-               if ( !Hooks::run( 'RenameUserAbort', array( $uid, 
$oldusername->getText(), $newusername->getText() ) ) ) {
+               if ( !Hooks::run(
+                       'RenameUserAbort',
+                       array( $uid, $oldusername->getText(), 
$newusername->getText() )
+               ) ) {
                        return;
                }
 
@@ -295,7 +316,7 @@
                                array(
                                        'page_namespace IN (' . NS_USER . ',' . 
NS_USER_TALK . ')',
                                        '(page_title ' . $dbr->buildLike( 
$oldusername->getDBkey() . '/', $dbr->anyString() ) .
-                                               ' OR page_title = ' . 
$dbr->addQuotes( $oldusername->getDBkey() ) . ')'
+                                       ' OR page_title = ' . $dbr->addQuotes( 
$oldusername->getDBkey() ) . ')'
                                ),
                                __METHOD__
                        );
@@ -315,20 +336,20 @@
                                if ( $newPage->exists() && 
!$oldPage->isValidMoveTarget( $newPage ) ) {
                                        $link = Linker::linkKnown( $newPage );
                                        $output .= Html::rawElement(
-                                                               'li',
-                                                               array( 'class' 
=> 'mw-renameuser-pe' ),
-                                                               wfMessage( 
'renameuser-page-exists' )->rawParams( $link )->escaped()
-                                                       );
+                                               'li',
+                                               array( 'class' => 
'mw-renameuser-pe' ),
+                                               $this->msg( 
'renameuser-page-exists' )->rawParams( $link )->escaped()
+                                       );
                                } else {
                                        $success = $oldPage->moveTo(
-                                                               $newPage,
-                                                               false,
-                                                               wfMessage(
-                                                                       
'renameuser-move-log',
-                                                                       
$oldusername->getText(),
-                                                                       
$newusername->getText() )->inContentLanguage()->text(),
-                                                               
!$suppressRedirect
-                                                       );
+                                               $newPage,
+                                               false,
+                                               $this->msg(
+                                                       'renameuser-move-log',
+                                                       $oldusername->getText(),
+                                                       $newusername->getText() 
)->inContentLanguage()->text(),
+                                               !$suppressRedirect
+                                       );
                                        if ( $success === true ) {
                                                # oldPage is not known in case 
of redirect suppression
                                                $oldLink = Linker::link( 
$oldPage, null, array(), array( 'redirect' => 'no' ) );
@@ -337,17 +358,17 @@
                                                $newLink = Linker::linkKnown( 
$newPage );
 
                                                $output .= Html::rawElement(
-                                                                       'li',
-                                                                       array( 
'class' => 'mw-renameuser-pm' ),
-                                                                       
wfMessage( 'renameuser-page-moved' )->rawParams( $oldLink, $newLink )->escaped()
-                                                               );
+                                                       'li',
+                                                       array( 'class' => 
'mw-renameuser-pm' ),
+                                                       $this->msg( 
'renameuser-page-moved' )->rawParams( $oldLink, $newLink )->escaped()
+                                               );
                                        } else {
                                                $oldLink = Linker::linkKnown( 
$oldPage );
                                                $newLink = Linker::link( 
$newPage );
                                                $output .= Html::rawElement(
-                                                                       'li', 
array( 'class' => 'mw-renameuser-pu' ),
-                                                                       
wfMessage( 'renameuser-page-unmoved' )->rawParams( $oldLink, $newLink 
)->escaped()
-                                                               );
+                                                       'li', array( 'class' => 
'mw-renameuser-pu' ),
+                                                       $this->msg( 
'renameuser-page-unmoved' )->rawParams( $oldLink, $newLink )->escaped()
+                                               );
                                        }
                                }
                        }
@@ -366,7 +387,7 @@
         * @param $type
         * @param $out OutputPage
         */
-       function showLogExtract( $username, $type, &$out ) {
+       protected function showLogExtract( $username, $type, &$out ) {
                # Show relevant lines from the logs:
                $logPage = new LogPage( $type );
                $out->addHTML( Xml::element( 'h2', null, 
$logPage->getName()->text() ) . "\n" );

-- 
To view, visit https://gerrit.wikimedia.org/r/243119
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4545276d84fc0d0405d7c16ab179332298eb682b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Renameuser
Gerrit-Branch: master
Gerrit-Owner: Siebrand <siebr...@kitano.nl>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to