Honor shortened thumbnail paths in mw.Title.newFromImg()
authorrillke <rainerrillke@hotmail.com>
Fri, 22 Nov 2013 16:15:55 +0000 (17:15 +0100)
committerrillke <rainerrillke@hotmail.com>
Fri, 22 Nov 2013 16:15:55 +0000 (17:15 +0100)
Currently mw.Title.newFromImg() fails when the thumbnail path is
shortened.

Cf.
https://git.wikimedia.org/blob/mediawiki%2Fcore.git/1e0bd351b760c2b1d9f5c0e058dc1c3bf9a83d2e/includes%2Ffilerepo%2FFileRepo.php#L1623

Change-Id: I7c166cfaefc1c31f9c378edd98c46f61b9c30aa3

resources/mediawiki/mediawiki.Title.js
tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js

index dde5abf..e25848a 100644 (file)
                        thumbPhpRegex = /thumb\.php/,
                        regexes = [
                                // Thumbnails
-                               /\/[a-f0-9]\/[a-f0-9]{2}\/([^\s\/]+)\/[^\s\/]+-\1[^\s\/]*$/,
+                               /\/[a-f0-9]\/[a-f0-9]{2}\/([^\s\/]+)\/[^\s\/]+-(?:\1|thumbnail)[^\s\/]*$/,
 
                                // Thumbnails in non-hashed upload directories
-                               /\/([^\s\/]+)\/[^\s\/]+-\1[^\s\/]*$/,
+                               /\/([^\s\/]+)\/[^\s\/]+-(?:\1|thumbnail)[^\s\/]*$/,
 
                                // Full size images
                                /\/[a-f0-9]\/[a-f0-9]{2}\/([^\s\/]+)$/,
index f0bb0fc..1b7fea6 100644 (file)
                assert.equal( title.getUrl(), '/wiki/User_talk:John_Doe', 'Escaping in title and namespace for urls' );
        } );
 
-       QUnit.test( 'newFromImg', 36, function ( assert ) {
+       QUnit.test( 'newFromImg', 40, function ( assert ) {
                var title, i, thisCase, prefix,
                        cases = [
+                               {
+                                       url: '//upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Princess_Alexandra_of_Denmark_%28later_Queen_Alexandra%2C_wife_of_Edward_VII%29_with_her_two_eldest_sons%2C_Prince_Albert_Victor_%28Eddy%29_and_George_Frederick_Ernest_Albert_%28later_George_V%29.jpg/939px-thumbnail.jpg',
+                                       typeOfUrl: 'Hashed thumb with shortened path',
+                                       nameText: 'Princess Alexandra of Denmark (later Queen Alexandra, wife of Edward VII) with her two eldest sons, Prince Albert Victor (Eddy) and George Frederick Ernest Albert (later George V)',
+                                       prefixedText: 'File:Princess Alexandra of Denmark (later Queen Alexandra, wife of Edward VII) with her two eldest sons, Prince Albert Victor (Eddy) and George Frederick Ernest Albert (later George V).jpg'
+                               },
                                {
                                        url: '/wiki/images/thumb/9/91/Anticlockwise_heliotrope%27s.jpg/99px-Anticlockwise_heliotrope%27s.jpg',
                                        typeOfUrl: 'Normal hashed directory thumbnail',