Merge "Tolerate invalid titles in some ChangesFeed and LogFormatter code"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 24 Jun 2019 23:29:11 +0000 (23:29 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 24 Jun 2019 23:29:11 +0000 (23:29 +0000)
includes/changes/ChangesFeed.php
includes/logging/BlockLogFormatter.php
tests/phpunit/includes/logging/BlockLogFormatterTest.php
tests/phpunit/includes/logging/LogFormatterTestCase.php

index bb9114a..69c709c 100644 (file)
@@ -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()
                                : '';
 
index ddecf9e..ead290f 100644 (file)
@@ -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 [];
index bc0ca2a..b6f8f9c 100644 (file)
@@ -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' => [],
                                ],
                        ],
 
index 883af71..fc2ab91 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+use MediaWiki\Linker\LinkTarget;
 
 /**
  * @since 1.26
@@ -22,6 +23,22 @@ abstract class LogFormatterTestCase extends MediaWikiLangTestCase {
                        self::removeApiMetaData( $formatter->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 ) {