X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdb%2FDatabaseError.php;h=fef47849fcbece00ed46fee0af3073d2eea389de;hb=d6cf8c57b4f5b0fdab7010a2e58a4baaec56f42f;hp=4838d02caaa4aa3216ac6393e921e4b0832c4286;hpb=51a0d537584ab8b1c1fd695b5b15c3d4f12c0457;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/db/DatabaseError.php b/includes/db/DatabaseError.php index 4838d02caa..fef47849fc 100644 --- a/includes/db/DatabaseError.php +++ b/includes/db/DatabaseError.php @@ -17,7 +17,7 @@ class DBError extends MWException { * @param $error String A simple error message to be used for debugging */ function __construct( DatabaseBase &$db, $error ) { - $this->db =& $db; + $this->db = $db; parent::__construct( $error ); } @@ -82,11 +82,19 @@ class DBConnectionError extends DBError { parent::__construct( $db, $msg ); } + /** + * @return bool + */ function useOutputPage() { // Not likely to work return false; } + /** + * @param $key + * @param $fallback + * @return string + */ function msg( $key, $fallback /*[, params...] */ ) { global $wgLang; @@ -100,6 +108,9 @@ class DBConnectionError extends DBError { return wfMsgReplaceArgs( $message, $args ); } + /** + * @return bool + */ function getLogMessage() { # Don't send to the exception log return false; @@ -171,20 +182,20 @@ class DBConnectionError extends DBError { } # We can't, cough and die in the usual fashion - return parent::reportHTML(); + parent::reportHTML(); } /** * @return string */ function searchForm() { - global $wgSitename, $wgServer; + global $wgSitename, $wgServer, $wgRequest; $usegoogle = htmlspecialchars( $this->msg( 'dberr-usegoogle', 'You can try searching via Google in the meantime.' ) ); $outofdate = htmlspecialchars( $this->msg( 'dberr-outofdate', 'Note that their indexes of our content may be out of date.' ) ); $googlesearch = htmlspecialchars( $this->msg( 'searchbutton', 'Search' ) ); - $search = htmlspecialchars( @$_REQUEST['search'] ); + $search = htmlspecialchars( $wgRequest->getVal( 'search' ) ); $server = htmlspecialchars( $wgServer ); $sitename = htmlspecialchars( $wgSitename ); @@ -193,7 +204,7 @@ class DBConnectionError extends DBError {
$usegoogle
$outofdate
-
+ @@ -215,21 +226,28 @@ EOT; * @return string */ private function fileCachedPage() { - global $wgTitle, $wgOut; + global $wgTitle, $wgOut, $wgRequest; if ( $wgOut->isDisabled() ) { - return; // Done already? + return ''; // Done already? } - if ( $wgTitle ) { - $t =& $wgTitle; + if ( $wgTitle ) { // use $wgTitle if we managed to set it + $t = $wgTitle->getPrefixedDBkey(); } else { - $t = Title::newFromText( $this->msg( 'mainpage', 'Main Page' ) ); + # Fallback to the raw title URL param. We can't use the Title + # class is it may hit the interwiki table and give a DB error. + # We may get a cache miss due to not sanitizing the title though. + $t = str_replace( ' ', '_', $wgRequest->getVal( 'title' ) ); + if ( $t == '' ) { // fallback to main page + $t = Title::newFromText( + $this->msg( 'mainpage', 'Main Page' ) )->getPrefixedDBkey(); + } } - $cache = new HTMLFileCache( $t ); - if ( $cache->isFileCached() ) { - return $cache->fetchPageText(); + $cache = HTMLFileCache::newFromTitle( $t, 'view' ); + if ( $cache->isCached() ) { + return $cache->fetchText(); } else { return ''; } @@ -242,8 +260,15 @@ EOT; class DBQueryError extends DBError { public $error, $errno, $sql, $fname; + /** + * @param $db DatabaseBase + * @param $error + * @param $errno + * @param $sql + * @param $fname + */ function __construct( DatabaseBase &$db, $error, $errno, $sql, $fname ) { - $message = "A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: http://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" . + $message = "A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" . "Query: $sql\n" . "Function: $fname\n" . "Error: $errno $error\n"; @@ -265,13 +290,18 @@ class DBQueryError extends DBError { */ function getContentMessage( $html ) { if ( $this->useMessageCache() ) { - $msg = $html ? 'dberrortext' : 'dberrortextcl'; - $ret = wfMsg( $msg, $this->getSQL(), - $this->fname, $this->errno, $this->error ); if ( $html ) { - $ret = htmlspecialchars( $ret ); + $msg = 'dberrortext'; + $sql = htmlspecialchars( $this->getSQL() ); + $fname = htmlspecialchars( $this->fname ); + $error = htmlspecialchars( $this->error ); + } else { + $msg = 'dberrortextcl'; + $sql = $this->getSQL(); + $fname = $this->fname; + $error = $this->error; } - return $ret; + return wfMsg( $msg, $sql, $fname, $this->errno, $error ); } else { return parent::getContentMessage( $html ); } @@ -290,6 +320,9 @@ class DBQueryError extends DBError { } } + /** + * @return bool + */ function getLogMessage() { # Don't send to the exception log return false;