r89032 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89031‎ | r89032 | r89033 >
Date:11:22, 28 May 2011
Author:janpaul123
Status:resolved
Tags:
Comment:
Some more fixes:
* Optimisations per http://www.mediawiki.org/wiki/User:Krinkle/Extension_review/WikiLove (used .toggle for even cleaner code)
* Fixed bug when leaving WikiLove at User:SomeUser/subpage, now it actually delivers on User talk:SomeUser instead of User talk:SomeUser/subpage, and the username is substituted for $7, instead of the page name which includes the subpath.
* Fixed bug in the API which triggered an error when not entering a message although this is allowed client-side.
* Fixed some more leftovers of r89030
Modified paths:
  • /trunk/extensions/WikiLove/WikiLove.api.php (modified) (history)
  • /trunk/extensions/WikiLove/WikiLove.hooks.php (modified) (history)
  • /trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiLove/WikiLove.hooks.php
@@ -56,6 +56,11 @@
5757 if ( !is_null( $title ) ) {
5858 $out->addModules( 'ext.wikiLove.icon' );
5959 $out->addModules( 'ext.wikiLove.init' );
 60+ $out->addInlineScript(
 61+ 'jQuery( document ).ready( function() {
 62+ jQuery.wikiLove.setUsername( ' . FormatJson::encode( $title->getText() ) . ' );
 63+ } );'
 64+ );
