Fix Uncaught TypeError: Cannot call method 'substr' of undefined
authorKrinkle <krinkle@users.mediawiki.org>
Wed, 31 Aug 2011 14:37:37 +0000 (14:37 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Wed, 31 Aug 2011 14:37:37 +0000 (14:37 +0000)
* 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.

resources/mediawiki.page/mediawiki.page.ajaxCategories.js

index 71f3ec5..b7fe3c2 100644 (file)
@@ -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' );