}
/**
+ * An error page which can definitely be safely rendered using the OutputPage
* @ingroup Exception
*/
class ErrorPageError extends MWException {
- public $title, $msg;
+ public $title, $msg, $params;
/**
* Note: these arguments are keys into wfMsg(), not text!
*/
- function __construct( $title, $msg ) {
+ function __construct( $title, $msg, $params = null ) {
$this->title = $title;
$this->msg = $msg;
+ $this->params = $params;
parent::__construct( wfMsg( $msg ) );
}
function report() {
global $wgOut;
- $wgOut->showErrorPage( $this->title, $this->msg );
+ $wgOut->showErrorPage( $this->title, $this->msg, $this->params );
$wgOut->output();
}
}
+/**
+ * Show an error when a user tries to do something they do not have the necessary
+ * permissions for.
+ */
+class PermissionsError extends ErrorPageError {
+ public $permission;
+
+ function __construct( $permission ) {
+ global $wgLang;
+
+ $this->permission = $permission;
+
+ $groups = array_map(
+ array( 'User', 'makeGroupLinkWiki' ),
+ User::getGroupsWithPermission( $this->permission )
+ );
+
+ if( $groups ) {
+ parent::__construct(
+ 'badaccess',
+ 'badaccess-groups',
+ array(
+ $wgLang->commaList( $groups ),
+ count( $groups )
+ )
+ );
+ } else {
+ parent::__construct(
+ 'badaccess',
+ 'badaccess-group0'
+ );
+ }
+ }
+}
+
/**
* Install an exception handler for MediaWiki exception types.
*/