Merge "LogFormatter: Fail softer when trying to link an invalid titles"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 8 Aug 2018 15:35:56 +0000 (15:35 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 8 Aug 2018 15:35:56 +0000 (15:35 +0000)
1  2 
includes/logging/LogFormatter.php
languages/i18n/en.json
languages/i18n/qqq.json

@@@ -189,7 -189,6 +189,7 @@@ class LogFormatter 
         * to avoid formatting for any particular user.
         * @see getActionText()
         * @return string Plain text
 +       * @return-taint tainted
         */
        public function getPlainActionText() {
                $this->plaintext = true;
        /**
         * Gets the log action, including username.
         * @return string HTML
 +       * phan-taint-check gets very confused by $this->plaintext, so disable.
 +       * @return-taint onlysafefor_html
         */
        public function getActionText() {
                if ( $this->canView( LogPage::DELETED_ACTION ) ) {
         * @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 );
         * Helper method for displaying restricted element.
         * @param string $message
         * @return string HTML or wiki text
 +       * @return-taint onlysafefor_html
         */
        protected function getRestrictedElement( $message ) {
                if ( $this->plaintext ) {
                return $this->context->msg( $key );
        }
  
 +      /**
 +       * @param User $user
 +       * @param int $toolFlags Combination of Linker::TOOL_LINKS_* flags
 +       * @return string wikitext or html
 +       * @return-taint onlysafefor_html
 +       */
        protected function makeUserLink( User $user, $toolFlags = 0 ) {
                if ( $this->plaintext ) {
                        $element = $user->getName();
@@@ -948,10 -943,6 +953,10 @@@ class LegacyLogFormatter extends LogFor
                return $this->comment;
        }
  
 +      /**
 +       * @return string
 +       * @return-taint onlysafefor_html
 +       */
        protected function getActionMessage() {
                $entry = $this->entry;
                $action = LogPage::actionText(
diff --combined languages/i18n/en.json
        "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",
        "categories": "Categories",
        "categories-summary": "",
        "categories-submit": "Show",
 -      "categoriespagetext": "The following {{PLURAL:$1|category contains|categories contain}} pages or media.\n[[Special:UnusedCategories|Unused categories]] are not shown here.\nAlso see [[Special:WantedCategories|wanted categories]].",
 +      "categoriespagetext": "The following {{PLURAL:$1|category exists|categories exist}} on the wiki, and may or may not be unused.\nAlso see [[Special:WantedCategories|wanted categories]].",
        "categoriesfrom": "Display categories starting at:",
        "deletedcontributions": "Deleted user contributions",
        "deletedcontributions-summary": "",
diff --combined languages/i18n/qqq.json
        "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}}",
        "categories": "The page name of [[Special:Categories]].\n{{Identical|Category}}",
        "categories-summary": "{{doc-specialpagesummary|categories}}",
        "categories-submit": "Submit button on [[Special:Categories]]\n{{Identical|Show}}",
 -      "categoriespagetext": "{{doc-important|Do not translate or change links.}}\nText displayed in [[Special:Categories]].\n\nIn order to translate \"Unused categories\" and \"wanted categories\" see {{msg-mw|Unusedcategories}} and {{msg-mw|Wantedcategories}}.\n\nParameters:\n* $1 - number of categories",
 +      "categoriespagetext": "{{doc-important|Do not translate or change links.}}\nText displayed in [[Special:Categories]].\n\nIn order to translate \"wanted categories\" see {{msg-mw|Wantedcategories}}.\n\nParameters:\n* $1 - number of categories",
        "categoriesfrom": "Used as label for the input box in [[Special:Categories]].\n\nThis message follows the fieldset label {{msg-mw|categories}}, and is followed by the input box.",
        "deletedcontributions": "The message is shown as a link on [[Special:SpecialPages]] to [[Special:DeletedContributions]].\n\n{{Identical|Deleted user contributions}}",
        "deletedcontributions-summary": "{{doc-specialpagesummary|deletedcontributions}}",