mw.widgets.CategoryCapsuleItemWidget: Handle titles not normalized in JS code
authorBartosz Dziewoński <matma.rex@gmail.com>
Wed, 24 Aug 2016 20:21:42 +0000 (22:21 +0200)
committerGergő Tisza <gtisza@wikimedia.org>
Tue, 30 Aug 2016 01:39:59 +0000 (01:39 +0000)
Bug: T139130
Change-Id: If20941fb381a01aab01b971e1093a53b76c96f66

resources/src/mediawiki.widgets/mw.widgets.CategoryCapsuleItemWidget.js

index 946823d..4d86cfd 100644 (file)
                        prop: [ 'info' ],
                        titles: titles
                } ).done( function ( response ) {
+                       var
+                               normalized = {},
+                               pages = {};
+                       $.each( response.query.normalized || [], function ( index, data ) {
+                               normalized[ data.fromencoded ? decodeURIComponent( data.from ) : data.from ] = data.to;
+                       } );
                        $.each( response.query.pages, function ( index, page ) {
-                               var title = new ForeignTitle( page.title ).getPrefixedText();
-                               cache.existenceCache[ title ] = !page.missing;
-                               if ( !queue[ title ] ) {
-                                       // Debugging for T139130
-                                       throw new Error( 'No queue for "' + title + '", requested "' + titles.join( '|' ) + '"' );
+                               pages[ page.title ] = !page.missing;
+                       } );
+                       $.each( titles, function ( index, title ) {
+                               var normalizedTitle = title;
+                               while ( normalized[ normalizedTitle ] ) {
+                                       normalizedTitle = normalized[ normalizedTitle ];
                                }
+                               cache.existenceCache[ title ] = pages[ normalizedTitle ];
                                queue[ title ].resolve( cache.existenceCache[ title ] );
                        } );
                } );