LogFormatter: Don't return a non-array from formatParameterValueForApi
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 28 Sep 2017 14:06:53 +0000 (10:06 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Thu, 28 Sep 2017 14:06:53 +0000 (10:06 -0400)
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
tests/phpunit/includes/logging/LogFormatterTest.php

index 2a47943..0f1e1f7 100644 (file)
@@ -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':
index 1ef3df6..012b0a3 100644 (file)
@@ -308,6 +308,10 @@ class LogFormatterTest extends MediaWikiLangTestCase {
                                'key_ns' => NS_PROJECT,
                                'key_title' => Title::newFromText( 'project:foo' )->getFullText(),
                        ] ],
+                       [ '4:title-link:key', '<invalid>', [
+                               'key_ns' => NS_SPECIAL,
+                               'key_title' => SpecialPage::getTitleFor( 'Badtitle', '<invalid>' )->getFullText(),
+                       ] ],
                        [ '4:user:key', 'foo', [ 'key' => 'Foo' ] ],
                        [ '4:user-link:key', 'foo', [ 'key' => 'Foo' ] ],
                ];