From 3cc7feefd11691d54ae350a76259c70688c63675 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Thu, 5 Jan 2012 15:34:26 +0000 Subject: [PATCH] (bug 33321. Sort of) Adding a line to MediaWiki:Sidebar that contains a pipe, but doesn't have any pipes after being transformed by MessageCache, causes exception on all pages. This can happen with lines like: **{{#if:yes|Something}} Thank you to liangent for figuring out how to escape a | without {{!}} existing and | not working. --- RELEASE-NOTES-1.19 | 3 +++ includes/Skin.php | 7 ++++++- tests/phpunit/skins/SideBarTest.php | 30 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 383ba4eab8..edc84ed6a7 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -218,6 +218,9 @@ production. HTTPS when the local wiki is served over HTTPS. * (bug 33525) clearTagHooks doesn't clear function hooks. * (bug 33523) Function tag hooks don't appear on Special:Version. +* (bug 33321) Adding a line to MediaWiki:Sidebar that contains a pipe, but doesn't + have any pipes after being transformed by MessageCache, causes exception on + all pages. === API changes in 1.19 === * (bug 19838) siprop=interwikimap can now use the interwiki cache. diff --git a/includes/Skin.php b/includes/Skin.php index 1841f8a08e..bb817828ac 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1244,6 +1244,12 @@ abstract class Skin extends ContextSource { if ( strpos( $line, '|' ) !== false ) { // sanity check $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() ); $line = array_map( 'trim', explode( '|', $line, 2 ) ); + if ( count( $line ) !== 2 ) { + // Second sanity check, could be hit by people doing + // funky stuff with parserfuncs... (bug 3321) + continue; + } + $extraAttribs = array(); $msgLink = $this->msg( $line[0] )->inContentLanguage(); @@ -1255,7 +1261,6 @@ abstract class Skin extends ContextSource { } else { $link = $line[0]; } - $msgText = $this->msg( $line[1] ); if ( $msgText->exists() ) { $text = $msgText->text(); diff --git a/tests/phpunit/skins/SideBarTest.php b/tests/phpunit/skins/SideBarTest.php index ed74c6e8f5..1734fd28d2 100644 --- a/tests/phpunit/skins/SideBarTest.php +++ b/tests/phpunit/skins/SideBarTest.php @@ -106,6 +106,36 @@ class SideBarTest extends MediaWikiLangTestCase { ); } + /** bug 33321 */ + function testTrickyPipe() { + $this->assertSidebar( + array( 'Title' => array( + # 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 +** Baz|Fred +** {{PLURAL:1|page-to-go-to{{int:pipe-separator/en}}title-to-display|branch not taken}} +' + ); + + } #### Attributes for external links ########################## -- 2.20.1