LogFormatter: Fail softer when trying to link an invalid titles
authorBartosz Dziewoński <matma.rex@gmail.com>
Wed, 1 Aug 2018 01:13:18 +0000 (03:13 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Wed, 1 Aug 2018 14:19:55 +0000 (16:19 +0200)
Old log entries contain titles that used to be valid, but now are not.

Bug: T185049
Change-Id: Ia66d901aedf1b385574b3910b29f020b3fd4bd97

includes/logging/LogFormatter.php
languages/i18n/en.json
languages/i18n/qqq.json

index d59c6aa..1380ef8 100644 (file)
@@ -642,13 +642,18 @@ class LogFormatter {
         * @param Title|null $title The page
         * @param array $parameters Query parameters
         * @param string|null $html Linktext of the link as raw html
-        * @throws MWException
         * @return string
         */
        protected function makePageLink( Title $title = null, $parameters = [], $html = null ) {
                if ( !$title instanceof Title ) {
-                       throw new MWException( 'Expected title, got null' );
+                       $msg = $this->msg( 'invalidtitle' )->text();
+                       if ( !$this->plaintext ) {
+                               return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ], $msg );
+                       } else {
+                               return $msg;
+                       }
                }
+
                if ( !$this->plaintext ) {
                        $html = $html !== null ? new HtmlArmor( $html ) : $html;
                        $link = $this->getLinkRenderer()->makeLink( $title, $html, [], $parameters );
index edc18bb..50b85ef 100644 (file)
        "ns-specialprotected": "Special pages cannot be edited.",
        "titleprotected": "This title has been protected from creation by [[User:$1|$1]].\nThe reason given is <em>$2</em>.",
        "filereadonlyerror": "Unable to modify the file \"$1\" because the file repository \"$2\" is in read-only mode.\n\nThe system administrator who locked it offered this explanation: \"$3\".",
+       "invalidtitle": "Invalid title",
        "invalidtitle-knownnamespace": "Invalid title with namespace \"$2\" and text \"$3\"",
        "invalidtitle-unknownnamespace": "Invalid title with unknown namespace number $1 and text \"$2\"",
        "exception-nologin": "Not logged in",
index d918a08..d9bd995 100644 (file)
        "ns-specialprotected": "Error message displayed when trying to edit a page in the Special namespace",
        "titleprotected": "Used as error message. Parameters:\n* $1 - username; GENDER supported\n* $2 - reason for protection",
        "filereadonlyerror": "Parameters:\n* $1 - file name\n* $2 - file repository name\n* $3 - reason",
+       "invalidtitle": "Displayed when an invalid title was encountered (generally in a list) and there are no details about it to be shown.",
        "invalidtitle-knownnamespace": "Displayed when an invalid title was encountered (generally in a list), but the namespace number is known to exist.\n\nParameters:\n* $1 - (Unused) the namespace number\n* $2 - the namespace name in content language or {{msg-mw|blanknamespace}} for the main namespace\n* $3 - the part of the title after the namespace (e.g. SomeName for the page User:SomeName)",
        "invalidtitle-unknownnamespace": "Displayed when an invalid title was encountered (generally in a list) and the namespace number is unknown.\n\nParameters:\n* $1 - the namespace number\n* $2 - the part of the title after the namespace (e.g. SomeName for the page User:SomeName)",
        "exception-nologin": "Generic page title used on error page when a user is not logged in. Message used by the UserNotLoggedIn exception.\n{{Identical|Not logged in}}",