From: Alexandre Emsenhuber Date: Fri, 28 Oct 2011 15:45:54 +0000 (+0000) Subject: * Factorise the code used to prepare the OutputPage object to display an error page... X-Git-Tag: 1.31.0-rc.0~26847 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=4b661607eb260fc270627b0265233dcbb6d69e97;p=lhc%2Fweb%2Fwiklou.git * Factorise the code used to prepare the OutputPage object to display an error page in OutputPage::prepareErrorPage() * Changed default value of OutputPage::getPageTitle() to match the value of the 'internalerror' message --- diff --git a/includes/Exception.php b/includes/Exception.php index 2e3dc636cc..b01d0d0e0c 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -138,8 +138,7 @@ class MWException extends Exception { * @return String */ function getPageTitle() { - global $wgSitename; - return $this->msg( 'internalerror', "$wgSitename error" ); + return $this->msg( 'internalerror', "Internal error" ); } /** @@ -171,12 +170,7 @@ class MWException extends Exception { function reportHTML() { global $wgOut; if ( $this->useOutputPage() ) { - $wgOut->setPageTitle( $this->getPageTitle() ); - $wgOut->setRobotPolicy( "noindex,nofollow" ); - $wgOut->setArticleRelated( false ); - $wgOut->enableClientCache( false ); - $wgOut->redirect( '' ); - $wgOut->clearHTML(); + $wgOut->prepareErrorPage( $this->getPageTitle() ); $hookResult = $this->runHooks( get_class( $this ) ); if ( $hookResult ) { diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 463cdaf059..13672e9cb1 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1924,6 +1924,32 @@ class OutputPage extends ContextSource { throw new UserBlockedError( $this->getUser()->mBlock ); } + /** + * Prepare this object to display an error page; disable caching and + * indexing, clear the current text and redirect, set the page's title + * and optionally an custom HTML title (content of the tag). + * + * @param $pageTitle String|Message will be passed directly to setPageTitle() + * @param $htmlTitle String|Message will be passed directly to setHTMLTitle(); + * optional, if not passed the <title> attribute will be + * based on $pageTitle + */ + public function prepareErrorPage( $pageTitle, $htmlTitle = false ) { + if ( $this->getTitle() ) { + $this->mDebugtext .= 'Original title: ' . $this->getTitle()->getPrefixedText() . "\n"; + } + + $this->setPageTitle( $pageTitle ); + if ( $htmlTitle !== false ) { + $this->setHTMLTitle( $htmlTitle ); + } + $this->setRobotPolicy( 'noindex,nofollow' ); + $this->setArticleRelated( false ); + $this->enableClientCache( false ); + $this->mRedirect = ''; + $this->clearHTML(); + } + /** * Output a standard error page * @@ -1935,16 +1961,7 @@ class OutputPage extends ContextSource { * @param $params Array: message parameters; ignored if $msg is a Message object */ public function showErrorPage( $title, $msg, $params = array() ) { - if ( $this->getTitle() ) { - $this->mDebugtext .= 'Original title: ' . $this->getTitle()->getPrefixedText() . "\n"; - } - $this->setPageTitle( $this->msg( $title ) ); - $this->setHTMLTitle( $this->msg( 'errorpagetitle' ) ); - $this->setRobotPolicy( 'noindex,nofollow' ); - $this->setArticleRelated( false ); - $this->enableClientCache( false ); - $this->mRedirect = ''; - $this->mBodytext = ''; + $this->prepareErrorPage( $this->msg( $title ), $this->msg( 'errorpagetitle' ) ); if ( $msg instanceof Message ){ $this->addHTML( $msg->parse() ); @@ -1962,15 +1979,8 @@ class OutputPage extends ContextSource { * @param $action String: action that was denied or null if unknown */ public function showPermissionsErrorPage( $errors, $action = null ) { - $this->mDebugtext .= 'Original title: ' . - $this->getTitle()->getPrefixedText() . "\n"; - $this->setPageTitle( $this->msg( 'permissionserrors' ) ); - $this->setHTMLTitle( $this->msg('permissionserrors' ) ); - $this->setRobotPolicy( 'noindex,nofollow' ); - $this->setArticleRelated( false ); - $this->enableClientCache( false ); - $this->mRedirect = ''; - $this->mBodytext = ''; + $this->prepareErrorPage( $this->msg( 'permissionserrors' ), $this->msg( 'permissionserrors' ) ); + $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) ); } @@ -1981,11 +1991,7 @@ class OutputPage extends ContextSource { * @param $version Mixed: the version of MediaWiki needed to use the page */ public function versionRequired( $version ) { - $this->setPageTitle( $this->msg( 'versionrequired' ) ); - $this->setHTMLTitle( $this->msg( 'versionrequired', $version ) ); - $this->setRobotPolicy( 'noindex,nofollow' ); - $this->setArticleRelated( false ); - $this->mBodytext = ''; + $this->prepareErrorPage( $this->msg( 'versionrequired', $version ) ); $this->addWikiMsg( 'versionrequiredtext', $version ); $this->returnToMain(); @@ -2008,14 +2014,10 @@ class OutputPage extends ContextSource { throw new PermissionsError( 'read' ); } - $this->setPageTitle( $this->msg( 'loginreqtitle' ) ); - $this->setHTMLTitle( $this->msg( 'errorpagetitle' ) ); - $this->setRobotPolicy( 'noindex,nofollow' ); - $this->setArticleRelated( false ); + $this->prepareErrorPage( $this->msg( 'loginreqtitle' ), $this->msg( 'errorpagetitle' ) ); - $loginTitle = SpecialPage::getTitleFor( 'Userlogin' ); $loginLink = Linker::linkKnown( - $loginTitle, + SpecialPage::getTitleFor( 'Userlogin' ), $this->msg( 'loginreqlink' )->escaped(), array(), array( 'returnto' => $this->getTitle()->getPrefixedText() ) @@ -2176,12 +2178,9 @@ $templates } public function showFatalError( $message ) { - $this->setPageTitle( $this->msg( 'internalerror' ) ); - $this->setRobotPolicy( 'noindex,nofollow' ); - $this->setArticleRelated( false ); - $this->enableClientCache( false ); - $this->mRedirect = ''; - $this->mBodytext = $message; + $this->prepareErrorPage( $this->msg( 'internalerror' ) ); + + $this->addHTML( $message ); } public function showUnexpectedValueError( $name, $val ) {