Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -2044,28 +2044,11 @@ |
2045 | 2045 | |
2046 | 2046 | /** |
2047 | 2047 | * Display an error page noting that a given permission bit is required. |
2048 | | - * |
| 2048 | + * @deprecated since 1.18, just throw the exception directly |
2049 | 2049 | * @param $permission String: key required |
2050 | 2050 | */ |
2051 | 2051 | public function permissionRequired( $permission ) { |
2052 | | - $this->setPageTitle( wfMsg( 'badaccess' ) ); |
2053 | | - $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) ); |
2054 | | - $this->setRobotPolicy( 'noindex,nofollow' ); |
2055 | | - $this->setArticleRelated( false ); |
2056 | | - $this->mBodytext = ''; |
2057 | | - |
2058 | | - $groups = array_map( array( 'User', 'makeGroupLinkWiki' ), |
2059 | | - User::getGroupsWithPermission( $permission ) ); |
2060 | | - if( $groups ) { |
2061 | | - $this->addWikiMsg( |
2062 | | - 'badaccess-groups', |
2063 | | - $this->getContext()->getLang()->commaList( $groups ), |
2064 | | - count( $groups ) |
2065 | | - ); |
2066 | | - } else { |
2067 | | - $this->addWikiMsg( 'badaccess-group0' ); |
2068 | | - } |
2069 | | - $this->returnToMain(); |
| 2052 | + throw new PermissionsError( $permission ); |
2070 | 2053 | } |
2071 | 2054 | |
2072 | 2055 | /** |
— | — | @@ -2073,8 +2056,7 @@ |
2074 | 2057 | */ |
2075 | 2058 | public function loginToUse() { |
2076 | 2059 | if( $this->getUser()->isLoggedIn() ) { |
2077 | | - $this->permissionRequired( 'read' ); |
2078 | | - return; |
| 2060 | + throw new PermissionsError( 'read' ); |
2079 | 2061 | } |
2080 | 2062 | |
2081 | 2063 | $this->setPageTitle( wfMsg( 'loginreqtitle' ) ); |
Index: trunk/phase3/includes/Exception.php |
— | — | @@ -311,29 +311,66 @@ |
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
| 315 | + * An error page which can definitely be safely rendered using the OutputPage |
315 | 316 | * @ingroup Exception |
316 | 317 | */ |
317 | 318 | class ErrorPageError extends MWException { |
318 | | - public $title, $msg; |
| 319 | + public $title, $msg, $params; |
319 | 320 | |
320 | 321 | /** |
321 | 322 | * Note: these arguments are keys into wfMsg(), not text! |
322 | 323 | */ |
323 | | - function __construct( $title, $msg ) { |
| 324 | + function __construct( $title, $msg, $params = null ) { |
324 | 325 | $this->title = $title; |
325 | 326 | $this->msg = $msg; |
| 327 | + $this->params = $params; |
326 | 328 | parent::__construct( wfMsg( $msg ) ); |
327 | 329 | } |
328 | 330 | |
329 | 331 | function report() { |
330 | 332 | global $wgOut; |
331 | 333 | |
332 | | - $wgOut->showErrorPage( $this->title, $this->msg ); |
| 334 | + $wgOut->showErrorPage( $this->title, $this->msg, $this->params ); |
333 | 335 | $wgOut->output(); |
334 | 336 | } |
335 | 337 | } |
336 | 338 | |
337 | 339 | /** |
| 340 | + * Show an error when a user tries to do something they do not have the necessary |
| 341 | + * permissions for. |
| 342 | + */ |
| 343 | +class PermissionsError extends ErrorPageError { |
| 344 | + public $permission; |
| 345 | + |
| 346 | + function __construct( $permission ) { |
| 347 | + global $wgLang; |
| 348 | + |
| 349 | + $this->permission = $permission; |
| 350 | + |
| 351 | + $groups = array_map( |
| 352 | + array( 'User', 'makeGroupLinkWiki' ), |
| 353 | + User::getGroupsWithPermission( $this->permission ) |
| 354 | + ); |
| 355 | + |
| 356 | + if( $groups ) { |
| 357 | + parent::__construct( |
| 358 | + 'badaccess', |
| 359 | + 'badaccess-groups', |
| 360 | + array( |
| 361 | + $wgLang->commaList( $groups ), |
| 362 | + count( $groups ) |
| 363 | + ) |
| 364 | + ); |
| 365 | + } else { |
| 366 | + parent::__construct( |
| 367 | + 'badaccess', |
| 368 | + 'badaccess-group0' |
| 369 | + ); |
| 370 | + } |
| 371 | + } |
| 372 | +} |
| 373 | + |
| 374 | +/** |
338 | 375 | * Install an exception handler for MediaWiki exception types. |
339 | 376 | */ |
340 | 377 | function wfInstallExceptionHandler() { |