From 00a2df687234cbe8de244e659185a9c0a6cf43b1 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Wed, 31 Aug 2011 14:37:37 +0000 Subject: [PATCH] Fix Uncaught TypeError: Cannot call method 'substr' of undefined * When changing the name of a category and saving it, this error is thrown from $.ucFirst. Although the script does check for it to be a string, what happens between that and ucFirst is broken. It should always set 'category' of splitresult[0], not just if there is a [1] (=sortkey). Otherwise, if there is no sortkey, 'category' is undefined. * Also updated outdated comment saying that variable sortkey contains wikitext between "[[Category:Foo" and "]]" (which implies it includes the pipe, which is no longer true) Follows-up r93351. --- .../mediawiki.page/mediawiki.page.ajaxCategories.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/resources/mediawiki.page/mediawiki.page.ajaxCategories.js b/resources/mediawiki.page/mediawiki.page.ajaxCategories.js index 71f3ec5879..b7fe3c2ff1 100644 --- a/resources/mediawiki.page/mediawiki.page.ajaxCategories.js +++ b/resources/mediawiki.page/mediawiki.page.ajaxCategories.js @@ -270,20 +270,17 @@ mw.ajaxCategories = function( options ) { * @param e {jQuery Event} */ this.handleEditLink = function( e ) { - var input, category, categoryOld, - sortkey = '', // Wikitext for between '[[Category:Foo' and ']]'. + var input, category, sortkey, categoryOld, $el = $( this ), $link = $el.parent().parent().find( 'a:not(.icon)' ); // Grab category text input = $el.parent().find( '.mw-addcategory-input' ).val(); - // Strip sortkey + // Split categoryname and sortkey var arr = input.split( '|', 2 ); - if ( arr.length > 1 ) { - category = arr[0]; - sortkey = arr[1]; - } + category = arr[0]; + sortkey = arr[1]; // Is usually undefined, ie. if there was no '|' in the input. // Grab text var isAdded = $link.hasClass( 'mw-added-category' ); -- 2.20.1