Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/126720
Change subject: Stop throwing fatal errors in CommonsLinkFormatter ...................................................................... Stop throwing fatal errors in CommonsLinkFormatter We are currently using the Title object as a passive formatter to normalize file names (e.g. replace underscores with spaces). This may not be the best solution but it works. We may think about other ways to do this but as long as we are using this method we should not throw wild "Fatal error: Call to a member function [...] on a non-object" to the frontend and logs. Bug: 62904 Change-Id: I28a20dbb63a8eb353b80de4e055e0eb830695efe --- M lib/includes/formatters/CommonsLinkFormatter.php M lib/tests/phpunit/formatters/CommonsLinkFormatterTest.php 2 files changed, 10 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/20/126720/1 diff --git a/lib/includes/formatters/CommonsLinkFormatter.php b/lib/includes/formatters/CommonsLinkFormatter.php index d406216..3f3618f 100644 --- a/lib/includes/formatters/CommonsLinkFormatter.php +++ b/lib/includes/formatters/CommonsLinkFormatter.php @@ -53,9 +53,12 @@ // We are using NS_MAIN only because makeTitleSafe requires a valid namespace // We cannot use makeTitle because it does not secureAndSplit() $title = Title::makeTitleSafe( NS_MAIN, $fileName ); + if ( $title === null ) { + return $fileName; + } $attributes = array_merge( $this->attributes, array( - 'href' => '//commons.wikimedia.org/wiki/' . 'File:' . $title->getPartialURL() + 'href' => '//commons.wikimedia.org/wiki/File:' . $title->getPartialURL() ) ); $html = Html::element( 'a', $attributes, $title->getText() ); diff --git a/lib/tests/phpunit/formatters/CommonsLinkFormatterTest.php b/lib/tests/phpunit/formatters/CommonsLinkFormatterTest.php index 7fd4a0d..14f56b0 100644 --- a/lib/tests/phpunit/formatters/CommonsLinkFormatterTest.php +++ b/lib/tests/phpunit/formatters/CommonsLinkFormatterTest.php @@ -49,6 +49,11 @@ $options, '@<a .*href="//commons.wikimedia.org/wiki/File:Example%2Bplus.jpg".*>.*Example\+plus.jpg.*</a>@' ), + array( + new StringValue( '' ), + $options, + '//' + ), ); } @@ -74,4 +79,5 @@ $this->setExpectedException( 'InvalidArgumentException' ); $formatter->format( $value ); } + } -- To view, visit https://gerrit.wikimedia.org/r/126720 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I28a20dbb63a8eb353b80de4e055e0eb830695efe Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits