r95683 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95682‎ | r95683 | r95684 >
Date:18:54, 29 August 2011
Author:neilk
Status:ok (Comments)
Tags:
Comment:
add a few subclasses of ErrorPageError. PermissionsError, ReadOnlyError, ThrottledError. Allow for Message objects as arguments to ErrorPageError. Needed to make WikiLovesMonuments / UploadWizard Campaigns work
Modified paths:
  • /branches/wmf/1.17wmf1/includes/Exception.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/includes/Exception.php
@@ -283,29 +283,122 @@
284284 }
285285
286286 /**
 287+ * An error page which can definitely be safely rendered using the OutputPage
287288 * @ingroup Exception
288289 */
289290 class ErrorPageError extends MWException {
290 - public $title, $msg;
 291+ public $title, $msg, $params;
291292
292293 /**
293294 * Note: these arguments are keys into wfMsg(), not text!
294295 */
295 - function __construct( $title, $msg ) {
 296+ function __construct( $title, $msg, $params = null ) {
296297 $this->title = $title;
297298 $this->msg = $msg;
298 - parent::__construct( wfMsg( $msg ) );
 299+ $this->params = $params;
 300+
 301+ if( $msg instanceof Message ){
 302+ parent::__construct( $msg );
 303+ } else {
 304+ parent::__construct( wfMsg( $msg ) );
 305+ }
299306 }
300307
301308 function report() {
302309 global $wgOut;
303310
304 - $wgOut->showErrorPage( $this->title, $this->msg );
 311+ if ( $wgOut->getTitle() ) {
 312+ $wgOut->debug( 'Original title: ' . $wgOut->getTitle()->getPrefixedText() . "\n" );
 313+ }
 314+ $wgOut->setPageTitle( wfMsg( $this->title ) );
 315+ $wgOut->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
 316+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
 317+ $wgOut->setArticleRelated( false );
 318+ $wgOut->enableClientCache( false );
 319+ $wgOut->mRedirect = '';
 320+ $wgOut->clearHTML();
 321+
 322+ if( $this->msg instanceof Message ){
 323+ $wgOut->addHTML( $this->msg->parse() );
 324+ } else {
 325+ $wgOut->addWikiMsgArray( $this->msg, $this->params );
 326+ }
 327+
 328+ $wgOut->returnToMain();
305329 $wgOut->output();
306330 }
307331 }
308332
309333 /**
 334+ * Show an error when a user tries to do something they do not have the necessary
 335+ * permissions for.
 336+ * @ingroup Exception
 337+ */
 338+class PermissionsError extends ErrorPageError {
 339+ public $permission;
 340+
 341+ function __construct( $permission ) {
 342+ global $wgLang;
 343+
 344+ $this->permission = $permission;
 345+
 346+ $groups = array_map(
 347+ array( 'User', 'makeGroupLinkWiki' ),
 348+ User::getGroupsWithPermission( $this->permission )
 349+ );
 350+
 351+ if( $groups ) {
 352+ parent::__construct(
 353+ 'badaccess',
 354+ 'badaccess-groups',
 355+ array(
 356+ $wgLang->commaList( $groups ),
 357+ count( $groups )
 358+ )
 359+ );
 360+ } else {
 361+ parent::__construct(
 362+ 'badaccess',
 363+ 'badaccess-group0'
 364+ );
 365+ }
 366+ }
 367+}
 368+
 369+/**
 370+ * Show an error when the wiki is locked/read-only and the user tries to do
 371+ * something that requires write access
 372+ * @ingroup Exception
 373+ */
 374+class ReadOnlyError extends ErrorPageError {
 375+ public function __construct(){
 376+ parent::__construct(
 377+ 'readonly',
 378+ 'readonlytext',
 379+ wfReadOnlyReason()
 380+ );
 381+ }
 382+}
 383+
 384+/**
 385+ * Show an error when the user hits a rate limit
 386+ * @ingroup Exception
 387+ */
 388+class ThrottledError extends ErrorPageError {
 389+ public function __construct(){
 390+ parent::__construct(
 391+ 'actionthrottled',
 392+ 'actionthrottledtext'
 393+ );
 394+ }
 395+ public function report(){
 396+ global $wgOut;
 397+ $wgOut->setStatusCode( 503 );
 398+ return parent::report();
 399+ }
 400+}
 401+
 402+/**
310403 * Install an exception handler for MediaWiki exception types.
311404 */
312405 function wfInstallExceptionHandler() {

Comments

#Comment by 😂 (talk | contribs)   19:37, 30 August 2011

Are there related trunk revs for this?

Status & tagging log