title: Fix bogus Title::getSkinFromConfigSubpage()

Same as I3d8c6f6 already did for two other methods. It looks like this
one was forgotten.

This patch also adds tests for the previously untested method
Title::getSkinFromConfigSubpage().

Note this patch changes the behavior of Title::getSkinFromConfigSubpage()
slightly. It will return an empty string much more often. This is not a
breaking change as far as I can tell. According to
https://codesearch.wmflabs.org/search/?q=getSkinFromConfigSubpage%5C(
there are only two known callers, and both guarantee the string passed to
this method contains both a slash and a dot. Returning an empty string in
all other cases is much closer to the original intent of the method. For
example. "User:Vector" will not be considered a valid skin name any more.

Bug: T229443
Change-Id: I0a5be39ca11a4e5d6c05f70eb05e80c6c4980523
This commit is contained in:
Thiemo Kreuz 2019-03-26 11:58:54 +01:00
parent 14639b48d7
commit 3ae4c5efc2
2 changed files with 35 additions and 6 deletions

View file

@ -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 );
}
/**

View file

@ -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 ],