r84857 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84856‎ | r84857 | r84858 >
Date:17:07, 27 March 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Allow changePassword.php to use username or userid
Modified paths:
  • /trunk/phase3/maintenance/changePassword.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/changePassword.php
@@ -29,13 +29,20 @@
3030 class ChangePassword extends Maintenance {
3131 public function __construct() {
3232 parent::__construct();
33 - $this->addOption( "user", "The username to operate on", true, true );
 33+ $this->addOption( "user", "The username to operate on", false, true );
 34+ $this->addOption( "userid", "The user id to operate on", false, true );
3435 $this->addOption( "password", "The password to use", true, true );
3536 $this->mDescription = "Change a user's password";
3637 }
3738
3839 public function execute() {
39 - $user = User::newFromName( $this->getOption( 'user' ) );
 40+ if ( $this->hasOption( "user" ) ) {
 41+ $user = User::newFromName( $this->getOption( 'user' ) );
 42+ } elseif ( $this->hasOption( "userid" ) ) {
 43+ $user = User::newFromId( $this->getOption( 'userid' ) );
 44+ } else {
 45+ $this->error( "A \"user\" or \"userid\" must be set to change the password for" , true );
 46+ }
4047 if ( !$user->getId() ) {
4148 $this->error( "No such user: " . $this->getOption( 'user' ), true );
4249 }

Comments

#Comment by 😂 (talk | contribs)   17:34, 27 March 2011

Why not just reuse 'user' and see if is_int() or not.

#Comment by 😂 (talk | contribs)   17:34, 27 March 2011

Strike that entire comment, I meant to delete it because it was stupid and I figured it out already.

Status & tagging log