r56044 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56043‎ | r56044 | r56045 >
Date:16:27, 8 September 2009
Author:ashley
Status:deferred
Tags:
Comment:
AjaxLogin: more cleanup
Modified paths:
  • /trunk/extensions/AjaxLogin/AjaxLogin.css (modified) (history)
  • /trunk/extensions/AjaxLogin/AjaxLogin.js (modified) (history)
  • /trunk/extensions/AjaxLogin/AjaxLogin.php (modified) (history)
  • /trunk/extensions/AjaxLogin/ApiAjaxLogin.php (modified) (history)
  • /trunk/extensions/AjaxLogin/README (modified) (history)

Diff [purge]

Index: trunk/extensions/AjaxLogin/AjaxLogin.php
@@ -28,7 +28,8 @@
2929 // Array of skins for which AjaxLogin is enabled.
3030 // Key is: 'skinname' => (true or false)
3131 $wgEnableAjaxLogin = array(
32 - 'monobook' => true
 32+ 'monobook' => true,
 33+ 'vector' => true
3334 );
3435
3536 // Autoload AjaxLogin API interface
@@ -51,16 +52,15 @@
5253 * @return true
5354 */
5455 function AjaxLoginJS( OutputPage $out ) {
55 - global $wgEnableAjaxLogin, $wgScriptPath, $wgJsMimeType;
 56+ global $wgEnableAjaxLogin, $wgScriptPath;
5657
5758 # Don't load anything if AjaxLogin isn't enabled
5859 if ( !isset( $wgEnableAjaxLogin ) ) {
5960 return true;
6061 }
6162
62 -
6363 // Our custom CSS
64 - $out->addStyle( '../..' . $wgScriptPath . '/extensions/AjaxLogin/AjaxLogin.css' );
 64+ $out->addExtensionStyle( $wgScriptPath . '/extensions/AjaxLogin/AjaxLogin.css' );
6565 // JQuery and JQModal scripts
6666 $out->addScriptFile( $wgScriptPath . '/extensions/AjaxLogin/jquery-1.3.2.min.js' );
6767 $out->addScriptFile( $wgScriptPath . '/extensions/AjaxLogin/jqModal.js' );
@@ -105,7 +105,7 @@
106106 <b class="xtop"><b class="xb1"></b><b class="xb2"></b><b class="xb3"></b><b class="xb4"></b></b>
107107 <div class="r_boxContent">
108108 <div>
109 - <div name="wpClose" id="wpClose" value="' . wfMsg( 'close' ) . '" style ="float:right;cursor:pointer;"><a href="#" tabindex="108"><font size="4" color="white"><b>X</b></font></a>
 109+ <div name="wpClose" id="wpClose" value="' . wfMsg( 'close' ) . '" style ="float:right;cursor:pointer;"><a href="#" tabindex="108"><font size="4" color="white"><b>X</b></font></a>
110110 </div>
111111 <div class="boxHeader color1">
112112 ' . wfMsg( 'login' ) . '
@@ -136,4 +136,4 @@
137137 </div>' );
138138 }
139139 return true;
140 -}
 140+}
\ No newline at end of file
Index: trunk/extensions/AjaxLogin/AjaxLogin.css
@@ -12,7 +12,6 @@
1313 #userloginRound .boxHeader {
1414 padding: 3px 5px;
1515 font-size: 12px; /* Jack: added this */
16 -
1716 }
1817
1918 #userloginRound form {
@@ -32,26 +31,22 @@
3332
3433 .jqmWindow {
3534 display: none;
36 -
3735 position: fixed;
3836 top: 30%;
3937 left: 60%;
40 -
4138 margin-left: -300px;
42 -
4339 background-color: #EEE;
4440 color: #333;
4541 border: 1px solid black;
4642 }
4743
48 -
4944 .jqmOverlay { background-color: #000; }
5045
5146 /* Fixed posistioning emulation for IE6
5247 * Star selector used to hide definition from browsers other than IE6
53 - * For valid CSS, use a conditional include instead */
 48+ * For valid CSS, use a conditional include instead
 49+ */
5450 * html .jqmWindow {
5551 position: absolute;
5652 top: expression((document.documentElement.scrollTop || document.body.scrollTop) + Math.round(17 * (document.documentElement.offsetHeight || document.body.clientHeight) / 100) + 'px');
57 -}
58 -
 53+}
