r20841 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20840‎ | r20841 | r20842 >
Date:13:44, 30 March 2007
Author:raymond
Status:old
Tags:
Comment:
* (bug 4939) Renameuser extension:
1) Don't allow renaming a user to an invalid username.
2) Do allow renaming an invalid username to a valid one.
Found another bug (and fixed it): oldusername was written with NS0 instead of NS2 into logs
Modified paths:
  • /trunk/extensions/Renameuser/SpecialRenameuser.php (modified) (history)
  • /trunk/extensions/Renameuser/SpecialRenameuser_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Renameuser/SpecialRenameuser_body.php
@@ -4,10 +4,10 @@
55 function Renameuser() {
66 SpecialPage::SpecialPage('Renameuser', 'renameuser');
77 }
8 -
 8+
99 function execute() {
1010 global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang, $wgLang;
11 - global $wgVersion, $wgMaxNameChars;
 11+ global $wgVersion, $wgMaxNameChars, $wgCapitalLinks;
1212
1313 $fname = 'Renameuser::execute';
1414
@@ -27,10 +27,9 @@
2828 $wgOut->versionRequired( '1.7.0' );
2929 return;
3030 }
31 -
32 - $oldusername = Title::newFromText( $wgRequest->getText( 'oldusername' ) );
33 - $newusername = Title::newFromText( $wgRequest->getText( 'newusername' ) );
3431
 32+ $oldusername = Title::newFromText( $wgRequest->getText( 'oldusername' ), NS_USER );
 33+ $newusername = Title::newFromText( $wgContLang->ucfirst( $wgRequest->getText( 'newusername' ) ), NS_USER ); // Force uppercase of newusername otherweise wikis with wgCapitalLinks=false can create lc usernames
3534 $action = $wgTitle->escapeLocalUrl();
3635 $renameuserold = wfMsgHtml( 'renameuserold' );
3736 $renameusernew = wfMsgHtml( 'renameusernew' );
@@ -77,32 +76,57 @@
7877
7978 if ( !is_object( $oldusername ) || !is_object( $newusername ) || $oldusername->getText() == $newusername->getText() )
8079 return;
81 -
 80+
8281 $wgOut->addHTML( '<hr />' );
83 -
 82+
8483 // Suppress username validation of old username
8584 $olduser = User::newFromName( $oldusername->getText(), false );
8685 $newuser = User::newFromName( $newusername->getText() );
8786
8887 // It won't be an object if for instance "|" is supplied as a value
8988 if ( !is_object( $olduser ) ) {
90 - $wgOut->addWikiText( wfMsg( 'renameusererrorinvalid', $oldusername->getText() ) );
 89+ $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorinvalid', $oldusername->getText() ) . "</div>" );
9190 return;
9291 }
9392
9493 if ( !is_object( $newuser ) ) {
95 - $wgOut->addWikiText( wfMsg( 'renameusererrorinvalid', $newusername->getText() ) );
 94+ $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorinvalid', $newusername->getText() ) . "</div>" );
9695 return;
9796 }
98 -
99 - $uid = $olduser->idForName();
 97+
 98+ // Check for the existence of lowercase oldusername in database.
 99+ // Until r19631 it was possible to rename a user to a name with first character as lowercase
 100+ if ( $wgRequest->getText( 'oldusername' ) !== $wgContLang->ucfirst( $wgRequest->getText( 'oldusername' ) ) ) {
 101+ // oldusername was entered as lowercase -> check for existence in table 'user'
 102+ $dbr_lc = wfGetDB( DB_SLAVE );
 103+ $s = trim( $wgRequest->getText( 'oldusername' ) );
 104+ $uid = $dbr_lc->selectField( 'user', 'user_id', array( 'user_name' => $s ), __METHOD__ );
 105+ if ( $uid === false ) {
 106+ if ( !$wgCapitalLinks ) {
 107+ $uid = 0; // We are on a lowercase wiki but lowercase username does not exists
 108+ } else {
 109+ $uid = $olduser->idForName(); // We are on a standard uppercase wiki, use normal
 110+ }
 111+ } else {
 112+ // username with lowercase exists
 113+ // Title::newFromText was nice, but forces uppercase
 114+ // for older rename accidents on lowercase wikis we need the lowercase username as entered in the form
 115+ $oldusername->mTextform = $wgRequest->getText( 'oldusername' );
 116+ $oldusername->mUrlform = $wgRequest->getText( 'oldusername' );
 117+ $oldusername->mDbkeyform = $wgRequest->getText( 'oldusername' );
 118+ }
 119+ } else {
 120+ // oldusername was entered as upperase -> standard procedure
 121+ $uid = $olduser->idForName();
 122+ }
 123+
100124 if ($uid == 0) {
101 - $wgOut->addWikiText( wfMsg( 'renameusererrordoesnotexist', $oldusername->getText() ) );
 125+ $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrordoesnotexist' , $oldusername->getText() ) . "</div>" );
102126 return;
103127 }
104 -
 128+
105129 if ($newuser->idForName() != 0) {
106 - $wgOut->addWikiText( wfMsg( 'renameusererrorexists', $newusername->getText() ) );
 130+ $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorexists', $newusername->getText() ) . "</div>" );
107131 return;
108132 }
109133
@@ -110,13 +134,13 @@
111135 if ( !$wgUser->isAllowed( 'siteadmin' ) ) {
112136 $contribs = User::edits( $uid );
113137 if ( RENAMEUSER_CONTRIBLIMIT != 0 && $contribs > RENAMEUSER_CONTRIBLIMIT ) {
114 - $wgOut->addWikiText(
 138+ $wgOut->addWikiText( "<div class=\"errorbox\">" .
115139 wfMsg( 'renameusererrortoomany',
116140 $oldusername->getText(),
117141 $wgLang->formatNum( $contribs ),
118142 $wgLang->formatNum( RENAMEUSER_CONTRIBLIMIT )
119143 )
120 - );
 144+ . "</div>" );
121145 return;
122146 }
123147 }
Index: trunk/extensions/Renameuser/SpecialRenameuser.php
@@ -18,7 +18,7 @@
1919 $wgExtensionCredits['specialpage'][] = array(
2020 'name' => 'Renameuser',
2121 'author' => 'Ævar Arnfjörð Bjarmason',
22 - 'url' => 'http://meta.wikimedia.org/wiki/Renameuser',
 22+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Renameuser',
2323 'description' => 'Rename a user (need \'\'renameuser\'\' right)',
2424 );
2525