r82284 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82283‎ | r82284 | r82285 >
Date:19:51, 16 February 2011
Author:happy-melon
Status:ok
Tags:
Comment:
revert r82283, loads of unrelated changes
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderUserGroupsModule.php (deleted) (history)
  • /trunk/phase3/includes/specials/SpecialResetpass.php (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -5,6 +5,12 @@
66 */
77
88 /**
 9+ * Int Number of characters in user_token field.
 10+ * @ingroup Constants
 11+ */
 12+define( 'USER_TOKEN_LENGTH', 32 );
 13+
 14+/**
915 * Int Serialized record version.
1016 * @ingroup Constants
1117 */
@@ -35,6 +41,13 @@
3642 * of the database.
3743 */
3844 class User {
 45+ /**
 46+ * Global constants made accessible as class constants so that autoloader
 47+ * magic can be used.
 48+ */
 49+ const USER_TOKEN_LENGTH = USER_TOKEN_LENGTH;
 50+ const MW_USER_VERSION = MW_USER_VERSION;
 51+ const EDIT_TOKEN_SUFFIX = EDIT_TOKEN_SUFFIX;
3952
4053 /**
4154 * Array of Strings List of member variables which are saved to the
@@ -364,7 +377,7 @@
365378 /**
366379 * Create a new user object from a user row.
367380 * The row should have all fields from the user table in it.
368 - * @param $row array A row from the user table
 381+ * @param $row Array A row from the user table
369382 * @return User
370383 */
371384 static function newFromRow( $row ) {
@@ -614,7 +627,6 @@
615628 if( !wfRunHooks( 'isValidPassword', array( $password, &$result, $this ) ) )
616629 return $result;
617630
618 -
619631 if ( $result === false ) {
620632 if( strlen( $password ) < $wgMinimalPasswordLength ) {
621633 return 'passwordtooshort';
@@ -1238,9 +1250,6 @@
12391251 // Deprecated, but kept for backwards-compatibility config
12401252 return false;
12411253 }
1242 -
1243 -
1244 -
12451254 if( in_array( wfGetIP(), $wgRateLimitsExcludedIPs ) ) {
12461255 // No other good way currently to disable rate limits
12471256 // for specific IPs. :P
@@ -1777,7 +1786,7 @@
17781787 }
17791788
17801789 if( !$this->isValidPassword( $str ) ) {
1781 - global $wgMinimalPasswordLength;
 1790+ global $wgMinimalPasswordLength;
17821791 $valid = $this->getPasswordValidity( $str );
17831792 if ( is_array( $valid ) ) {
17841793 $message = array_shift( $valid );
@@ -1787,7 +1796,7 @@
17881797 $params = array( $wgMinimalPasswordLength );
17891798 }
17901799 throw new PasswordError( wfMsgExt( $message, array( 'parsemag' ), $params ) );
1791 - }
 1800+ }
17921801 }
17931802
17941803 if( !$wgAuth->setPassword( $this, $str ) ) {
@@ -2197,7 +2206,6 @@
21982207 }
21992208
22002209 /**
2201 -
22022210 * Check if user is allowed to access a feature / make an action
22032211 * @param $action String action to be checked
22042212 * @return Boolean: True if action is allowed, else false
@@ -2521,8 +2529,8 @@
25222530 'user_newpassword' => $this->mNewpassword,
25232531 'user_newpass_time' => $dbw->timestampOrNull( $this->mNewpassTime ),
25242532 'user_real_name' => $this->mRealName,
2525 - 'user_email' => $this->mEmail,
2526 - 'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated ),
 2533+ 'user_email' => $this->mEmail,
 2534+ 'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated ),
25272535 'user_options' => '',
25282536 'user_touched' => $dbw->timestamp( $this->mTouched ),
25292537 'user_token' => $this->mToken,
@@ -2581,6 +2589,7 @@
25822590 }
25832591 $dbw = wfGetDB( DB_MASTER );
25842592 $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
 2593+
25852594 $fields = array(
25862595 'user_id' => $seqVal,
25872596 'user_name' => $name,
@@ -2792,7 +2801,7 @@
27932802 // are shorter than this, doesn't mean people wont be able
27942803 // to. Certain authentication plugins do NOT want to save
27952804 // domain passwords in a mysql database, so we should
2796 - // check this (incase $wgAuth->strict() is false).
 2805+ // check this (in case $wgAuth->strict() is false).
27972806 if( !$this->isValidPassword( $password ) ) {
27982807 return false;
27992808 }
@@ -2851,7 +2860,7 @@
28522861 return EDIT_TOKEN_SUFFIX;
28532862 } else {
28542863 if( !isset( $_SESSION['wsEditToken'] ) ) {
2855 - $token = $this->generateToken();
 2864+ $token = self::generateToken();
28562865 $_SESSION['wsEditToken'] = $token;
28572866 } else {
28582867 $token = $_SESSION['wsEditToken'];
@@ -2869,7 +2878,7 @@
28702879 * @param $salt String Optional salt value
28712880 * @return String The new random token
28722881 */
2873 - function generateToken( $salt = '' ) {
 2882+ public static function generateToken( $salt = '' ) {
28742883 $token = dechex( mt_rand() ) . dechex( mt_rand() );
28752884 return md5( $token . $salt );
28762885 }
@@ -2977,7 +2986,7 @@
29782987 $now = time();
29792988 $expires = $now + $wgUserEmailConfirmationTokenExpiry;
29802989 $expiration = wfTimestamp( TS_MW, $expires );
2981 - $token = wfGenerateToken( $this->mId . $this->mEmail . $expires );
 2990+ $token = self::generateToken( $this->mId . $this->mEmail . $expires );
29822991 $hash = md5( $token );
29832992 $this->load();
29842993 $this->mEmailToken = $hash;
@@ -3131,7 +3140,7 @@
31323141 * Get the timestamp of account creation.
31333142 *
31343143 * @return String|Bool Timestamp of account creation, or false for
3135 - * non-existent/anonymous user accounts.
 3144+ * non-existent/anonymous user accounts.
31363145 */
31373146 public function getRegistration() {
31383147 return $this->getId() > 0
@@ -3143,7 +3152,7 @@
31443153 * Get the timestamp of the first edit
31453154 *
31463155 * @return String|Bool Timestamp of first edit, or false for
3147 - * non-existent/anonymous user accounts.
 3156+ * non-existent/anonymous user accounts.
31483157 */
31493158 public function getFirstEditTimestamp() {
31503159 if( $this->getId() == 0 ) {
@@ -3333,9 +3342,9 @@
33343343 *
33353344 * @param $group String: the group to check for whether it can add/remove
33363345 * @return Array array( 'add' => array( addablegroups ),
3337 - * 'remove' => array( removablegroups ),
3338 - * 'add-self' => array( addablegroups to self),
3339 - * 'remove-self' => array( removable groups from self) )
 3346+ * 'remove' => array( removablegroups ),
 3347+ * 'add-self' => array( addablegroups to self),
 3348+ * 'remove-self' => array( removable groups from self) )
33403349 */
33413350 static function changeableByGroup( $group ) {
33423351 global $wgAddGroups, $wgRemoveGroups, $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
@@ -3573,27 +3582,31 @@
35743583 * @param $byEmail Boolean: account made by email?
35753584 * @param $reason String: user supplied reason
35763585 */
3577 - public function addNewUserLogEntry( $creator, $byEmail = false ) {
3578 - global $wgUser, $wgNewUserLog;
 3586+ public function addNewUserLogEntry( $byEmail = false, $reason = '' ) {
 3587+ global $wgUser, $wgContLang, $wgNewUserLog;
35793588 if( empty( $wgNewUserLog ) ) {
35803589 return true; // disabled
35813590 }
35823591
3583 - $action = ( $creator == $wgUser )
3584 - ? 'create2' # Safe to publish the creator
3585 - : 'create'; # Creator is an IP, don't splash it all over Special:Log
3586 -
3587 - $message = $byEmail
3588 - ? wfMsgForContent( 'newuserlog-byemail' )
3589 - : '';
3590 -
 3592+ if( $this->getName() == $wgUser->getName() ) {
 3593+ $action = 'create';
 3594+ } else {
 3595+ $action = 'create2';
 3596+ if ( $byEmail ) {
 3597+ if ( $reason === '' ) {
 3598+ $reason = wfMsgForContent( 'newuserlog-byemail' );
 3599+ } else {
 3600+ $reason = $wgContLang->commaList( array(
 3601+ $reason, wfMsgForContent( 'newuserlog-byemail' ) ) );
 3602+ }
 3603+ }
 3604+ }
35913605 $log = new LogPage( 'newusers' );
35923606 $log->addEntry(
35933607 $action,
35943608 $this->getUserPage(),
3595 - $message,
3596 - array( $this->getId() ),
3597 - $creator
 3609+ $reason,
 3610+ array( $this->getId() )
35983611 );
35993612 return true;
36003613 }
@@ -3603,18 +3616,12 @@
36043617 * Used by things like CentralAuth and perhaps other authplugins.
36053618 */
36063619 public function addNewUserLogEntryAutoCreate() {
3607 - global $wgNewUserLog;
3608 - if( empty( $wgNewUserLog ) ) {
 3620+ global $wgNewUserLog, $wgLogAutocreatedAccounts;
 3621+ if( !$wgNewUserLog || !$wgLogAutocreatedAccounts ) {
36093622 return true; // disabled
36103623 }
36113624 $log = new LogPage( 'newusers', false );
3612 - $log->addEntry(
3613 - 'autocreate',
3614 - $this->getUserPage(),
3615 - '',
3616 - array( $this->getId() ),
3617 - $this->getId()
3618 - );
 3625+ $log->addEntry( 'autocreate', $this->getUserPage(), '', array( $this->getId() ) );
36193626 return true;
36203627 }
36213628
Index: trunk/phase3/includes/HTMLForm.php
@@ -109,7 +109,6 @@
110110 protected $mButtons = array();
111111
112112 protected $mWrapperLegend = false;
113 - protected $mTokenAction = 'Edit';
114113
115114 /**
116115 * Build a new HTMLForm from an array of field attributes
@@ -185,7 +184,7 @@
186185 if ( !$class ) {
187186 throw new MWException( "Descriptor with no class: " . print_r( $descriptor, true ) );
188187 }
189 -
 188+
190189 $descriptor['fieldname'] = $fieldname;
191190
192191 $obj = new $class( $descriptor );
@@ -211,15 +210,14 @@
212211
213212 /**
214213 * Try submitting, with edit token check first
215 - * @return Status|boolean
 214+ * @return Status|boolean
216215 */
217216 function tryAuthorizedSubmit() {
218217 global $wgUser, $wgRequest;
219218 $editToken = $wgRequest->getVal( 'wpEditToken' );
220219
221220 $result = false;
222 - # FIXME
223 - if ( $wgRequest->wasPosted() ){#&& $this->getMethod() != 'post' || $wgUser->matchEditToken( $editToken ) ) {
 221+ if ( $this->getMethod() != 'post' || $wgUser->matchEditToken( $editToken ) ) {
224222 $result = $this->trySubmit();
225223 }
226224 return $result;
@@ -251,11 +249,6 @@
252250 * display.
253251 */
254252 function trySubmit() {
255 - # Check the session tokens
256 - # FIXME
257 - if ( false && !Token::match( null, $this->mTokenAction ) ) {
258 - return array( 'sessionfailure' );
259 - }
260253 # Check for validation
261254 foreach ( $this->mFlatFields as $fieldname => $field ) {
262255 if ( !empty( $field->mParams['nodata'] ) ) {
@@ -431,14 +424,9 @@
432425 global $wgUser;
433426
434427 $html = '';
 428+
435429 if( $this->getMethod() == 'post' ){
436 - # FIXME
437 - $token = new Token( $this->mTokenAction );
438 - $html .= Html::hidden(
439 - "wp{$this->mTokenAction}Token",
440 - $token->set(),
441 - array( 'id' => 'wpEditToken' )
442 - ) . "\n";
 430+ $html .= Html::hidden( 'wpEditToken', $wgUser->editToken(), array( 'id' => 'wpEditToken' ) ) . "\n";
443431 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
444432 }
445433
@@ -591,7 +579,6 @@
592580 $this->mSubmitTooltip = $name;
593581 }
594582
595 -
596583 /**
597584 * Set the id for the submit button.
598585 * @param $t String. FIXME: Integrity is *not* validated
@@ -620,15 +607,6 @@
621608 function setMessagePrefix( $p ) {
622609 $this->mMessagePrefix = $p;
623610 }
624 - /**
625 - * If you want to protect the form from CSRF by a token other than
626 - * the usual wsEditToken, set something here.
627 - * @see Token::set()
628 - * @param $a
629 - */
630 - function setTokenAction( $a ){
631 - $this->mTokenAction = ucfirst( $a );
632 - }
633611
634612 /**
635613 * Set the title for form submission
@@ -645,7 +623,7 @@
646624 function getTitle() {
647625 return $this->mTitle;
648626 }
649 -
 627+
650628 /**
651629 * Set the method used to submit the form
652630 * @param $method String
@@ -653,7 +631,7 @@
654632 public function setMethod( $method='post' ){
655633 $this->mMethod = $method;
656634 }
657 -
 635+
658636 public function getMethod(){
659637 return $this->mMethod;
660638 }
@@ -862,12 +840,12 @@
863841 if ( isset( $params['name'] ) ) {
864842 $this->mName = $params['name'];
865843 }
866 -
 844+
867845 $validName = Sanitizer::escapeId( $this->mName );
868846 if ( $this->mName != $validName && !isset( $params['nodata'] ) ) {
869847 throw new MWException( "Invalid name '{$this->mName}' passed to " . __METHOD__ );
870848 }
871 -
 849+
872850 $this->mID = "mw-input-{$this->mName}";
873851
874852 if ( isset( $params['default'] ) ) {
@@ -909,10 +887,10 @@
910888 global $wgRequest;
911889
912890 $errors = $this->validate( $value, $this->mParent->mFieldData );
913 -
 891+
914892 $cellAttributes = array();
915893 $verticalLabel = false;
916 -
 894+
917895 if ( !empty($this->mParams['vertical-label']) ) {
918896 $cellAttributes['colspan'] = 2;
919897 $verticalLabel = true;
@@ -930,9 +908,9 @@
931909 array( 'class' => 'mw-input' ) + $cellAttributes,
932910 $this->getInputHTML( $value ) . "\n$errors"
933911 );
934 -
 912+
935913 $fieldType = get_class( $this );
936 -
 914+
937915 if ($verticalLabel) {
938916 $html = Html::rawElement( 'tr',
939917 array( 'class' => 'mw-htmlform-vertical-label' ), $label );
@@ -1161,11 +1139,11 @@
11621140 if ( $p !== true ) {
11631141 return $p;
11641142 }
1165 -
 1143+
11661144 $value = trim( $value );
11671145
11681146 # http://dev.w3.org/html5/spec/common-microsyntaxes.html#real-numbers
1169 - # with the addition that a leading '+' sign is ok.
 1147+ # with the addition that a leading '+' sign is ok.
11701148 if ( !preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) {
11711149 return wfMsgExt( 'htmlform-float-invalid', 'parse' );
11721150 }
@@ -1204,8 +1182,8 @@
12051183 }
12061184
12071185 # http://dev.w3.org/html5/spec/common-microsyntaxes.html#signed-integers
1208 - # with the addition that a leading '+' sign is ok. Note that leading zeros
1209 - # are fine, and will be left in the input, which is useful for things like
 1186+ # with the addition that a leading '+' sign is ok. Note that leading zeros
 1187+ # are fine, and will be left in the input, which is useful for things like
12101188 # phone numbers when you know that they are integers (the HTML5 type=tel
12111189 # input does not require its value to be numeric). If you want a tidier
12121190 # value to, eg, save in the DB, clean it up with intval().
@@ -1437,8 +1415,8 @@
14381416 } else {
14391417 $thisAttribs = array( 'id' => "{$this->mID}-$info", 'value' => $info );
14401418
1441 - $checkbox = Xml::check(
1442 - $this->mName . '[]',
 1419+ $checkbox = Xml::check(
 1420+ $this->mName . '[]',
14431421 in_array( $info, $value, true ),
14441422 $attribs + $thisAttribs );
14451423 $checkbox .= '&#160;' . Html::rawElement( 'label', array( 'for' => "{$this->mID}-$info" ), $label );
@@ -1578,7 +1556,7 @@
15791557 class HTMLHiddenField extends HTMLFormField {
15801558 public function __construct( $params ) {
15811559 parent::__construct( $params );
1582 -
 1560+
15831561 # Per HTML5 spec, hidden fields cannot be 'required'
15841562 # http://dev.w3.org/html5/spec/states-of-the-type-attribute.html#hidden-state
15851563 unset( $this->mParams['required'] );
@@ -1627,7 +1605,7 @@
16281606 protected function needsLabel() {
16291607 return false;
16301608 }
1631 -
 1609+
16321610 /**
16331611 * Button cannot be invalid
16341612 */
Index: trunk/phase3/includes/OutputPage.php
@@ -2555,29 +2555,28 @@
25562556 // Legacy Scripts
25572557 $scripts .= "\n" . $this->mScripts;
25582558
2559 - $userScripts = array( 'user.options' );
2560 -
25612559 // Add site JS if enabled
25622560 if ( $wgUseSiteJs ) {
25632561 $scripts .= $this->makeResourceLoaderLink( $sk, 'site', ResourceLoaderModule::TYPE_SCRIPTS );
2564 - if( $wgUser->isLoggedIn() ){
2565 - $userScripts[] = 'user.groups';
2566 - }
25672562 }
25682563
2569 - // Add user JS if enabled
 2564+ // Add user JS if enabled - trying to load user.options as a bundle if possible
 2565+ $userOptionsAdded = false;
25702566 if ( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
25712567 $action = $wgRequest->getVal( 'action', 'view' );
25722568 if( $this->mTitle && $this->mTitle->isJsSubpage() && $sk->userCanPreview( $action ) ) {
25732569 # XXX: additional security check/prompt?
25742570 $scripts .= Html::inlineScript( "\n" . $wgRequest->getText( 'wpTextbox1' ) . "\n" ) . "\n";
25752571 } else {
2576 - # FIXME: this means that User:Me/Common.js doesn't load when previewing
2577 - # User:Me/Vector.js, and vice versa (bug26283)
2578 - $userScripts[] = 'user';
 2572+ $scripts .= $this->makeResourceLoaderLink(
 2573+ $sk, array( 'user', 'user.options' ), ResourceLoaderModule::TYPE_SCRIPTS
 2574+ );
 2575+ $userOptionsAdded = true;
25792576 }
25802577 }
2581 - $scripts .= $this->makeResourceLoaderLink( $sk, $userScripts, ResourceLoaderModule::TYPE_SCRIPTS );
 2578+ if ( !$userOptionsAdded ) {
 2579+ $scripts .= $this->makeResourceLoaderLink( $sk, 'user.options', ResourceLoaderModule::TYPE_SCRIPTS );
 2580+ }
25822581
25832582 return $scripts;
25842583 }
Index: trunk/phase3/includes/resourceloader/ResourceLoaderUserGroupsModule.php
@@ -1,61 +0,0 @@
2 -<?php
3 -/**
4 - * This program is free software; you can redistribute it and/or modify
5 - * it under the terms of the GNU General Public License as published by
6 - * the Free Software Foundation; either version 2 of the License, or
7 - * (at your option) any later version.
8 - *
9 - * This program is distributed in the hope that it will be useful,
10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 - * GNU General Public License for more details.
13 - *
14 - * You should have received a copy of the GNU General Public License along
15 - * with this program; if not, write to the Free Software Foundation, Inc.,
16 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 - * http://www.gnu.org/copyleft/gpl.html
18 - *
19 - * @file
20 - * @author Trevor Parscal
21 - * @author Roan Kattouw
22 - */
23 -
24 -/**
25 - * Module for user customizations
26 - */
27 -class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule {
28 -
29 - /* Protected Methods */
30 - protected $origin = self::ORIGIN_USER_SITEWIDE;
31 -
32 - protected function getPages( ResourceLoaderContext $context ) {
33 - if ( $context->getUser() ) {
34 - $user = User::newFromName( $context->getUser() );
35 - if( $user instanceof User ){
36 - $pages = array();
37 - foreach( $user->getEffectiveGroups() as $group ){
38 - if( in_array( $group, array( '*', 'user' ) ) ){
39 - continue;
40 - }
41 - $g = ucfirst( $group );
42 - $pages["MediaWiki:$g.js"] = array( 'type' => 'script' );
43 - $pages["MediaWiki:$g.css"] = array( 'type' => 'style' );
44 - }
45 - return $pages;
46 - }
47 - }
48 - return array();
49 - }
50 -
51 - /* Methods */
52 -
53 - public function getGroup() {
54 - return 'user';
55 - }
56 -
57 - public function getFlip( $context ) {
58 - global $wgContLang;
59 -
60 - return $wgContLang->getDir() !== $context->getDirection();
61 - }
62 -}
Index: trunk/phase3/includes/AutoLoader.php
@@ -152,7 +152,6 @@
153153 'LinksUpdate' => 'includes/LinksUpdate.php',
154154 'LocalisationCache' => 'includes/LocalisationCache.php',
155155 'LocalisationCache_BulkLoad' => 'includes/LocalisationCache.php',
156 - 'Login' => 'includes/Login.php',
157156 'LogPage' => 'includes/LogPage.php',
158157 'LogPager' => 'includes/LogEventsList.php',
159158 'LogEventsList' => 'includes/LogEventsList.php',
@@ -212,7 +211,6 @@
213212 'ResourceLoaderFileModule' => 'includes/resourceloader/ResourceLoaderFileModule.php',
214213 'ResourceLoaderSiteModule' => 'includes/resourceloader/ResourceLoaderSiteModule.php',
215214 'ResourceLoaderUserModule' => 'includes/resourceloader/ResourceLoaderUserModule.php',
216 - 'ResourceLoaderUserGroupsModule' => 'includes/resourceloader/ResourceLoaderUserGroupsModule.php',
217215 'ResourceLoaderUserOptionsModule' => 'includes/resourceloader/ResourceLoaderUserOptionsModule.php',
218216 'ResourceLoaderStartUpModule' => 'includes/resourceloader/ResourceLoaderStartUpModule.php',
219217 'ReverseChronologicalPager' => 'includes/Pager.php',
@@ -581,7 +579,6 @@
582580 'AncientPagesPage' => 'includes/specials/SpecialAncientpages.php',
583581 'BrokenRedirectsPage' => 'includes/specials/SpecialBrokenRedirects.php',
584582 'ContribsPager' => 'includes/specials/SpecialContributions.php',
585 - 'SpecialCreateAccount' => 'includes/specials/SpecialCreateAccount.php',
586583 'DBLockForm' => 'includes/specials/SpecialLockdb.php',
587584 'DBUnlockForm' => 'includes/specials/SpecialUnlockdb.php',
588585 'DeadendPagesPage' => 'includes/specials/SpecialDeadendpages.php',
@@ -681,7 +678,6 @@
682679 'UnwatchedpagesPage' => 'includes/specials/SpecialUnwatchedpages.php',
683680 'UploadForm' => 'includes/specials/SpecialUpload.php',
684681 'UploadSourceField' => 'includes/specials/SpecialUpload.php',
685 - 'SpecialUserlogin' => 'includes/specials/SpecialUserlogin.php',
686682 'UserrightsPage' => 'includes/specials/SpecialUserrights.php',
687683 'UsersPager' => 'includes/specials/SpecialListusers.php',
688684 'WantedCategoriesPage' => 'includes/specials/SpecialWantedcategories.php',
Index: trunk/phase3/includes/specials/SpecialResetpass.php
@@ -27,69 +27,14 @@
2828 * @ingroup SpecialPage
2929 */
3030 class SpecialResetpass extends SpecialPage {
31 -
32 - public $mFormFields = array(
33 - 'NameInfo' => array(
34 - 'type' => 'info',
35 - 'label-message' => 'yourname',
36 - 'default' => '',
37 - ),
38 - 'Name' => array(
39 - 'type' => 'hidden',
40 - 'name' => 'wpName',
41 - 'default' => null,
42 - ),
43 - 'OldPassword' => array(
44 - 'type' => 'password',
45 - 'label-message' => 'oldpassword',
46 - 'size' => '20',
47 - 'id' => 'wpPassword',
48 - 'required' => '',
49 - ),
50 - 'NewPassword' => array(
51 - 'type' => 'password',
52 - 'label-message' => 'newpassword',
53 - 'size' => '20',
54 - 'id' => 'wpNewPassword',
55 - 'required' => '',
56 - ),
57 - 'Retype' => array(
58 - 'type' => 'password',
59 - 'label-message' => 'retypenew',
60 - 'size' => '20',
61 - 'id' => 'wpRetype',
62 - 'required' => '',
63 - ),
64 - 'Remember' => array(
65 - 'type' => 'check',
66 - 'id' => 'wpRemember',
67 - ),
68 - );
69 -
70 - protected $mUsername;
71 - protected $mLogin;
72 -
7331 public function __construct() {
74 - global $wgRequest, $wgUser, $wgLang, $wgCookieExpiration;
75 -
7632 parent::__construct( 'Resetpass' );
77 - $this->mFormFields['Retype']['validation-callback'] = array( 'SpecialCreateAccount', 'formValidateRetype' );
78 -
79 - $this->mUsername = $wgRequest->getVal( 'wpName', $wgUser->getName() );
80 - $this->mReturnTo = $wgRequest->getVal( 'returnto' );
81 - $this->mReturnToQuery = $wgRequest->getVal( 'returntoquery' );
82 -
83 - $this->mFormFields['Remember']['label'] = wfMsgExt(
84 - 'remembermypassword',
85 - 'parseinline',
86 - $wgLang->formatNum( ceil( $wgCookieExpiration / 86400 ) )
87 - );
8833 }
8934
9035 /**
9136 * Main execution point
9237 */
93 - public function execute( $par ) {
 38+ function execute( $par ) {
9439 global $wgUser, $wgAuth, $wgOut, $wgRequest;
9540
9641 if ( wfReadOnly() ) {
@@ -97,134 +42,196 @@
9843 return;
9944 }
10045
 46+ $this->mUserName = $wgRequest->getVal( 'wpName' );
 47+ $this->mOldpass = $wgRequest->getVal( 'wpPassword' );
 48+ $this->mNewpass = $wgRequest->getVal( 'wpNewPassword' );
 49+ $this->mRetype = $wgRequest->getVal( 'wpRetype' );
 50+ $this->mDomain = $wgRequest->getVal( 'wpDomain' );
 51+
10152 $this->setHeaders();
10253 $this->outputHeader();
10354 $wgOut->disallowUserJs();
10455
105 - if( wfReadOnly() ){
106 - $wgOut->readOnlyPage();
107 - return false;
 56+ if( !$wgRequest->wasPosted() && !$wgUser->isLoggedIn() ) {
 57+ $this->error( wfMsg( 'resetpass-no-info' ) );
 58+ return;
10859 }
109 - if( !$wgAuth->allowPasswordChange() ) {
110 - $wgOut->showErrorPage( 'errorpagetitle', 'resetpass_forbidden' );
111 - return false;
112 - }
11360
114 - if( !$wgRequest->wasPosted() && !$wgUser->isLoggedIn() ) {
115 - $wgOut->showErrorPage( 'errorpagetitle', 'resetpass-no-info' );
116 - return false;
 61+ if( $wgRequest->wasPosted() && $wgRequest->getBool( 'wpCancel' ) ) {
 62+ $this->doReturnTo();
 63+ return;
11764 }
11865
119 - $this->getForm()->show();
 66+ if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
 67+ try {
 68+ $wgAuth->setDomain( $this->mDomain );
 69+ if( !$wgAuth->allowPasswordChange() ) {
 70+ $this->error( wfMsg( 'resetpass_forbidden' ) );
 71+ return;
 72+ }
12073
121 - }
122 -
123 - public function formSubmitCallback( $data ){
124 - $data['Password'] = $data['OldPassword'];
125 - $this->mLogin = new Login( $data );
126 - $result = $this->attemptReset( $data );
127 -
128 - if( $result === true ){
129 - # Log the user in if they're not already (ie we're
130 - # coming from the e-mail-password-reset route
131 - global $wgUser;
132 - if( !$wgUser->isLoggedIn() ) {
133 - $this->mLogin->attemptLogin( $data['NewPassword'] );
134 - # Redirect out to the appropriate target.
135 - SpecialUserlogin::successfulLogin(
136 - 'resetpass_success',
137 - $this->mReturnTo,
138 - $this->mReturnToQuery,
139 - $this->mLogin->mLoginResult
140 - );
141 - } else {
142 - # Redirect out to the appropriate target.
143 - SpecialUserlogin::successfulLogin(
144 - 'resetpass_success',
145 - $this->mReturnTo,
146 - $this->mReturnToQuery
147 - );
 74+ $this->attemptReset( $this->mNewpass, $this->mRetype );
 75+ $wgOut->addWikiMsg( 'resetpass_success' );
 76+ if( !$wgUser->isLoggedIn() ) {
 77+ LoginForm::setLoginToken();
 78+ $token = LoginForm::getLoginToken();
 79+ $data = array(
 80+ 'action' => 'submitlogin',
 81+ 'wpName' => $this->mUserName,
 82+ 'wpDomain' => $this->mDomain,
 83+ 'wpLoginToken' => $token,
 84+ 'wpPassword' => $this->mNewpass,
 85+ 'returnto' => $wgRequest->getVal( 'returnto' ),
 86+ );
 87+ if( $wgRequest->getCheck( 'wpRemember' ) ) {
 88+ $data['wpRemember'] = 1;
 89+ }
 90+ $login = new LoginForm( new FauxRequest( $data, true ) );
 91+ $login->execute( null );
 92+ }
 93+ $this->doReturnTo();
 94+ } catch( PasswordError $e ) {
 95+ $this->error( $e->getMessage() );
14896 }
149 - return true;
150 - } else {
151 - return $result;
15297 }
 98+ $this->showForm();
15399 }
 100+
 101+ function doReturnTo() {
 102+ global $wgRequest, $wgOut;
 103+ $titleObj = Title::newFromText( $wgRequest->getVal( 'returnto' ) );
 104+ if ( !$titleObj instanceof Title ) {
 105+ $titleObj = Title::newMainPage();
 106+ }
 107+ $wgOut->redirect( $titleObj->getFullURL() );
 108+ }
154109
155 - public function getForm( $reset=false ) {
156 - global $wgOut, $wgUser, $wgRequest;
 110+ function error( $msg ) {
 111+ global $wgOut;
 112+ $wgOut->addHTML( Xml::element('p', array( 'class' => 'error' ), $msg ) );
 113+ }
157114
158 - if( $reset || $wgRequest->getCheck( 'reset' ) ){
159 - # Request is coming from Special:UserLogin after it
160 - # authenticated someone with a temporary password.
161 - $this->mFormFields['OldPassword']['label-message'] = 'resetpass-temp-password';
 115+ function showForm() {
 116+ global $wgOut, $wgUser, $wgRequest, $wgLivePasswordStrengthChecks;
 117+
 118+ if ( $wgLivePasswordStrengthChecks ) {
 119+ $wgOut->addPasswordSecurity( 'wpNewPassword', 'wpRetype' );
 120+ }
 121+ $self = $this->getTitle();
 122+ if ( !$this->mUserName ) {
 123+ $this->mUserName = $wgUser->getName();
 124+ }
 125+ $rememberMe = '';
 126+ if ( !$wgUser->isLoggedIn() ) {
 127+ global $wgCookieExpiration, $wgLang;
 128+ $rememberMe = '<tr>' .
 129+ '<td></td>' .
 130+ '<td class="mw-input">' .
 131+ Xml::checkLabel(
 132+ wfMsgExt( 'remembermypassword', 'parsemag', $wgLang->formatNum( ceil( $wgCookieExpiration / ( 3600 * 24 ) ) ) ),
 133+ 'wpRemember', 'wpRemember',
 134+ $wgRequest->getCheck( 'wpRemember' ) ) .
 135+ '</td>' .
 136+ '</tr>';
162137 $submitMsg = 'resetpass_submit';
163 - $this->mFormFields['OldPassword']['default'] = $wgRequest->getText( 'wpPassword' );
164 - #perpetuate
165 - $this->mFormFields['reset'] = array(
166 - 'type' => 'hidden',
167 - 'default' => '1',
168 - );
 138+ $oldpassMsg = 'resetpass-temp-password';
169139 } else {
170 - unset( $this->mFormFields['Remember'] );
 140+ $oldpassMsg = 'oldpassword';
171141 $submitMsg = 'resetpass-submit-loggedin';
172142 }
 143+ $wgOut->addHTML(
 144+ Xml::fieldset( wfMsg( 'resetpass_header' ) ) .
 145+ Xml::openElement( 'form',
 146+ array(
 147+ 'method' => 'post',
 148+ 'action' => $self->getLocalUrl(),
 149+ 'id' => 'mw-resetpass-form' ) ) . "\n" .
 150+ Html::hidden( 'token', $wgUser->editToken() ) . "\n" .
 151+ Html::hidden( 'wpName', $this->mUserName ) . "\n" .
 152+ Html::hidden( 'wpDomain', $this->mDomain ) . "\n" .
 153+ Html::hidden( 'returnto', $wgRequest->getVal( 'returnto' ) ) . "\n" .
 154+ wfMsgExt( 'resetpass_text', array( 'parse' ) ) . "\n" .
 155+ Xml::openElement( 'table', array( 'id' => 'mw-resetpass-table' ) ) . "\n" .
 156+ $this->pretty( array(
 157+ array( 'wpName', 'username', 'text', $this->mUserName, '' ),
 158+ array( 'wpPassword', $oldpassMsg, 'password', $this->mOldpass, '' ),
 159+ array( 'wpNewPassword', 'newpassword', 'password', null, '<div id="password-strength"></div>' ),
 160+ array( 'wpRetype', 'retypenew', 'password', null, '<div id="password-retype"></div>' ),
 161+ ) ) . "\n" .
 162+ $rememberMe .
 163+ "<tr>\n" .
 164+ "<td></td>\n" .
 165+ '<td class="mw-input">' .
 166+ Xml::submitButton( wfMsg( $submitMsg ) ) .
 167+ Xml::submitButton( wfMsg( 'resetpass-submit-cancel' ), array( 'name' => 'wpCancel' ) ) .
 168+ "</td>\n" .
 169+ "</tr>\n" .
 170+ Xml::closeElement( 'table' ) .
 171+ Xml::closeElement( 'form' ) .
 172+ Xml::closeElement( 'fieldset' ) . "\n"
 173+ );
 174+ }
173175
174 - $this->mFormFields['Name']['default'] =
175 - $this->mFormFields['NameInfo']['default'] = $this->mUsername;
176 -
177 - $form = new HTMLForm( $this->mFormFields, '' );
178 - $form->suppressReset();
179 - $form->setSubmitText( wfMsg( $submitMsg ) );
180 - $form->setTitle( $this->getTitle() );
181 - $form->addHiddenField( 'returnto', $this->mReturnTo );
182 - $form->setWrapperLegend( wfMsg( 'resetpass_header' ) );
183 -
184 - $form->setSubmitCallback( array( $this, 'formSubmitCallback' ) );
185 - $form->loadData();
186 -
187 - return $form;
 176+ function pretty( $fields ) {
 177+ $out = '';
 178+ foreach ( $fields as $list ) {
 179+ list( $name, $label, $type, $value, $extra ) = $list;
 180+ if( $type == 'text' ) {
 181+ $field = htmlspecialchars( $value );
 182+ } else {
 183+ $attribs = array( 'id' => $name );
 184+ if ( $name == 'wpNewPassword' || $name == 'wpRetype' ) {
 185+ $attribs = array_merge( $attribs,
 186+ User::passwordChangeInputAttribs() );
 187+ }
 188+ if ( $name == 'wpPassword' ) {
 189+ $attribs[] = 'autofocus';
 190+ }
 191+ $field = Html::input( $name, $value, $type, $attribs );
 192+ }
 193+ $out .= "<tr>\n";
 194+ $out .= "\t<td class='mw-label'>";
 195+ if ( $type != 'text' )
 196+ $out .= Xml::label( wfMsg( $label ), $name );
 197+ else
 198+ $out .= wfMsgHtml( $label );
 199+ $out .= "</td>\n";
 200+ $out .= "\t<td class='mw-input'>$field</td>\n";
 201+ $out .= "\t<td>$extra</td>\n";
 202+ $out .= "</tr>";
 203+ }
 204+ return $out;
188205 }
189206
190207 /**
191 - * Try to reset the user's password
 208+ * @throws PasswordError when cannot set the new password because requirements not met.
192209 */
193 - protected function attemptReset( $data ) {
194 -
195 - if( !$data['Name']
196 - || !$data['OldPassword']
197 - || !$data['NewPassword']
198 - || !$data['Retype'] )
199 - {
200 - return false;
 210+ protected function attemptReset( $newpass, $retype ) {
 211+ $user = User::newFromName( $this->mUserName );
 212+ if( !$user || $user->isAnon() ) {
 213+ throw new PasswordError( 'no such user' );
201214 }
202 -
203 - $user = $this->mLogin->getUser();
204 - if( !( $user instanceof User ) ){
205 - return wfMsgExt( 'nosuchuser', 'parse' );
 215+
 216+ if( $newpass !== $retype ) {
 217+ wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'badretype' ) );
 218+ throw new PasswordError( wfMsg( 'badretype' ) );
206219 }
207220
208 - if( $data['NewPassword'] !== $data['Retype'] ) {
209 - wfRunHooks( 'PrefsPasswordAudit', array( $user, $data['NewPassword'], 'badretype' ) );
210 - return wfMsgExt( 'badretype', 'parse' );
 221+ if( !$user->checkTemporaryPassword($this->mOldpass) && !$user->checkPassword($this->mOldpass) ) {
 222+ wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'wrongpassword' ) );
 223+ throw new PasswordError( wfMsg( 'resetpass-wrong-oldpass' ) );
211224 }
212 -
213 - if( !$user->checkPassword( $data['OldPassword'] ) && !$user->checkTemporaryPassword( $data['OldPassword'] ) )
214 - {
215 - wfRunHooks( 'PrefsPasswordAudit', array( $user, $data['NewPassword'], 'wrongpassword' ) );
216 - return wfMsgExt( 'resetpass-wrong-oldpass', 'parse' );
217 - }
218 -
 225+
219226 try {
220 - $user->setPassword( $data['NewPassword'] );
221 - wfRunHooks( 'PrefsPasswordAudit', array( $user, $data['NewPassword'], 'success' ) );
 227+ $user->setPassword( $this->mNewpass );
 228+ wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'success' ) );
 229+ $this->mNewpass = $this->mOldpass = $this->mRetypePass = '';
222230 } catch( PasswordError $e ) {
223 - wfRunHooks( 'PrefsPasswordAudit', array( $user, $data['NewPassword'], 'error' ) );
224 - return $e->getMessage();
 231+ wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'error' ) );
 232+ throw new PasswordError( $e->getMessage() );
225233 }
226 -
 234+
227235 $user->setCookies();
228236 $user->saveSettings();
229 - return true;
230237 }
231238 }
Index: trunk/phase3/includes/Skin.php
@@ -546,7 +546,7 @@
547547 * @private
548548 */
549549 function setupUserCss( OutputPage $out ) {
550 - global $wgRequest, $wgUser;
 550+ global $wgRequest;
551551 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
552552
553553 wfProfileIn( __METHOD__ );
@@ -560,9 +560,6 @@
561561 // Per-site custom styles
562562 if ( $wgUseSiteCss ) {
563563 $out->addModuleStyles( 'site' );
564 - if( $wgUser->isLoggedIn() ){
565 - $out->addModuleStyles( 'user.groups' );
566 - }
567564 }
568565
569566 // Per-user custom styles
Index: trunk/phase3/RELEASE-NOTES
@@ -72,8 +72,6 @@
7373 (maintenance/fixDoubleRedirects.php)
7474 * (bug 23315) New body classes to allow easier styling of special pages
7575 * (bug 27159) Make email confirmation code expiration time configurable
76 -* CSS/JS for each user group is imported from MediaWiki:Sysop.js,
77 - MediaWiki:Autoconfirmed.css, etc.
7876
7977 === Bug fixes in 1.18 ===
8078 * (bug 23119) WikiError class and subclasses are now marked as deprecated
Index: trunk/phase3/resources/Resources.php
@@ -8,7 +8,6 @@
99 'startup' => array( 'class' => 'ResourceLoaderStartUpModule' ),
1010 'user' => array( 'class' => 'ResourceLoaderUserModule' ),
1111 'user.options' => array( 'class' => 'ResourceLoaderUserOptionsModule' ),
12 - 'user.groups' => array( 'class' => 'ResourceLoaderUserGroupsModule' ),
1312
1413 /* Skins */
1514

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r82283Create a user.groups module in ResourceLoader, which bundles a CSS and JS pag...happy-melon19:49, 16 February 2011

Status & tagging log