* Added HttpError exception as replacement for wfHttpError(); changed alls core calls to it except AjaxDispatcher.php
* Changed FeedUtils' call to it to be similar than feeds are completely disabled * Use local context instead of global variables in Special:Userlogout
This commit is contained in:
parent
d8957aca62
commit
ec9b551ca9
7 changed files with 69 additions and 24 deletions
|
|
@ -366,6 +366,55 @@ class UserBlockedError extends ErrorPageError {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an error that looks like an HTTP server error.
|
||||
* Replacement for wfHttpError().
|
||||
*
|
||||
* @ingroup Exception
|
||||
*/
|
||||
class HttpError extends MWException {
|
||||
private $httpCode, $header, $content;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param $httpCode Integer: HTTP status code to send to the client
|
||||
* @param $content String|Message: content of the message
|
||||
* @param $header String|Message: content of the header (\<title\> and \<h1\>)
|
||||
*/
|
||||
public function __construct( $httpCode, $content, $header = null ){
|
||||
parent::__construct( $content );
|
||||
$this->httpCode = (int)$httpCode;
|
||||
$this->header = $header;
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function reportHTML() {
|
||||
$httpMessage = HttpStatus::getMessage( $this->httpCode );
|
||||
|
||||
header( "Status: {$this->httpCode} {$httpMessage}" );
|
||||
header( 'Content-type: text/html; charset=utf-8' );
|
||||
|
||||
if ( $this->header === null ) {
|
||||
$header = $httpMessage;
|
||||
} elseif ( $this->header instanceof Message ) {
|
||||
$header = $this->header->escaped();
|
||||
} else {
|
||||
$header = htmlspecialchars( $this->header );
|
||||
}
|
||||
|
||||
if ( $this->content instanceof Message ) {
|
||||
$content = $this->content->escaped();
|
||||
} else {
|
||||
$content = htmlspecialchars( $this->content );
|
||||
}
|
||||
|
||||
print "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n".
|
||||
"<html><head><title>$header</title></head>\n" .
|
||||
"<body><h1>$header</h1><p>$content</p></body></html>\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler class for MWExceptions
|
||||
* @ingroup Exception
|
||||
|
|
|
|||
|
|
@ -31,16 +31,15 @@ class FeedUtils {
|
|||
* @return Boolean
|
||||
*/
|
||||
public static function checkFeedOutput( $type ) {
|
||||
global $wgFeed, $wgFeedClasses;
|
||||
global $wgOut, $wgFeed, $wgFeedClasses;
|
||||
|
||||
if ( !$wgFeed ) {
|
||||
global $wgOut;
|
||||
$wgOut->addWikiMsg( 'feed-unavailable' );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !isset( $wgFeedClasses[$type] ) ) {
|
||||
wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
|
||||
$wgOut->addWikiMsg( 'feed-invalid' );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,14 +41,13 @@ abstract class RdfMetaData {
|
|||
$rdftype = wfNegotiateType( wfAcceptToPrefs( $httpaccept ), wfAcceptToPrefs( self::RDF_TYPE_PREFS ) );
|
||||
|
||||
if( !$rdftype ){
|
||||
wfHttpError( 406, 'Not Acceptable', wfMsg( 'notacceptable' ) );
|
||||
return false;
|
||||
} else {
|
||||
$wgOut->disable();
|
||||
$wgRequest->response()->header( "Content-type: {$rdftype}; charset=utf-8" );
|
||||
$wgOut->sendCacheControl();
|
||||
return true;
|
||||
throw new HttpError( 406, wfMessage( 'notacceptable' ) );
|
||||
}
|
||||
|
||||
$wgOut->disable();
|
||||
$wgRequest->response()->header( "Content-type: {$rdftype}; charset=utf-8" );
|
||||
$wgOut->sendCacheControl();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function reallyFullUrl() {
|
||||
|
|
|
|||
|
|
@ -874,7 +874,7 @@ class WebRequest {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
wfHttpError( 403, 'Forbidden',
|
||||
throw new HttpError( 403,
|
||||
'Invalid file extension found in the path info or query string.' );
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ class MediaWiki {
|
|||
"\$wgArticlePath setting and/or toggle \$wgUsePathInfo " .
|
||||
"to true.";
|
||||
}
|
||||
wfHttpError( 500, "Internal error", $message );
|
||||
throw new HttpError( 500, $message );
|
||||
} else {
|
||||
$output->setSquidMaxage( 1200 );
|
||||
$output->redirect( $targetUrl, '301' );
|
||||
|
|
|
|||
|
|
@ -95,8 +95,7 @@ class SpecialUploadStash extends UnlistedSpecialPage {
|
|||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
wfHttpError( $code, HttpStatus::getMessage( $code ), $message );
|
||||
return false;
|
||||
throw new HttpError( $code, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -33,31 +33,30 @@ class SpecialUserlogout extends UnlistedSpecialPage {
|
|||
}
|
||||
|
||||
function execute( $par ) {
|
||||
global $wgUser, $wgOut;
|
||||
|
||||
/**
|
||||
* Some satellite ISPs use broken precaching schemes that log people out straight after
|
||||
* they're logged in (bug 17790). Luckily, there's a way to detect such requests.
|
||||
*/
|
||||
if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], '&' ) !== false ) {
|
||||
wfDebug( "Special:Userlogout request {$_SERVER['REQUEST_URI']} looks suspicious, denying.\n" );
|
||||
wfHttpError( 400, wfMsg( 'loginerror' ), wfMsg( 'suspicious-userlogout' ) );
|
||||
return;
|
||||
throw new HttpError( 400, wfMessage( 'suspicious-userlogout' ), wfMessage( 'loginerror' ) );
|
||||
}
|
||||
|
||||
$this->setHeaders();
|
||||
$this->outputHeader();
|
||||
|
||||
$oldName = $wgUser->getName();
|
||||
$wgUser->logout();
|
||||
$user = $this->getUser();
|
||||
$oldName = $user->getName();
|
||||
$user->logout();
|
||||
|
||||
$wgOut->addWikiMsg( 'logouttext' );
|
||||
$out = $this->getOutput();
|
||||
$out->addWikiMsg( 'logouttext' );
|
||||
|
||||
// Hook.
|
||||
$injected_html = '';
|
||||
wfRunHooks( 'UserLogoutComplete', array( &$wgUser, &$injected_html, $oldName ) );
|
||||
$wgOut->addHTML( $injected_html );
|
||||
wfRunHooks( 'UserLogoutComplete', array( &$user, &$injected_html, $oldName ) );
|
||||
$out->addHTML( $injected_html );
|
||||
|
||||
$wgOut->returnToMain();
|
||||
$out->returnToMain();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue