r94338 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94337‎ | r94338 | r94339 >
Date:11:35, 12 August 2011
Author:krinkle
Status:ok
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki.page/mediawiki.page.ajaxCategories.js (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -3498,6 +3498,7 @@
34993499 'ajax-category-already-present',
35003500 'ajax-category-hook-error',
35013501 'ajax-api-error',
 3502+ 'ajax-api-unknown-error',
35023503 ),
35033504
35043505 );
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -4628,5 +4628,6 @@
46294629 'ajax-category-already-present' => 'This page already belongs to the category "$1"',
46304630 'ajax-category-hook-error' => 'A local function prevented the changes from being saved.',
46314631 'ajax-api-error' => 'The API returned an error: $1: $2.',
 4632+'ajax-api-unknown-error' => 'The API returned an unknown error.',
46324633
46334634 );
Index: trunk/phase3/resources/Resources.php
@@ -625,6 +625,7 @@
626626 'ajax-category-already-present',
627627 'ajax-category-hook-error',
628628 'ajax-api-error',
 629+ 'ajax-api-unknown-error',
629630 ),
630631 ),
631632 'mediawiki.page.ajaxCategories.init' => array(
Index: trunk/phase3/resources/mediawiki.page/mediawiki.page.ajaxCategories.js
@@ -664,14 +664,19 @@
665665 var redirect = json.query.redirects,
666666 exists = !json.query.pages[-1];
667667
 668+ // If it's a redirect 'exists' is for the target, not the origin
 669+ if ( redirect ) {
 670+ // Register existance of redirect origin as well,
 671+ // a non-existent page can't be a redirect.
 672+ mw.Title.exist.set( catTitle.toString(), true );
 673+
 674+ // Override title with the redirect target
 675+ catTitle = new mw.Title( redirect[0].to ).getMainText();
 676+ }
 677+
668678 // Register existence
669679 mw.Title.exist.set( catTitle.toString(), exists );
670680
671 - if ( redirect ) {
672 - catTitle = new mw.Title( redirect[0].to ).getMainText();
673 - // Redirect existence as well (non-existant pages can't be redirects)
674 - mw.Title.exist.set( catTitle.toString(), true );
675 - }
676681 callback( catTitle );
677682 } );
678683 },
@@ -824,7 +829,7 @@
825830
826831 $link.removeData();
827832
828 - // Read static.
 833+ // Re-add data
829834 $link.data( {
830835 saveButton: data.saveButton,
831836 deleteButton: data.deleteButton,
@@ -855,8 +860,17 @@
856861 $.post(
857862 mw.util.wikiScript( 'api' ),
858863 getTokenVars,
859 - function( reply ) {
860 - var infos = reply.query.pages;
 864+ function( json ) {
 865+ if ( 'error' in json ) {
 866+ ajaxcat.showError( mw.msg( 'ajax-api-error', json.error.code, json.error.info ) );
 867+ return;
 868+ } else if ( json.query && json.query.pages ) {
 869+ var infos = json.query.pages;
 870+ } else {
 871+ ajaxcat.showError( mw.msg( 'ajax-api-unknown-error' ) );
 872+ return;
 873+ }
 874+
861875 $.each( infos, function( pageid, data ) {
862876 var token = data.edittoken,
863877 timestamp = data.revisions[0].timestamp,
@@ -910,8 +924,8 @@
911925 *
912926 * @param props {Object}:
913927 * - modFn {Function} text-modifying function
914 - * - dialogDescription {String} Changes done (HTML in the dialog)
915 - * - editSummary {String} Changes done (text for edit summary)
 928+ * - dialogDescription {String} Changes done (HTML for in the dialog, escape before hand if needed)
 929+ * - editSummary {String} Changes done (text for the edit summary)
916930 * - doneFn {Function} callback after everything is done
917931 * - $link {jQuery}
918932 * - action
@@ -952,7 +966,7 @@
953967
954968 // Summary of the action to be taken
955969 summaryHolder = $( '<p>' )
956 - .html( '<strong>' + mw.msg( 'ajax-category-question' ) + '</strong><br/>' + props.dialogDescription );
 970+ .html( '<strong>' + mw.message( 'ajax-category-question' ).escaped() + '</strong><br/>' + props.dialogDescription );
957971
958972 // Reason textbox.
959973 reasonBox = $( '<input type="text" size="45"></input>' )

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r93351AjaxCategories rewrite:...krinkle00:43, 28 July 2011

Status & tagging log