\ No newline at end of file
Index: trunk/extensions/AjaxLogin/AjaxLogin.js
@@ -1,4 +1,10 @@
2 -(function($) {
 2+/**
 3+ * JavaScript for AjaxLogin extension
 4+ * @file
 5+ * @author Chamindu Munasinghe <chamindu@calcey.com>
 6+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 7+ */
 8+(function( $ ) {
39 mediawiki = new Object;
410
511 mediawiki.AjaxLogin = function() {
@@ -9,26 +15,26 @@
1016 mediawiki.AjaxLogin.prototype.initialize = function() {
1117 this._loginPanel = $("#userloginRound");
1218 this._loginForm = $("#userajaxloginform");
13 - if(this._loginPanel.length > 0) {
 19+ if( this._loginPanel.length > 0 ) {
1420 this._loginPanel.jqm({modal : true, toTop : true});
1521 var that = this;
16 - $("#pt-anonlogin, #pt-login").click( function(event) {
 22+ $("#pt-anonlogin, #pt-login").click( function( event ) {
1723 event.preventDefault();
1824 that.showLoginPanel();
1925 });
20 - $("#wpLoginattempt").click(function(event) {
 26+ $("#wpLoginattempt").click(function( event ) {
2127 event.preventDefault();
22 - that.postAjax("wpLoginattempt");
 28+ that.postAjax( 'wpLoginattempt' );
2329 });
24 - $("#wpMailmypassword").click(function(event) {
 30+ $("#wpMailmypassword").click(function( event ) {
2531 event.preventDefault();
26 - that.postAjax("wpMailmypassword");
 32+ that.postAjax( 'wpMailmypassword' );
2733 });
28 - $("#wpAjaxRegister").click(function(event) {
29 - that.doRegister(event);
 34+ $("#wpAjaxRegister").click(function( event ) {
 35+ that.doRegister( event );
3036 });
31 - $("#wpClose").click(function(event) {
32 - that.doClose(event);
 37+ $("#wpClose").click(function( event ) {
 38+ that.doClose( event );
3339 });
3440 }
3541 };
@@ -38,93 +44,94 @@
3945 this._loginPanel.jqmShow();
4046 };
4147
42 -mediawiki.AjaxLogin.prototype.postAjax = function(action) {
 48+mediawiki.AjaxLogin.prototype.postAjax = function( action ) {
4349 var actionURL = wgServer + wgScriptPath + '/api.php?action=ajaxlogin&format=json';
4450 var dataString = this._loginForm.serialize();
45 - dataString += "&" + action + "=" + action;
 51+ dataString += '&' + action + '=' + action;
4652 this.disableForm();
4753 var that = this;
4854 $.ajax({
49 - type : "POST" ,
 55+ type : 'POST',
5056 url : actionURL,
51 - dataType : "json",
 57+ dataType : 'json',
5258 data : dataString,
53 - success : function(data) {
54 - that.requestSuccess(data);
 59+ success : function( data ) {
 60+ that.requestSuccess( data );
5561 },
56 - error : function(XMLHttpRequest, textStatus, errorThrown)
57 - {
 62+ error : function( XMLHttpRequest, textStatus, errorThrown ){
5863 //TODO : add error handling here
 64+ if( typeof console != 'undefined' ){
 65+ console_log( 'Error in AjaxLogin.js!' );
 66+ }
5967 }
6068 });
6169 };
6270
6371 mediawiki.AjaxLogin.prototype.enableForm = function() {
64 - $("#wpName1").removeAttr("disabled");
65 - $("#wpPassword1").removeAttr("disabled");
66 - $("#wpLoginattempt").removeAttr("disabled");
67 - $("#wpRemember").removeAttr("disabled");
68 - $("#wpMailmypassword").removeAttr("disabled");
69 - $("#wpPassword1").removeAttr("disabled");
70 - $("#wpClose").removeAttr("disabled");
 72+ $("#wpName1").removeAttr('disabled');
 73+ $("#wpPassword1").removeAttr('disabled');
 74+ $("#wpLoginattempt").removeAttr('disabled');
 75+ $("#wpRemember").removeAttr('disabled');
 76+ $("#wpMailmypassword").removeAttr('disabled');
 77+ $("#wpPassword1").removeAttr('disabled');
 78+ $("#wpClose").removeAttr('disabled');
7179 };
7280
7381 mediawiki.AjaxLogin.prototype.disableForm = function() {
74 - $("#wpName1").attr("disabled", "disabled");
75 - $("#wpPassword1").attr("disabled", "disabled");
76 - $("#wpLoginattempt").attr("disabled", "disabled");
77 - $("#wpRemember").attr("disabled", "disabled");
78 - $("#wpMailmypassword").attr("disabled", "disabled");
79 - $("#wpPassword1").attr("disabled", "disabled");
80 - $("#wpClose").attr("disabled", "disabled");
 82+ $("#wpName1").attr('disabled', 'disabled');
 83+ $("#wpPassword1").attr('disabled', 'disabled');
 84+ $("#wpLoginattempt").attr('disabled', 'disabled');
 85+ $("#wpRemember").attr('disabled', 'disabled');
 86+ $("#wpMailmypassword").attr('disabled', 'disabled');
 87+ $("#wpPassword1").attr('disabled', 'disabled');
 88+ $("#wpClose").attr('disabled', 'disabled');
8189 };
8290
83 -mediawiki.AjaxLogin.prototype.displayReason = function(reason) {
84 - $("#wpError").html(reason + "<br /><br />").show();
 91+mediawiki.AjaxLogin.prototype.displayReason = function( reason ) {
 92+ $("#wpError").html(reason + '<br /><br />').show();
8593 };
8694
87 -mediawiki.AjaxLogin.prototype.doRegister = function(event){
88 - if($("#wpPreview").length > 0 && $("#wpLogin").length > 0) {
89 - if( typeof(ajaxLogin2) != 'undefined' && !confirm(ajaxLogin2)) {
 95+mediawiki.AjaxLogin.prototype.doRegister = function( event ){
 96+ if( $("#wpPreview").length > 0 && $("#wpLogin").length > 0 ) {
 97+ if( typeof( ajaxLogin2 ) != 'undefined' && !confirm( ajaxLogin2 ) ) {
9098 event.preventDefault();
9199 }
92100 }
93101 };
94102
95103 mediawiki.AjaxLogin.prototype.refreshForm = function() {
96 - $("#wpName1").val("");
97 - $("#wpPassword1").val("");
98 - $("#wpError").html("");
 104+ $("#wpName1").val('');
 105+ $("#wpPassword1").val('');
 106+ $("#wpError").html('');
99107 this.enableForm();
100 -
101108 };
102109
103 -mediawiki.AjaxLogin.prototype.doClose = function(event){
 110+mediawiki.AjaxLogin.prototype.doClose = function( event ){
104111 this._loginPanel.jqmHide();
105112 };
106113
107 -mediawiki.AjaxLogin.prototype.requestSuccess = function(data) {
 114+mediawiki.AjaxLogin.prototype.requestSuccess = function( data ) {
108115 var responseResult = data.ajaxlogin.result;
109 - switch(responseResult) {
110 - case "Reset":
111 - if($("#wpPreview").length > 0 && $("#wpLogin").length > 0) {
112 - if(typeof(ajaxLogin1) != 'undefined' && !confirm(ajaxLogin1)) {
 116+ switch( responseResult ) {
 117+ case 'Reset':
 118+ if( $("#wpPreview").length > 0 && $("#wpLogin").length > 0 ) {
 119+ if( typeof( ajaxLogin1 ) != 'undefined' && !confirm( ajaxLogin1 ) ) {
113120 break;
114121 }
115122 }
116 - this._loginForm.attr("action", wgServer + wgScriptPath + "/index.php?title=Special:Userlogin&action=submitlogin&type=login");
117 - this._loginForm.unbind("submit");
 123+ this._loginForm.attr('action', wgServer + wgScriptPath + '/index.php?title=Special:Userlogin&action=submitlogin&type=login');
 124+ this._loginForm.unbind('submit');
118125 this.disableForm();
119126 this._loginForm.submit();
120127 this.enableForm();
121128 break;
122 - case "Success":
123 - if($("#wpPreview").length > 0 && $("#wpLogin").length > 0) {
124 - if($("#wikiDiff").length > 0 && ($("#wikiDiff").children.length > 0) ) {
 129+ case 'Success':
 130+ if( $("#wpPreview").length > 0 && $("#wpLogin").length > 0 ) {
 131+ if( $("#wikiDiff").length > 0 && ( $("#wikiDiff").children.length > 0 ) ) {
125132 $("#wpDiff").click();
126133 } else {
127134 if( $("#wikiPreview") && $("#wikiPreview").children.length == 0 ) {
128 - $("#wpLogin").val(1);
 135+ $("#wpLogin").val( 1 );
129136 }
130137 $("#wpPreview").click();
131138 }
@@ -132,32 +139,31 @@
133140 if( wgCanonicalSpecialPageName == 'Userlogout' ) {
134141 window.location.href = wgServer + wgScriptPath;
135142 } else {
136 - window.location.reload(true);
 143+ window.location.reload( true );
137144 }
138145 }
139146 break;
140 - case "NotExists":
 147+ case 'NotExists':
141148 this.enableForm();
142 - $("#wpName1").value = "";
143 - $("#wpPassword1").value = "";
 149+ $("#wpName1").value = '';
 150+ $("#wpPassword1").value = '';
144151 $("#wpName1").focus();
145 - case "WrongPass":
 152+ case 'WrongPass':
146153 this.enableForm();
147 - $("#wpPassword1").val("");
 154+ $("#wpPassword1").val('');
148155 $("#wpPassword1").focus();
149156 default:
150157 this.enableForm();
151 - this.displayReason(data.ajaxlogin.text);
 158+ this.displayReason( data.ajaxlogin.text );
152159 break;
153160 }
154161 };
155162
156163 $(document).ready( function() {
157 - if( typeof wgEnableAjaxLogin != 'undefined' && wgEnableAjaxLogin )
158 - {
 164+ if( typeof wgEnableAjaxLogin != 'undefined' && wgEnableAjaxLogin ) {
159165 var ajaxLogin = new mediawiki.AjaxLogin();
160166 ajaxLogin.initialize();
161167 }
162168 });
163169
164 -})(jQuery);
 170+})(jQuery);
\ No newline at end of file
Index: trunk/extensions/AjaxLogin/ApiAjaxLogin.php
@@ -94,10 +94,10 @@
9595 if ( !$wgAuth->allowPasswordChange() ) {
9696 $result['result'] = 'resetpass_forbidden';
9797 $result['text'] = wfMsg( 'resetpass_forbidden' );
98 - } else if ( $wgUser->isBlocked() ) {
 98+ } elseif ( $wgUser->isBlocked() ) {
9999 $result['result'] = 'blocked-mailpassword';
100100 $result['text'] = wfMsg( 'blocked-mailpassword' );
101 - } else if ( '' == $loginForm->mName ) {
 101+ } elseif ( '' == $loginForm->mName ) {
102102 $result['result'] = 'noname';
103103 $result['text'] = wfMsg( 'noname' );
104104 } else {
@@ -105,11 +105,11 @@
106106 if ( is_null( $u ) ) {
107107 $result['result'] = 'noname';
108108 $result['text'] = wfMsg( 'noname' );
109 - } else if ( 0 == $u->getID() ) {
 109+ } elseif ( 0 == $u->getID() ) {
110110 $result['result'] = 'nosuchuser';
111111 wfLoadExtensionMessages( 'AjaxLogin' );
112112 $result['text'] = wfMsg( 'al-nosuchuser', $u->getName() );
113 - } else if ( $u->isPasswordReminderThrottled() ) {
 113+ } elseif ( $u->isPasswordReminderThrottled() ) {
114114 global $wgPasswordReminderResendTime;
115115 $result['result'] = 'throttled-mailpassword';
116116 $result['text'] = wfMsg( 'throttled-mailpassword', round( $wgPasswordReminderResendTime, 3 ) );
@@ -145,4 +145,4 @@
146146 public function getVersion() {
147147 return __CLASS__ . ': $Id$';
148148 }
149 -}
 149+}
\ No newline at end of file
Index: trunk/extensions/AjaxLogin/README
@@ -7,15 +7,14 @@
88
99 Some code hacks were written by Jack Phoenix <jack@countervandalism.net>.
1010
11 -Replaced YUI with JQuery - Chamindu Munasinghe <chamindu@calcey.com>.
 11+Replaced YUI with jQuery - Chamindu Munasinghe <chamindu@calcey.com>.
1212
1313 ==License==
1414 GNU General Public License 2.0 or later
1515
1616 ==Dependency==
 17+jQuery
1718
18 -JQuery
19 -
2019 ==Manual modifications==
2120 You will need to modify one core MediaWiki file, includes/EditPage.php, if you want users to be able to log in with AjaxLogin
2221 on edit view (?action=edit) without losing their changes.
@@ -25,13 +24,7 @@
2625 <input type='hidden' value=\"\" name=\"wpLogin\" id=\"wpLogin\" />
2726
2827 ==To-do & bugs==
29 -This extension is right now a major hack. It requires YUI and isn't pretty in any case,
30 -but it works and has been tested on MediaWiki 1.14alpha.
31 -
32 -The JavaScript file should be rewritten so that the YUI dependency could be removed.
33 -Obviously YAHOOTools.js should also be killed in the process.
34 -
3528 Patches are more than welcome and they can be submitted either through Bugzilla <https://bugzilla.wikimedia.org> or emailed to me
3629 <jack@countervandalism.net> directly.
3730
\ No newline at end of file
 31+--Jack Phoenix, September 2009
\ No newline at end of file

Status & tagging log