From: daniel Date: Mon, 3 Jun 2019 21:29:55 +0000 (+0200) Subject: Tolerate invalid titles in some ChangesFeed and LogFormatter code X-Git-Tag: 1.34.0-rc.0~1286^2 X-Git-Url: http://git.cyclocoop.org/%27http:/code.google.com/p/ie7-js/Three?a=commitdiff_plain;h=7271ac0dcd001b514dbd9753a3d5a461fc527a9d;p=lhc%2Fweb%2Fwiklou.git Tolerate invalid titles in some ChangesFeed and LogFormatter code Bug: T224811 Change-Id: If134e20cc14d80f9186611606df0b860889bd2cf --- diff --git a/includes/changes/ChangesFeed.php b/includes/changes/ChangesFeed.php index bb9114aa62..69c709c258 100644 --- a/includes/changes/ChangesFeed.php +++ b/includes/changes/ChangesFeed.php @@ -93,7 +93,7 @@ class ChangesFeed { $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); foreach ( $sorted as $obj ) { $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title ); - $talkpage = $nsInfo->hasTalkNamespace( $obj->rc_namespace ) + $talkpage = $nsInfo->hasTalkNamespace( $obj->rc_namespace ) && $title->isValid() ? $title->getTalkPage()->getFullURL() : ''; diff --git a/includes/logging/BlockLogFormatter.php b/includes/logging/BlockLogFormatter.php index ddecf9ead5..ead290f062 100644 --- a/includes/logging/BlockLogFormatter.php +++ b/includes/logging/BlockLogFormatter.php @@ -127,7 +127,7 @@ class BlockLogFormatter extends LogFormatter { public function getPreloadTitles() { $title = $this->entry->getTarget(); // Preload user page for non-autoblocks - if ( substr( $title->getText(), 0, 1 ) !== '#' ) { + if ( substr( $title->getText(), 0, 1 ) !== '#' && $title->isValid() ) { return [ $title->getTalkPage() ]; } return []; diff --git a/tests/phpunit/includes/logging/BlockLogFormatterTest.php b/tests/phpunit/includes/logging/BlockLogFormatterTest.php index bc0ca2ad85..b6f8f9cc37 100644 --- a/tests/phpunit/includes/logging/BlockLogFormatterTest.php +++ b/tests/phpunit/includes/logging/BlockLogFormatterTest.php @@ -34,6 +34,30 @@ class BlockLogFormatterTest extends LogFormatterTestCase { 'duration' => 'infinite', 'flags' => [ 'anononly' ], ], + 'preload' => [ new TitleValue( NS_USER_TALK, 'Logtestuser' ) ], + ], + ], + + // With blank page title (T224811) + [ + [ + 'type' => 'block', + 'action' => 'block', + 'comment' => 'Block comment', + 'user' => 0, + 'user_text' => 'Sysop', + 'namespace' => NS_USER, + 'title' => '', + 'params' => [], + ], + [ + 'text' => 'Sysop blocked (no username available) ' + . 'with an expiration time of indefinite', + 'api' => [ + 'duration' => 'infinite', + 'flags' => [], + ], + 'preload' => [], ], ], diff --git a/tests/phpunit/includes/logging/LogFormatterTestCase.php b/tests/phpunit/includes/logging/LogFormatterTestCase.php index 883af71240..fc2ab916cb 100644 --- a/tests/phpunit/includes/logging/LogFormatterTestCase.php +++ b/tests/phpunit/includes/logging/LogFormatterTestCase.php @@ -1,4 +1,5 @@ formatParametersForApi() ), 'Api log params is equal to expected array' ); + + if ( isset( $extra['preload'] ) ) { + $this->assertArrayEquals( + $this->getLinkTargetsAsStrings( $extra['preload'] ), + $this->getLinkTargetsAsStrings( + $formatter->getPreloadTitles() + ) + ); + } + } + + private function getLinkTargetsAsStrings( array $linkTargets ) { + return array_map( function ( LinkTarget $t ) { + return $t->getInterwiki() . ':' . $t->getNamespace() . ':' + . $t->getDBkey() . '#' . $t->getFragment(); + }, $linkTargets ); } protected function isLegacy( $extra ) {