r83276 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83275‎ | r83276 | r83277 >
Date:08:16, 5 March 2011
Author:skizzerz
Status:deferred
Tags:
Comment:
* update AjaxLogin extension to work with the new (as of 1.16) login api where a token is required
Modified paths:
  • /trunk/extensions/AjaxLogin/AjaxLogin.i18n.php (modified) (history)
  • /trunk/extensions/AjaxLogin/AjaxLogin.js (modified) (history)
  • /trunk/extensions/AjaxLogin/AjaxLogin.php (modified) (history)
  • /trunk/extensions/AjaxLogin/ApiAjaxLogin.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AjaxLogin/AjaxLogin.i18n.php
@@ -21,6 +21,8 @@
2222 'al-nosuchuser' => 'There is no user by the name "$1".
2323 User names are case sensitive.
2424 Check your spelling.',
 25+ 'al-createblocked' => 'Your IP address is blocked from account creation.',
 26+ 'al-throttled' => 'You have had too many recent password attempts. Please wait $1 {{PLURAL:$1|second|seconds}} before trying again.',
2527 );
2628
2729 /** Message documentation (Message documentation)
Index: trunk/extensions/AjaxLogin/AjaxLogin.php
@@ -4,9 +4,10 @@
55 *
66 * @file
77 * @ingroup Extensions
8 - * @version 2.1.0
 8+ * @version 2.2.0
99 * @author Inez Korczyński <korczynski(at)gmail(dot)com>
1010 * @author Jack Phoenix <jack@countervandalism.net>
 11+ * @author Ryan Schmidt <skizzerz@shoutwiki.com>
1112 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1213 */
1314
@@ -18,8 +19,8 @@
1920 $wgExtensionCredits['other'][] = array(
2021 'path' => __FILE__,
2122 'name' => 'AjaxLogin',
22 - 'version' => '2.1.0',
23 - 'author' => array( 'Inez Korczyński', 'Jack Phoenix' ),
 23+ 'version' => '2.2.0',
 24+ 'author' => array( 'Inez Korczyński', 'Jack Phoenix', 'Ryan Schmidt' ),
2425 'url' => 'http://www.mediawiki.org/wiki/Extension:AjaxLogin',
2526 'descriptionmsg' => 'ajaxlogin-desc',
2627 );
@@ -94,13 +95,16 @@
9596 * @param $data The data, AjaxLogin form in this case, to be added to the HTML output of a page
9697 * @return true
9798 */
98 -function GetAjaxLoginForm( &$data, $skin ) {
 99+function GetAjaxLoginForm( &$data, $skin = null ) {
99100 global $wgAuth, $wgEnableEmail, $wgOut, $wgUser;
100101 global $wgEnableAjaxLogin;
101 - if (
102 - isset( $wgEnableAjaxLogin ) && $wgUser->isAnon() &&
103 - $skin->getTitle()->getNamespace() != 8 && !$skin->getTitle()->isSpecial( 'Userlogin' )
104 - ) {
 102+ if( is_null( $skin ) ) {
 103+ global $wgTitle;
 104+ $userlogincheck = $wgTitle->getNamespace() != 8 && $wgTitle->getDBkey() != 'Userlogin';
 105+ } else {
 106+ $userlogincheck = $skin->getTitle()->getNamespace() != 8 && !$skin->getTitle()->isSpecial( 'Userlogin' );
 107+ }
 108+ if( isset( $wgEnableAjaxLogin ) && $wgUser->isAnon() && $userlogincheck ) {
105109 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
106110 $link = $titleObj->getLocalURL( 'type=signup' );
107111 $wgOut->addHTML( '<!--[if lt IE 9]><style type="text/css">#userloginRound { width: 350px !important; }</style><![endif]-->
Index: trunk/extensions/AjaxLogin/AjaxLogin.js
@@ -47,8 +47,8 @@
4848 mediawiki.AjaxLogin.prototype.postAjax = function( action ) {
4949 var actionURL = wgServer + wgScriptPath + '/api.php?action=ajaxlogin&format=json';
5050 var dataString = this._loginForm.serialize();
 51+ this.disableForm();
5152 dataString += '&' + action + '=' + action;
52 - this.disableForm();
5353 var that = this;
5454 $.ajax({
5555 type : 'POST',
@@ -56,7 +56,7 @@
5757 dataType : 'json',
5858 data : dataString,
5959 success : function( data ) {
60 - that.requestSuccess( data );
 60+ that.requestSuccess( data, dataString, actionURL );
6161 },
6262 error : function( XMLHttpRequest, textStatus, errorThrown ) {
6363 // TODO : add error handling here
@@ -110,7 +110,7 @@
111111 this._loginPanel.jqmHide();
112112 };
113113
114 -mediawiki.AjaxLogin.prototype.requestSuccess = function( data ) {
 114+mediawiki.AjaxLogin.prototype.requestSuccess = function( data, dataString, actionURL ) {
115115 var responseResult = data.ajaxlogin.result;
116116 switch( responseResult ) {
117117 case 'Reset':
@@ -143,6 +143,26 @@
144144 }
145145 }
146146 break;
 147+ case 'NeedToken':
 148+ case 'WrongToken':
 149+ // TODO: make it so this can't go in an infinite loop
 150+ var that = this;
 151+ $.ajax({
 152+ type : 'POST',
 153+ url : actionURL,
 154+ dataType : 'json',
 155+ data : dataString + '&wpToken=' + data.ajaxlogin.token,
 156+ success : function( data ) {
 157+ that.requestSuccess( data, dataString, actionURL );
 158+ },
 159+ error : function( XMLHttpRequest, textStatus, errorThrown ) {
 160+ // TODO : add error handling here
 161+ if( typeof console != 'undefined' ) {
 162+ console.log( 'Error in AjaxLogin.js!' );
 163+ }
 164+ }
 165+ });
 166+ break;
147167 case 'NotExists':
148168 this.enableForm();
149169 $('#wpName1').value = '';
Index: trunk/extensions/AjaxLogin/ApiAjaxLogin.php
@@ -18,7 +18,7 @@
1919
2020 public function execute() {
2121 session_start();
22 - $Name = $Password = $Remember = $Loginattempt = $Mailmypassword = null;
 22+ $Name = $Password = $Remember = $Loginattempt = $Mailmypassword = $Token = null;
2323 extract( $this->extractRequestParams() );
2424
2525 if ( !empty( $Loginattempt ) ) {
@@ -28,7 +28,8 @@
2929 'wpName' => $Name,
3030 'wpPassword' => $Password,
3131 'wpRemember' => $Remember,
32 - 'wpLoginattempt' => $Loginattempt
 32+ 'wpLoginattempt' => $Loginattempt,
 33+ 'wpLoginToken' => $Token,
3334 )
3435 );
3536
@@ -39,16 +40,27 @@
4041 $result['result'] = 'Reset';
4142 break;
4243 case LoginForm::SUCCESS:
43 - global $wgUser;
 44+ global $wgUser, $wgCookiePrefix;
4445
4546 $wgUser->setOption( 'rememberpassword', $Remember ? 1 : 0 );
4647 $wgUser->setCookies();
4748
4849 $result['result'] = 'Success';
49 - $result['lguserid'] = $_SESSION['wsUserID'];
50 - $result['lgusername'] = $_SESSION['wsUserName'];
51 - $result['lgtoken'] = $_SESSION['wsToken'];
 50+ $result['lguserid'] = intval( $wgUser->getId() );
 51+ $result['lgusername'] = $wgUser->getName();
 52+ $result['lgtoken'] = $wgUser->getToken();
 53+ $result['cookieprefix'] = $wgCookiePrefix;
 54+ $result['sessionid'] = session_id();
5255 break;
 56+ case LoginForm::NEED_TOKEN:
 57+ $result['result'] = 'NeedToken';
 58+ $result['token'] = $loginForm->getLoginToken();
 59+ $result['cookieprefix'] = $wgCookiePrefix;
 60+ $result['sessionid'] = session_id();
 61+ break;
 62+ case LoginForm::WRONG_TOKEN:
 63+ $result['result'] = 'WrongToken';
 64+ break;
5365 case LoginForm::NO_NAME:
5466 $result['result'] = 'NoName';
5567 $result['text'] = wfMsg( 'noname' );
@@ -65,6 +77,7 @@
6678 $result['result'] = 'NotExists';
6779 $result['text'] = wfMsg( 'al-nosuchuser', htmlspecialchars( $Name ) );
6880 break;
 81+ case LoginForm::RESET_PASS:
6982 case LoginForm::WRONG_PASS:
7083 $result['result'] = 'WrongPass';
7184 $result['text'] = wfMsg( 'wrongpassword' );
@@ -73,6 +86,18 @@
7487 $result['result'] = 'EmptyPass';
7588 $result['text'] = wfMsg( 'wrongpasswordempty' );
7689 break;
 90+ case LoginForm::CREATE_BLOCKED:
 91+ $result['result'] = 'CreateBlocked';
 92+ $result['text'] = wfMsg( 'al-createblocked' );
 93+ break;
 94+ case LoginForm::THROTTLED:
 95+ global $wgPasswordAttemptThrottle;
 96+ $result['result'] = 'Throttled';
 97+ $result['text'] = wfMsg( 'al-throttled', intval( $wgPasswordAttemptThrottle['seconds'] ) );
 98+ break;
 99+ case LoginForm::USER_BLOCKED:
 100+ $result['result'] = 'Blocked';
 101+ break;
77102 default:
78103 ApiBase::dieDebug( __METHOD__, 'Unhandled case value' );
79104 }
@@ -135,8 +160,8 @@
136161 'Password' => null,
137162 'Remember' => null,
138163 'Loginattempt' => null,
139 - 'Mailmypassword' => null
140 -
 164+ 'Mailmypassword' => null,
 165+ 'Token' => null
141166 );
142167 }
143168

Follow-up revisions

RevisionCommit summaryAuthorDate
r83307Follow-up r83276: PLURAL needs wfMsgExt with parameter 'parsemag'...raymond18:53, 5 March 2011

Status & tagging log