diff --git a/includes/Title.php b/includes/Title.php index ef0b02d30c9..9b770039f91 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1483,13 +1483,18 @@ class Title implements LinkTarget, PageIdentity, IDBAccessObject { * @since 1.31 */ public function getSkinFromConfigSubpage() { - $subpage = explode( '/', $this->mTextform ); - $subpage = $subpage[count( $subpage ) - 1]; - $lastdot = strrpos( $subpage, '.' ); - if ( $lastdot === false ) { - return $subpage; # Never happens: only called for names ending in '.css'/'.json'/'.js' + $text = $this->getText(); + $lastSlashPos = $this->findSubpageDivider( $text, -1 ); + if ( $lastSlashPos === false ) { + return ''; } - return substr( $subpage, 0, $lastdot ); + + $lastDot = strrpos( $text, '.', $lastSlashPos ); + if ( $lastDot === false ) { + return ''; + } + + return substr( $text, $lastSlashPos + 1, $lastDot - $lastSlashPos - 1 ); } /** diff --git a/tests/phpunit/includes/TitleMethodsTest.php b/tests/phpunit/includes/TitleMethodsTest.php index c67a31dad31..c425b9b55b0 100644 --- a/tests/phpunit/includes/TitleMethodsTest.php +++ b/tests/phpunit/includes/TitleMethodsTest.php @@ -193,6 +193,30 @@ class TitleMethodsTest extends MediaWikiLangTestCase { ); } + public function provideGetSkinFromConfigSubpage() { + return [ + [ 'User:Foo', '' ], + [ 'User:Foo.css', '' ], + [ 'User:Foo/', '' ], + [ 'User:Foo/bar', '' ], + [ 'User:Foo./bar', '' ], + [ 'User:Foo/bar.', 'bar' ], + [ 'User:Foo/bar.css', 'bar' ], + [ '/bar.css', '' ], + [ '//bar.css', 'bar' ], + [ '.css', '' ], + ]; + } + + /** + * @dataProvider provideGetSkinFromConfigSubpage + * @covers Title::getSkinFromConfigSubpage + */ + public function testGetSkinFromConfigSubpage( $title, $expected ) { + $title = Title::newFromText( $title ); + $this->assertSame( $expected, $title->getSkinFromConfigSubpage() ); + } + public static function provideIsUserConfigPage() { return [ [ 'Help:Foo', false ],