Index: branches/wmf/1.17wmf1/includes/Exception.php |
— | — | @@ -283,29 +283,122 @@ |
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
| 287 | + * An error page which can definitely be safely rendered using the OutputPage |
287 | 288 | * @ingroup Exception |
288 | 289 | */ |
289 | 290 | class ErrorPageError extends MWException { |
290 | | - public $title, $msg; |
| 291 | + public $title, $msg, $params; |
291 | 292 | |
292 | 293 | /** |
293 | 294 | * Note: these arguments are keys into wfMsg(), not text! |
294 | 295 | */ |
295 | | - function __construct( $title, $msg ) { |
| 296 | + function __construct( $title, $msg, $params = null ) { |
296 | 297 | $this->title = $title; |
297 | 298 | $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 | + } |
299 | 306 | } |
300 | 307 | |
301 | 308 | function report() { |
302 | 309 | global $wgOut; |
303 | 310 | |
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(); |
305 | 329 | $wgOut->output(); |
306 | 330 | } |
307 | 331 | } |
308 | 332 | |
309 | 333 | /** |
| 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 | +/** |
310 | 403 | * Install an exception handler for MediaWiki exception types. |
311 | 404 | */ |
312 | 405 | function wfInstallExceptionHandler() { |