From fa2724fa842e8b03d98236545ba5640255d08722 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Thu, 28 Sep 2017 10:06:53 -0400 Subject: [PATCH] LogFormatter: Don't return a non-array from formatParameterValueForApi If the title for a 'title' or 'title-link' type is invalid, the code still must not return a non-array from the method. I'm not sure this is what was behind T176938, but it's the only thing I can find that might cause the errors I saw logged at about the same time. Change-Id: Iae77eb6ad9a64d8b67074164ff0c0fea36826f3c --- includes/logging/LogFormatter.php | 8 +++++--- tests/phpunit/includes/logging/LogFormatterTest.php | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index 2a47943a03..0f1e1f7f1e 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -866,10 +866,12 @@ class LogFormatter { case 'title': case 'title-link': $title = Title::newFromText( $value ); - if ( $title ) { - $value = []; - ApiQueryBase::addTitleInfo( $value, $title, "{$name}_" ); + if ( !$title ) { + // Huh? Do something halfway sane. + $title = SpecialPage::getTitleFor( 'Badtitle', $value ); } + $value = []; + ApiQueryBase::addTitleInfo( $value, $title, "{$name}_" ); return $value; case 'user': diff --git a/tests/phpunit/includes/logging/LogFormatterTest.php b/tests/phpunit/includes/logging/LogFormatterTest.php index 1ef3df6ca1..012b0a3aa5 100644 --- a/tests/phpunit/includes/logging/LogFormatterTest.php +++ b/tests/phpunit/includes/logging/LogFormatterTest.php @@ -308,6 +308,10 @@ class LogFormatterTest extends MediaWikiLangTestCase { 'key_ns' => NS_PROJECT, 'key_title' => Title::newFromText( 'project:foo' )->getFullText(), ] ], + [ '4:title-link:key', '', [ + 'key_ns' => NS_SPECIAL, + 'key_title' => SpecialPage::getTitleFor( 'Badtitle', '' )->getFullText(), + ] ], [ '4:user:key', 'foo', [ 'key' => 'Foo' ] ], [ '4:user-link:key', 'foo', [ 'key' => 'Foo' ] ], ]; -- 2.20.1