From: Andrew Garrett Date: Wed, 10 Oct 2007 09:56:47 +0000 (+0000) Subject: * Add a new hook getUserPermissionsErrors, which is a more modern version of the... X-Git-Tag: 1.31.0-rc.0~51183 X-Git-Url: https://git.cyclocoop.org/admin/%7B%7Blocalurl:Special:UserLogin%7D%7D?a=commitdiff_plain;h=1e0651dce79e80e3ac325c293811f5fd6300f4b9;p=lhc%2Fweb%2Fwiklou.git * Add a new hook getUserPermissionsErrors, which is a more modern version of the userCan hook. userCan hook marked as deprecated, as this one allows you to actually say to the user WHY they can't edit an article, as opposed to just that they can't. As a side-note, magic_quotes_gpc sucks. Two file-saves with it on, and I spent 45 minutes fixing it up, with a hacky perl script. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 5a51f4eaec..4823adc3a3 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -92,6 +92,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 11574) Add an interface message loginstart, which, similarly to loginend, appears just before the login form. Patch by MinuteElectron. * Do not cache category pages if using 'from' or 'until' +* Created new hook getUserPermissionsErrors, to go with my userCan changes from ages ago. === API changes in 1.12 === diff --git a/docs/hooks.txt b/docs/hooks.txt index 9999e587d1..a7b371ee27 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -494,6 +494,14 @@ $title: Title object of page $url: string value as output (out parameter, can modify) $query: query options passed to Title::getFullURL() +'getUserPermissionsErrors': Add a permissions error when permissions errors are checked for. + Use instead of userCan for most cases. Return false if the user can't do it, + and populate $result with the reason in the form of array( messagename, param1, param2 ) +$title: Title object being checked against +$user : Current user object +$action: Action being checked +$result: User permissions error to add. If none, return true. + 'ImageOpenShowImageInlineBefore': Call potential extension just before showing the image on an image page $imagePage: ImagePage object ($this) $output: $wgOut @@ -688,12 +696,13 @@ string &$error: output: HTML error to show if upload canceled by returning false 'UploadComplete': Upon completion of a file upload $image: Image object representing the file that was uploaded -'UserCan': To interrupt/advise the "user can do X to Y article" check +'UserCan': To interrupt/advise the "user can do X to Y article" check. + If you want to display an error message, try getUserPermissionsErrors. $title: Title object being checked against $user : Current user object $action: Action being checked $result: Pointer to result returned if hook returns false. If null is returned, - UserCan checks are continued by internal code + UserCan checks are continued by internal code. 'UserCreateForm': change to manipulate the login form $template: SimpleTemplate instance for the form diff --git a/includes/Title.php b/includes/Title.php index 56fe475262..2857959afa 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1109,10 +1109,22 @@ class Title { $errors = array(); + // Use getUserPermissionsErrors instead if ( !wfRunHooks( 'userCan', array( &$this, &$user, $action, &$result ) ) ) { return $result ? array() : array( array( 'badaccess-group0' ) ); } + if (!wfRunHooks( 'getUserPermissionsErrors', array( &$this, &$user, $action, &$result ) ) ) { + if ($result != array() && is_array($result) && !is_array($result[0])) + $errors[] = $result; # A single array representing an error + else if (is_array($result) && is_array($result([0]))) + $errors = array_merge( $errors, $result ); # A nested array representing multiple errors + else if ($result != '' && $result != null && $result !== true && $result !== false) + $errors[] = array($result); # A string representing a message-id + else if ($result === false ) + $errors[] = array('badaccess-group0'); # a generic "We don't want them to do that" + } + if( NS_SPECIAL == $this->mNamespace ) { $errors[] = array('ns-specialprotected'); }