mediawiki.Title: Generalise filename-matching in newFromImg
authorjarry1250 <jarry1250@gmail.com>
Mon, 21 Oct 2013 19:44:38 +0000 (20:44 +0100)
committerKrinkle <krinklemail@gmail.com>
Mon, 28 Oct 2013 09:42:13 +0000 (09:42 +0000)
Both core and extensions can (and do) modify the thumbnail string
e.g. to add page numbers, languages, etc.

As bawolff notes in the commentary to bug 55963, the assumption
that the filename itself appears twice is likely to be violated
from time to time, but for the moment it suffices to fix the
apparent regression described in that bug report.

Also includes some additional test cases.

Bug: 55963
Change-Id: I9bb29a24f9bf50924699b913e31f44689906c525

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

index b236019..4a64566 100644 (file)
 
                        // thumb.php-generated thumbnails
                        thumbPhpRegex = /thumb\.php/,
-
                        regexes = [
                                // Thumbnails
-                               /\/[a-f0-9]\/[a-f0-9]{2}\/([^\s\/]+)\/[0-9]+px-\1[^\s\/]*$/,
+                               /\/[a-f0-9]\/[a-f0-9]{2}\/([^\s\/]+)\/[^\s\/]+-\1[^\s\/]*$/,
 
                                // Thumbnails in non-hashed upload directories
-                               /\/([^\s\/]+)\/[0-9]+px-\1[^\s\/]*$/,
+                               /\/([^\s\/]+)\/[^\s\/]+-\1[^\s\/]*$/,
 
                                // Full size images
                                /\/[a-f0-9]\/[a-f0-9]{2}\/([^\s\/]+)$/,
index ba15fba..13c0efc 100644 (file)
                assert.equal( title.getUrl(), '/wiki/User_talk:John_Doe', 'Escaping in title and namespace for urls' );
        } );
 
-       QUnit.test( 'newFromImg', 28, function ( assert ) {
+       QUnit.test( 'newFromImg', 36, function ( assert ) {
                var title, i, thisCase, prefix,
                        cases = [
                                {
                                        prefixedText: 'File:Anticlockwise heliotrope\'s.jpg'
                                },
 
+                               {
+                                       url: '/wiki/images/thumb/8/80/Wikipedia-logo-v2.svg/langde-150px-Wikipedia-logo-v2.svg.png',
+                                       typeOfUrl: 'Normal hashed directory thumbnail with complex thumbnail parameters',
+                                       nameText: 'Wikipedia-logo-v2',
+                                       prefixedText: 'File:Wikipedia-logo-v2.svg'
+                               },
+
                                {
                                        url: '//upload.wikimedia.org/wikipedia/commons/thumb/8/80/Wikipedia-logo-v2.svg/150px-Wikipedia-logo-v2.svg.png',
                                        typeOfUrl: 'Commons thumbnail',
                                        prefixedText: 'File:Wikipedia-logo-v2.svg'
                                },
 
+                               {
+                                       url: '/wikipedia/commons/thumb/Wikipedia-logo-v2.svg/langde-150px-Wikipedia-logo-v2.svg.png',
+                                       typeOfUrl: 'Commons unhashed thumbnail with complex thumbnail parameters',
+                                       nameText: 'Wikipedia-logo-v2',
+                                       prefixedText: 'File:Wikipedia-logo-v2.svg'
+                               },
+
                                {
                                        url: '/wiki/images/Anticlockwise_heliotrope%27s.jpg',
                                        typeOfUrl: 'Unhashed local file',