jenkins-bot has submitted this change and it was merged.

Change subject: Extract file name from thumbnail only from first occurrence
......................................................................


Extract file name from thumbnail only from first occurrence

The existing regex assumes repetition of the filename in both
areas of the URL, which is limiting. The use case is having the second
instance of the filename replaced by the sha1 of the original, as
done here: I545586ff8d0020d00d9faa1dff2d0d9721134452

Bug: T118437
Change-Id: I2c90e672e343fbb4d287f0f2a0397761824e25c7
---
M resources/src/mediawiki/mediawiki.Title.js
M tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
2 files changed, 10 insertions(+), 2 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/resources/src/mediawiki/mediawiki.Title.js 
b/resources/src/mediawiki/mediawiki.Title.js
index 910a78f..47250ee 100644
--- a/resources/src/mediawiki/mediawiki.Title.js
+++ b/resources/src/mediawiki/mediawiki.Title.js
@@ -608,7 +608,7 @@
                        thumbPhpRegex = /thumb\.php/,
                        regexes = [
                                // Thumbnails
-                               
/\/[a-f0-9]\/[a-f0-9]{2}\/([^\s\/]+)\/[^\s\/]+-(?:\1|thumbnail)[^\s\/]*$/,
+                               
/\/[a-f0-9]\/[a-f0-9]{2}\/([^\s\/]+)\/[^\s\/]+-[^\s\/]*$/,
 
                                // Thumbnails in non-hashed upload directories
                                
/\/([^\s\/]+)\/[^\s\/]+-(?:\1|thumbnail)[^\s\/]*$/,
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js 
b/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
index 641a5a5..4bcb12e 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
@@ -346,7 +346,7 @@
                assert.equal( title.getUrl(), '/wiki/User_talk:John_Doe', 
'Escaping in title and namespace for urls' );
        } );
 
-       QUnit.test( 'newFromImg', 40, function ( assert ) {
+       QUnit.test( 'newFromImg', 44, function ( assert ) {
                var title, i, thisCase, prefix,
                        cases = [
                                {
@@ -355,6 +355,14 @@
                                        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: 
'//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-ki708pr1r6g2dl5lbhvwdqxenhait13.jpg',
+                                       typeOfUrl: 'Hashed thumb with sha1-ed 
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',

-- 
To view, visit https://gerrit.wikimedia.org/r/252696
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2c90e672e343fbb4d287f0f2a0397761824e25c7
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gilles <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Edokter <[email protected]>
Gerrit-Reviewer: Filippo Giunchedi <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Jack Phoenix <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to