6065 }
6166 return true;
6267 }
@@ -130,10 +135,15 @@
131136 }
132137
133138 $ns = $title->getNamespace();
134 - if ( $ns == NS_USER_TALK && $title->quickUserCan( 'edit' ) ) {
135 - return $title;
 139+ // return quickly if we're in the wrong namespace anyway
 140+ if ( $ns != NS_USER && $ns != NS_USER_TALK ) return null;
 141+
 142+ $baseTitle = Title::newFromText( $title->getBaseText(), $ns );
 143+
 144+ if ( $ns == NS_USER_TALK && $baseTitle->quickUserCan( 'edit' ) ) {
 145+ return $baseTitle;
136146 } elseif ( $ns == NS_USER ) {
137 - $talk = $title->getTalkPage();
 147+ $talk = $baseTitle->getTalkPage();
138148 if ( $talk->quickUserCan( 'edit' ) ) {
139149 return $talk;
140150 }
Index: trunk/extensions/WikiLove/WikiLove.api.php
@@ -98,7 +98,6 @@
9999 ),
100100 'message' => array(
101101 ApiBase::PARAM_TYPE => 'string',
102 - ApiBase::PARAM_REQUIRED => true,
103102 ),
104103 'token' => array(
105104 ApiBase::PARAM_TYPE => 'string',
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
@@ -8,7 +8,8 @@
99 currentTypeOrSubtype = null, // content of the current (sub)type (i.e. an object with title, descr, text, etc.)
1010 previewData = null, // data of the currently previewed thing is set here
1111 emailable = false,
12 - gallery = {};
 12+ gallery = {},
 13+ username = '';
1314
1415 return {
1516 optionsHook: function() { return {}; }, // hook that can be overridden by the user to modify options
@@ -138,7 +139,7 @@
139140 currentTypeId = newTypeId;
140141 currentSubtypeId = null; // reset the subtype id
141142
142 - $( '#mw-wikilove-types a' ).removeClass( 'selected' );
 143+ $( '#mw-wikilove-types' ).find( 'a' ).removeClass( 'selected' );
143144 $( this ).addClass( 'selected' ); // highlight the new type in the menu
144145
145146 if( typeof options.types[currentTypeId].subtypes == 'object' ) {
@@ -207,51 +208,34 @@
208209 }
209210
210211 // show or hide header label and textbox depending on whether a predefined header exists
211 - if( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 ) {
212 - $( '#mw-wikilove-header-label').show();
213 - $( '#mw-wikilove-header' ).show();
214 - } else {
215 - $( '#mw-wikilove-header-label').hide();
216 - $( '#mw-wikilove-header' ).hide();
217 - }
 212+ $( '#mw-wikilove-header, #mw-wikilove-header-label' )
 213+ .toggle( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 );
 214+
 215+ // set the new text for the header textbox
218216 $( '#mw-wikilove-header' ).val( currentTypeOrSubtype.header || '' );
219217
220218 // show or hide title label and textbox depending on whether a predefined title exists
221 - if( $.inArray( 'title', currentTypeOrSubtype.fields ) >= 0 ) {
222 - $( '#mw-wikilove-title-label').show();
223 - $( '#mw-wikilove-title' ).show();
224 - } else {
225 - $( '#mw-wikilove-title-label').hide();
226 - $( '#mw-wikilove-title' ).hide();
227 - }
 219+ $( '#mw-wikilove-title, #mw-wikilove-title-label')
 220+ .toggle( $.inArray( 'title', currentTypeOrSubtype.fields ) >= 0 );
 221+
 222+ // set the new text for the title textbox
228223 $( '#mw-wikilove-title' ).val( currentTypeOrSubtype.title || '' );
229224
230225 // show or hide image label and textbox depending on whether a predefined image exists
231 - if( $.inArray( 'image', currentTypeOrSubtype.fields ) >= 0 ) {
232 - $( '#mw-wikilove-image-label').show();
233 - $( '#mw-wikilove-image' ).show();
234 - } else {
235 - $( '#mw-wikilove-image-label').hide();
236 - $( '#mw-wikilove-image' ).hide();
237 - }
 226+ $( '#mw-wikilove-image, #mw-wikilove-image-label')
 227+ .toggle( $.inArray( 'image', currentTypeOrSubtype.fields ) >= 0 );
 228+
 229+ // set the new text for the image textbox
238230 $( '#mw-wikilove-image' ).val( currentTypeOrSubtype.image || '' );
239231
240 - if( typeof currentTypeOrSubtype.gallery == 'object' ) {
241 - if( currentTypeOrSubtype.gallery.imageList instanceof Array) {
242 - $( '#mw-wikilove-gallery-label' ).show();
243 - $( '#mw-wikilove-gallery' ).show();
244 - $.wikiLove.showGallery(); // build gallery from array of images
245 - } else {
246 - // gallery is a category
247 - // not supported right now
248 - $( '#mw-wikilove-gallery-label' ).hide();
249 - $( '#mw-wikilove-gallery' ).hide();
250 - //$.wikiLove.makeGallery(); // build gallery from category
251 - }
 232+ if( typeof currentTypeOrSubtype.gallery == 'object'
 233+ && currentTypeOrSubtype.gallery.imageList instanceof Array
 234+ ) {
 235+ $( '#mw-wikilove-gallery, #mw-wikilove-gallery-label' ).show();
 236+ $.wikiLove.showGallery(); // build gallery from array of images
252237 }
253238 else {
254 - $( '#mw-wikilove-gallery-label' ).hide();
255 - $( '#mw-wikilove-gallery' ).hide();
 239+ $( '#mw-wikilove-gallery, #mw-wikilove-gallery-label' ).hide();
256240 }
257241
258242 if( $.inArray( 'notify', currentTypeOrSubtype.fields ) >= 0 && emailable ) {
@@ -298,14 +282,14 @@
299283 $.wikiLove.showError( 'wikilove-err-sig' ); return false;
300284 }
301285
302 - var text = prepareMsg(
 286+ var text = $.wikiLove.prepareMsg(
303287 currentTypeOrSubtype.text || options.defaultText,
304288 currentTypeOrSubtype.imageSize,
305289 currentTypeOrSubtype.backgroundColor,
306290 currentTypeOrSubtype.borderColor
307291 );
308292
309 - doPreview( '==' + $( '#mw-wikilove-header' ).val() + "==\n" + text );
 293+ $.wikiLove.doPreview( '==' + $( '#mw-wikilove-header' ).val() + "==\n" + text );
310294 previewData = {
311295 'header': $( '#mw-wikilove-header' ).val(),
312296 'text': text,
@@ -315,7 +299,7 @@
316300 };
317301
318302 if ( $( '#mw-wikilove-notify-checkbox:checked' ).val() && emailable ) {
319 - previewData.email = prepareMsg( currentTypeOrSubtype.email );
 303+ previewData.email = $.wikiLove.prepareMsg( currentTypeOrSubtype.email );
320304 }
321305 },
322306
@@ -347,7 +331,7 @@
348332 msg = msg.replace( '$5', myBackgroundColor ); // replace the background color
349333 msg = msg.replace( '$6', myBorderColor ); // replace the border color
350334
351 - msg = msg.replace( '$7', wgTitle ); // replace the username we're sending to
 335+ msg = msg.replace( '$7', username ); // replace the username we're sending to
352336
353337 return msg;
354338 },
@@ -358,7 +342,7 @@
359343 doPreview: function( wikitext ) {
360344 $( '#mw-wikilove-preview-spinner' ).fadeIn( 200 );
361345 $.ajax({
362 - url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php?',
 346+ url: mw.util.wikiScript( 'api' ),
363347 data: {
364348 'action': 'parse',
365349 'format': 'json',
@@ -416,7 +400,7 @@
417401 }
418402
419403 $.ajax({
420 - url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php?',
 404+ url: mw.util.wikiScript( 'api' ),
421405 data: sendData,
422406 dataType: 'json',
423407 type: 'POST',
@@ -472,7 +456,7 @@
473457
474458 var index = 0;
475459 $.ajax({
476 - url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php',
 460+ url: mw.util.wikiScript( 'api' ),
477461 data: {
478462 'action' : 'query',
479463 'format' : 'json',
@@ -517,14 +501,21 @@
518502 },
519503
520504 /*
521 - * Init function which is called upon page load. Binds the WikiLove icon to opening the dialog.
522 - */
 505+ * Init function which is called upon page load. Binds the WikiLove icon to opening the dialog.
 506+ */
523507 init: function() {
524508 options = $.wikiLove.optionsHook();
525 - $( '#ca-wikilove a' ).click( function( e ) {
 509+ $( '#ca-wikilove' ).find( 'a' ).click( function( e ) {
526510 $.wikiLove.openDialog();
527511 e.preventDefault();
528512 });
 513+ },
 514+
 515+ /*
 516+ * Public function to set the username by finding the base title server-side.
 517+ */
 518+ setUsername: function( name ) {
 519+ username = name;
529520 }
530521
531522 /*
@@ -544,7 +535,7 @@
545536 $( '#mw-wikilove-gallery-spinner' ).fadeIn( 200 );
546537
547538 $.ajax({
548 - url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php',
 539+ url: mw.util.wikiScript( 'api' ),
549540 data: {
550541 'action' : 'query',
551542 'format' : 'json',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89030Restructured the core file per http://www.mediawiki.org/wiki/User:Krinkle/Ext...janpaul12310:49, 28 May 2011

Status & tagging log