Merge "ApiQuerySiteinfo: Fix "rightsinfo"/"url" when $wgRightsPage is set"

This commit is contained in:
jenkins-bot 2021-11-09 13:15:25 +00:00 committed by Gerrit Code Review
commit 6e4f771462
2 changed files with 18 additions and 5 deletions

View file

@ -769,9 +769,10 @@ class ApiQuerySiteinfo extends ApiQueryBase {
protected function appendRightsInfo( $property ) {
$config = $this->getConfig();
$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 );
$url = wfExpandUrl( $title, PROTO_CURRENT );
$url = wfExpandUrl( $title->getLinkURL(), PROTO_CURRENT );
} else {
$title = false;
$url = $config->get( 'RightsUrl' );

View file

@ -477,15 +477,27 @@ class ApiQuerySiteinfoTest extends ApiTestCase {
'wgRightsUrl' => $url,
'wgRightsText' => $text,
] );
$this->assertSame(
[ 'url' => $expectedUrl, 'text' => $expectedText ],
$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() {
$textUrl = wfExpandUrl( Title::newFromText( 'License' ), PROTO_CURRENT );
$textUrl = wfExpandUrl( Title::newFromText( 'License' )->getLinkURL(), PROTO_CURRENT );
$url = 'http://license.example/';
return [
@ -499,7 +511,7 @@ class ApiQuerySiteinfoTest extends ApiTestCase {
'Page and text' => [ 'License', null, '!!!', $textUrl, '!!!' ],
'Page and URL and text' => [ 'License', $url, '!!!', $textUrl, '!!!' ],
'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', '' ],
'Text "0"' => [ null, null, '0', '', '0' ],
];