Merge "ApiQuerySiteinfo: Fix "rightsinfo"/"url" when $wgRightsPage is set"
This commit is contained in:
commit
6e4f771462
2 changed files with 18 additions and 5 deletions
|
|
@ -769,9 +769,10 @@ class ApiQuerySiteinfo extends ApiQueryBase {
|
||||||
protected function appendRightsInfo( $property ) {
|
protected function appendRightsInfo( $property ) {
|
||||||
$config = $this->getConfig();
|
$config = $this->getConfig();
|
||||||
$rightsPage = $config->get( 'RightsPage' );
|
$rightsPage = $config->get( 'RightsPage' );
|
||||||
if ( is_string( $rightsPage ) ) {
|
// The default value is null, but the installer sets it to empty string
|
||||||
|
if ( strlen( $rightsPage ) ) {
|
||||||
$title = Title::newFromText( $rightsPage );
|
$title = Title::newFromText( $rightsPage );
|
||||||
$url = wfExpandUrl( $title, PROTO_CURRENT );
|
$url = wfExpandUrl( $title->getLinkURL(), PROTO_CURRENT );
|
||||||
} else {
|
} else {
|
||||||
$title = false;
|
$title = false;
|
||||||
$url = $config->get( 'RightsUrl' );
|
$url = $config->get( 'RightsUrl' );
|
||||||
|
|
|
||||||
|
|
@ -477,15 +477,27 @@ class ApiQuerySiteinfoTest extends ApiTestCase {
|
||||||
'wgRightsUrl' => $url,
|
'wgRightsUrl' => $url,
|
||||||
'wgRightsText' => $text,
|
'wgRightsText' => $text,
|
||||||
] );
|
] );
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
[ 'url' => $expectedUrl, 'text' => $expectedText ],
|
[ 'url' => $expectedUrl, 'text' => $expectedText ],
|
||||||
$this->doQuery( 'rightsinfo' )
|
$this->doQuery( 'rightsinfo' )
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// The installer sets these options to empty string if not specified otherwise,
|
||||||
|
// test that this behaves the same as null.
|
||||||
|
$this->setMwGlobals( [
|
||||||
|
'wgRightsPage' => $page ?? '',
|
||||||
|
'wgRightsUrl' => $url ?? '',
|
||||||
|
'wgRightsText' => $text ?? '',
|
||||||
|
] );
|
||||||
|
$this->assertSame(
|
||||||
|
[ 'url' => $expectedUrl, 'text' => $expectedText ],
|
||||||
|
$this->doQuery( 'rightsinfo' ),
|
||||||
|
'empty string behaves the same as null'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rightsInfoProvider() {
|
public function rightsInfoProvider() {
|
||||||
$textUrl = wfExpandUrl( Title::newFromText( 'License' ), PROTO_CURRENT );
|
$textUrl = wfExpandUrl( Title::newFromText( 'License' )->getLinkURL(), PROTO_CURRENT );
|
||||||
$url = 'http://license.example/';
|
$url = 'http://license.example/';
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
@ -499,7 +511,7 @@ class ApiQuerySiteinfoTest extends ApiTestCase {
|
||||||
'Page and text' => [ 'License', null, '!!!', $textUrl, '!!!' ],
|
'Page and text' => [ 'License', null, '!!!', $textUrl, '!!!' ],
|
||||||
'Page and URL and text' => [ 'License', $url, '!!!', $textUrl, '!!!' ],
|
'Page and URL and text' => [ 'License', $url, '!!!', $textUrl, '!!!' ],
|
||||||
'Pagename "0"' => [ '0', null, null,
|
'Pagename "0"' => [ '0', null, null,
|
||||||
wfExpandUrl( Title::newFromText( '0' ), PROTO_CURRENT ), '0' ],
|
wfExpandUrl( Title::newFromText( '0' )->getLinkURL(), PROTO_CURRENT ), '0' ],
|
||||||
'URL "0"' => [ null, '0', null, '0', '' ],
|
'URL "0"' => [ null, '0', null, '0', '' ],
|
||||||
'Text "0"' => [ null, null, '0', '', '0' ],
|
'Text "0"' => [ null, null, '0', '', '0' ],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue