From: Krinkle Date: Fri, 12 Aug 2011 11:35:50 +0000 (+0000) Subject: more ajaxCategories fixes based on review in r93351 CR X-Git-Tag: 1.31.0-rc.0~28326 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=7d569319c7ead0ece68e92fcbb6a6b447ae64001;p=lhc%2Fweb%2Fwiklou.git more ajaxCategories fixes based on review in r93351 CR * Html-escaping unescaped message in summaryHolder * Check for errors in the API response * Pass true for existence of redirect origin and value of 'exists' for target (instead of backwards) * Comment fixes --- diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index a0cc9144d6..57903bfe66 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -4628,5 +4628,6 @@ This usually occurs when the category has been added to the page in a template.' 'ajax-category-already-present' => 'This page already belongs to the category "$1"', 'ajax-category-hook-error' => 'A local function prevented the changes from being saved.', 'ajax-api-error' => 'The API returned an error: $1: $2.', +'ajax-api-unknown-error' => 'The API returned an unknown error.', ); diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 8e2618764f..561a99adb2 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -3498,6 +3498,7 @@ $wgMessageStructure = array( 'ajax-category-already-present', 'ajax-category-hook-error', 'ajax-api-error', + 'ajax-api-unknown-error', ), ); diff --git a/resources/Resources.php b/resources/Resources.php index a07331f57c..693cc668fe 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -625,6 +625,7 @@ return array( 'ajax-category-already-present', 'ajax-category-hook-error', 'ajax-api-error', + 'ajax-api-unknown-error', ), ), 'mediawiki.page.ajaxCategories.init' => array( diff --git a/resources/mediawiki.page/mediawiki.page.ajaxCategories.js b/resources/mediawiki.page/mediawiki.page.ajaxCategories.js index 986aaa4131..71f3ec5879 100644 --- a/resources/mediawiki.page/mediawiki.page.ajaxCategories.js +++ b/resources/mediawiki.page/mediawiki.page.ajaxCategories.js @@ -664,14 +664,19 @@ mw.ajaxCategories.prototype = { var redirect = json.query.redirects, exists = !json.query.pages[-1]; - // Register existence - mw.Title.exist.set( catTitle.toString(), exists ); - + // If it's a redirect 'exists' is for the target, not the origin if ( redirect ) { - catTitle = new mw.Title( redirect[0].to ).getMainText(); - // Redirect existence as well (non-existant pages can't be redirects) + // Register existance of redirect origin as well, + // a non-existent page can't be a redirect. mw.Title.exist.set( catTitle.toString(), true ); + + // Override title with the redirect target + catTitle = new mw.Title( redirect[0].to ).getMainText(); } + + // Register existence + mw.Title.exist.set( catTitle.toString(), exists ); + callback( catTitle ); } ); }, @@ -824,7 +829,7 @@ mw.ajaxCategories.prototype = { $link.removeData(); - // Read static. + // Re-add data $link.data( { saveButton: data.saveButton, deleteButton: data.deleteButton, @@ -855,8 +860,17 @@ mw.ajaxCategories.prototype = { $.post( mw.util.wikiScript( 'api' ), getTokenVars, - function( reply ) { - var infos = reply.query.pages; + function( json ) { + if ( 'error' in json ) { + ajaxcat.showError( mw.msg( 'ajax-api-error', json.error.code, json.error.info ) ); + return; + } else if ( json.query && json.query.pages ) { + var infos = json.query.pages; + } else { + ajaxcat.showError( mw.msg( 'ajax-api-unknown-error' ) ); + return; + } + $.each( infos, function( pageid, data ) { var token = data.edittoken, timestamp = data.revisions[0].timestamp, @@ -910,8 +924,8 @@ mw.ajaxCategories.prototype = { * * @param props {Object}: * - modFn {Function} text-modifying function - * - dialogDescription {String} Changes done (HTML in the dialog) - * - editSummary {String} Changes done (text for edit summary) + * - dialogDescription {String} Changes done (HTML for in the dialog, escape before hand if needed) + * - editSummary {String} Changes done (text for the edit summary) * - doneFn {Function} callback after everything is done * - $link {jQuery} * - action @@ -952,7 +966,7 @@ mw.ajaxCategories.prototype = { // Summary of the action to be taken summaryHolder = $( '

' ) - .html( '' + mw.msg( 'ajax-category-question' ) + '
' + props.dialogDescription ); + .html( '' + mw.message( 'ajax-category-question' ).escaped() + '
' + props.dialogDescription ); // Reason textbox. reasonBox = $( '' )