MWException: Fix sitename appearing twice in <title>
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 14 Mar 2014 05:02:45 +0000 (06:02 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 31 Mar 2014 18:49:54 +0000 (11:49 -0700)
The MWException::getPageTitle method is wrapping the page title
in the 'pagetitle' ($1 - sitename) message, but OutputPage does
this as well when outputing <title>.

OutputPage::prepareErrorPage takes the first parameter as page
title (unwrapped, appears in <h1>,) and the second optional one
is for <title>, which (if omitted, like before) results in
pagetitle being applied by OutputPage.

Now that we specify them separately, this also removes the
sitename from the <h1> on the page, which always looked weird.

It also fixes DBQueryError (extends MWException) where previously
no sitename was added, it just returns 'databaseerror' from
its DBQueryError::getPageTitle() method.

Change-Id: I85d65d89e72b4497a050f440524ff6f959518b88

includes/exception/MWException.php

index 797d406..136fb89 100644 (file)
@@ -173,8 +173,7 @@ class MWException extends Exception {
         * @return string
         */
        public function getPageTitle() {
-               global $wgSitename;
-               return $this->msg( 'pagetitle', "$1 - $wgSitename", $this->msg( 'internalerror', 'Internal error' ) );
+               return $this->msg( 'internalerror', 'Internal error' );
        }
 
        /**
@@ -206,7 +205,7 @@ class MWException extends Exception {
         * Output the exception report using HTML.
         */
        public function reportHTML() {
-               global $wgOut;
+               global $wgOut, $wgSitename;
                if ( $this->useOutputPage() ) {
                        $wgOut->prepareErrorPage( $this->getPageTitle() );
 
@@ -222,7 +221,8 @@ class MWException extends Exception {
                        header( 'Content-Type: text/html; charset=utf-8' );
                        echo "<!DOCTYPE html>\n" .
                                '<html><head>' .
-                               '<title>' . htmlspecialchars( $this->getPageTitle() ) . '</title>' .
+                               // Mimick OutputPage::setPageTitle behaviour
+                               '<title>' . htmlspecialchars( $this->msg( 'pagetitle', "$1 - $wgSitename", $this->getPageTitle() ) ) . '</title>' .
                                '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
                                "</head><body>\n";