/** Build $this->messages array */
private function initMessagesHref() {
- # List of default messages for the sidebar:
- $URL_messages = array(
+ # List of default messages for the sidebar. The sidebar doesn't care at
+ # all whether they are full URLs, interwiki links or local titles.
+ $URL_messages = [
'mainpage',
'portal-url',
'currentevents-url',
'recentchanges-url',
'randompage-url',
'helppage',
- );
+ ];
+ # We're assuming that isValidURI works as advertised: it's also
+ # tested separately, in tests/phpunit/includes/HttpTest.php.
foreach ( $URL_messages as $m ) {
$titleName = MessageCache::singleton()->get( $m );
- $title = Title::newFromText( $titleName );
- $this->messages[$m]['href'] = $title->getLocalURL();
+ if ( Http::isValidURI( $titleName ) ) {
+ $this->messages[$m]['href'] = $titleName;
+ } else {
+ $title = Title::newFromText( $titleName );
+ $this->messages[$m]['href'] = $title->getLocalURL();
+ }
}
}
/**
* Internal helper to test the sidebar
- * @param $expected
- * @param $text
- * @param $message (Default: '')
+ * @param array $expected
+ * @param string $text
+ * @param string $message (Default: '')
* @todo this assert method to should be converted to a test using a dataprovider..
*/
private function assertSideBar( $expected, $text, $message = '' ) {
- $bar = array();
+ $bar = [];
$this->skin->addToSidebarPlain( $bar, $text );
$this->assertEquals( $expected, $bar, $message );
}
*/
public function testSidebarWithOnlyTwoTitles() {
$this->assertSideBar(
- array(
- 'Title1' => array(),
- 'Title2' => array(),
- ),
+ [
+ 'Title1' => [],
+ 'Title2' => [],
+ ],
'* Title1
* Title2
'
* @covers SkinTemplate::addToSidebarPlain
*/
public function testExpandMessages() {
- $this->assertSidebar(
- array( 'Title' => array(
- array(
+ $this->assertSideBar(
+ [ 'Title' => [
+ [
'text' => 'Help',
'href' => $this->messages['helppage']['href'],
'id' => 'n-help',
'active' => null
- )
- ) ),
+ ]
+ ] ],
'* Title
** helppage|help
'
* @covers SkinTemplate::addToSidebarPlain
*/
public function testExternalUrlsRequireADescription() {
- $this->setMwGlobals( array(
+ $this->setMwGlobals( [
'wgNoFollowLinks' => true,
- 'wgNoFollowDomainExceptions' => array(),
- 'wgNoFollowNsExceptions' => array(),
- ) );
- $this->assertSidebar(
- array( 'Title' => array(
+ 'wgNoFollowDomainExceptions' => [],
+ 'wgNoFollowNsExceptions' => [],
+ ] );
+ $this->assertSideBar(
+ [ 'Title' => [
# ** http://www.mediawiki.org/| Home
- array(
+ [
'text' => 'Home',
'href' => 'http://www.mediawiki.org/',
'id' => 'n-Home',
'active' => null,
'rel' => 'nofollow',
- ),
+ ],
# ** http://valid.no.desc.org/
# ... skipped since it is missing a pipe with a description
- ) ),
+ ] ],
'* Title
** http://www.mediawiki.org/| Home
** http://valid.no.desc.org/
*/
public function testTrickyPipe() {
$this->assertSidebar(
- array( 'Title' => array(
+ [ 'Title' => [
# The first 2 are skipped
# Doesn't really test the url properly
# because it will vary with $wgArticlePath et al.
# ** Baz|Fred
- array(
+ [
'text' => 'Fred',
'href' => Title::newFromText( 'Baz' )->getLocalURL(),
'id' => 'n-Fred',
'active' => null,
- ),
- array(
+ ],
+ [
'text' => 'title-to-display',
'href' => Title::newFromText( 'page-to-go-to' )->getLocalURL(),
'id' => 'n-title-to-display',
'active' => null,
- ),
- ) ),
+ ],
+ ] ],
'* Title
** {{PAGENAME|Foo}}
** Bar
$text = '* Title
** http://www.mediawiki.org/| Home';
- $bar = array();
+ $bar = [];
$this->skin->addToSideBarPlain( $bar, $text );
return $bar['Title'][0];
* Simple test to verify our helper assertAttribs() is functional
*/
public function testTestAttributesAssertionHelper() {
- $this->setMwGlobals( array(
+ $this->setMwGlobals( [
'wgNoFollowLinks' => true,
- 'wgNoFollowDomainExceptions' => array(),
- 'wgNoFollowNsExceptions' => array(),
+ 'wgNoFollowDomainExceptions' => [],
+ 'wgNoFollowNsExceptions' => [],
'wgExternalLinkTarget' => false,
- ) );
+ ] );
$attribs = $this->getAttribs();
$this->assertArrayHasKey( 'rel', $attribs );
}
public static function dataRespectExternallinktarget() {
- return array(
- array( '_blank' ),
- array( '_self' ),
- );
+ return [
+ [ '_blank' ],
+ [ '_self' ],
+ ];
}
}