r101142 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101141‎ | r101142 | r101143 >
Date:15:45, 28 October 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
* 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
Modified paths:
  • /trunk/phase3/includes/Exception.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -1925,6 +1925,32 @@
19261926 }
19271927
19281928 /**
 1929+ * Prepare this object to display an error page; disable caching and
 1930+ * indexing, clear the current text and redirect, set the page's title
 1931+ * and optionally an custom HTML title (content of the <title> tag).
 1932+ *
 1933+ * @param $pageTitle String|Message will be passed directly to setPageTitle()
 1934+ * @param $htmlTitle String|Message will be passed directly to setHTMLTitle();
 1935+ * optional, if not passed the <title> attribute will be
 1936+ * based on $pageTitle
 1937+ */
 1938+ public function prepareErrorPage( $pageTitle, $htmlTitle = false ) {
 1939+ if ( $this->getTitle() ) {
 1940+ $this->mDebugtext .= 'Original title: ' . $this->getTitle()->getPrefixedText() . "\n";
 1941+ }
 1942+
 1943+ $this->setPageTitle( $pageTitle );
 1944+ if ( $htmlTitle !== false ) {
 1945+ $this->setHTMLTitle( $htmlTitle );
 1946+ }
 1947+ $this->setRobotPolicy( 'noindex,nofollow' );
 1948+ $this->setArticleRelated( false );
 1949+ $this->enableClientCache( false );
 1950+ $this->mRedirect = '';
 1951+ $this->clearHTML();
 1952+ }
 1953+
 1954+ /**
19291955 * Output a standard error page
19301956 *
19311957 * showErrorPage( 'titlemsg', 'pagetextmsg', array( 'param1', 'param2' ) );
@@ -1935,16 +1961,7 @@
19361962 * @param $params Array: message parameters; ignored if $msg is a Message object
19371963 */
19381964 public function showErrorPage( $title, $msg, $params = array() ) {
1939 - if ( $this->getTitle() ) {
1940 - $this->mDebugtext .= 'Original title: ' . $this->getTitle()->getPrefixedText() . "\n";
1941 - }
1942 - $this->setPageTitle( $this->msg( $title ) );
1943 - $this->setHTMLTitle( $this->msg( 'errorpagetitle' ) );
1944 - $this->setRobotPolicy( 'noindex,nofollow' );
1945 - $this->setArticleRelated( false );
1946 - $this->enableClientCache( false );
1947 - $this->mRedirect = '';
1948 - $this->mBodytext = '';
 1965+ $this->prepareErrorPage( $this->msg( $title ), $this->msg( 'errorpagetitle' ) );
19491966
19501967 if ( $msg instanceof Message ){
19511968 $this->addHTML( $msg->parse() );
@@ -1962,15 +1979,8 @@
19631980 * @param $action String: action that was denied or null if unknown
19641981 */
19651982 public function showPermissionsErrorPage( $errors, $action = null ) {
1966 - $this->mDebugtext .= 'Original title: ' .
1967 - $this->getTitle()->getPrefixedText() . "\n";
1968 - $this->setPageTitle( $this->msg( 'permissionserrors' ) );
1969 - $this->setHTMLTitle( $this->msg('permissionserrors' ) );
1970 - $this->setRobotPolicy( 'noindex,nofollow' );
1971 - $this->setArticleRelated( false );
1972 - $this->enableClientCache( false );
1973 - $this->mRedirect = '';
1974 - $this->mBodytext = '';
 1983+ $this->prepareErrorPage( $this->msg( 'permissionserrors' ), $this->msg( 'permissionserrors' ) );
 1984+
19751985 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) );
19761986 }
19771987
@@ -1981,11 +1991,7 @@
19821992 * @param $version Mixed: the version of MediaWiki needed to use the page
19831993 */
19841994 public function versionRequired( $version ) {
1985 - $this->setPageTitle( $this->msg( 'versionrequired' ) );
1986 - $this->setHTMLTitle( $this->msg( 'versionrequired', $version ) );
1987 - $this->setRobotPolicy( 'noindex,nofollow' );
1988 - $this->setArticleRelated( false );
1989 - $this->mBodytext = '';
 1995+ $this->prepareErrorPage( $this->msg( 'versionrequired', $version ) );
19901996
19911997 $this->addWikiMsg( 'versionrequiredtext', $version );
19921998 $this->returnToMain();
@@ -2008,14 +2014,10 @@
20092015 throw new PermissionsError( 'read' );
20102016 }
20112017
2012 - $this->setPageTitle( $this->msg( 'loginreqtitle' ) );
2013 - $this->setHTMLTitle( $this->msg( 'errorpagetitle' ) );
2014 - $this->setRobotPolicy( 'noindex,nofollow' );
2015 - $this->setArticleRelated( false );
 2018+ $this->prepareErrorPage( $this->msg( 'loginreqtitle' ), $this->msg( 'errorpagetitle' ) );
20162019
2017 - $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
20182020 $loginLink = Linker::linkKnown(
2019 - $loginTitle,
 2021+ SpecialPage::getTitleFor( 'Userlogin' ),
20202022 $this->msg( 'loginreqlink' )->escaped(),
20212023 array(),
20222024 array( 'returnto' => $this->getTitle()->getPrefixedText() )
@@ -2176,12 +2178,9 @@
21772179 }
21782180
21792181 public function showFatalError( $message ) {
2180 - $this->setPageTitle( $this->msg( 'internalerror' ) );
2181 - $this->setRobotPolicy( 'noindex,nofollow' );
2182 - $this->setArticleRelated( false );
2183 - $this->enableClientCache( false );
2184 - $this->mRedirect = '';
2185 - $this->mBodytext = $message;
 2182+ $this->prepareErrorPage( $this->msg( 'internalerror' ) );
 2183+
 2184+ $this->addHTML( $message );
21862185 }
21872186
21882187 public function showUnexpectedValueError( $name, $val ) {
Index: trunk/phase3/includes/Exception.php
@@ -138,8 +138,7 @@
139139 * @return String
140140 */
141141 function getPageTitle() {
142 - global $wgSitename;
143 - return $this->msg( 'internalerror', "$wgSitename error" );
 142+ return $this->msg( 'internalerror', "Internal error" );
144143 }
145144
146145 /**
@@ -171,12 +170,7 @@
172171 function reportHTML() {
173172 global $wgOut;
174173 if ( $this->useOutputPage() ) {
175 - $wgOut->setPageTitle( $this->getPageTitle() );
176 - $wgOut->setRobotPolicy( "noindex,nofollow" );
177 - $wgOut->setArticleRelated( false );
178 - $wgOut->enableClientCache( false );
179 - $wgOut->redirect( '' );
180 - $wgOut->clearHTML();
 174+ $wgOut->prepareErrorPage( $this->getPageTitle() );
181175
182176 $hookResult = $this->runHooks( get_class( $this ) );
183177 if ( $hookResult ) {

Comments

#Comment by Aaron Schulz (talk | contribs)   05:05, 17 December 2011

Nice.

Status & tagging log