more ajaxCategories fixes based on review in r93351 CR
authorKrinkle <krinkle@users.mediawiki.org>
Fri, 12 Aug 2011 11:35:50 +0000 (11:35 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Fri, 12 Aug 2011 11:35:50 +0000 (11:35 +0000)
* 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

languages/messages/MessagesEn.php
maintenance/language/messages.inc
resources/Resources.php
resources/mediawiki.page/mediawiki.page.ajaxCategories.js

index a0cc914..57903bf 100644 (file)
@@ -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.',
 
 );
index 8e26187..561a99a 100644 (file)
@@ -3498,6 +3498,7 @@ $wgMessageStructure = array(
                'ajax-category-already-present',
                'ajax-category-hook-error',
                'ajax-api-error',
+               'ajax-api-unknown-error',
        ),
 
 );
index a07331f..693cc66 100644 (file)
@@ -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(
index 986aaa4..71f3ec5 100644 (file)
@@ -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 = $( '<p>' )
-                       .html( '<strong>' + mw.msg( 'ajax-category-question' ) + '</strong><br/>' + props.dialogDescription );
+                       .html( '<strong>' + mw.message( 'ajax-category-question' ).escaped() + '</strong><br/>' + props.dialogDescription );
 
                // Reason textbox.
                reasonBox = $( '<input type="text" size="45"></input>' )