* Add a new hook getUserPermissionsErrors, which is a more modern version of the...
authorAndrew Garrett <werdna@users.mediawiki.org>
Wed, 10 Oct 2007 09:56:47 +0000 (09:56 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Wed, 10 Oct 2007 09:56:47 +0000 (09:56 +0000)
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.

RELEASE-NOTES
docs/hooks.txt
includes/Title.php

index 5a51f4e..4823adc 100644 (file)
@@ -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 ===
index 9999e58..a7b371e 100644 (file)
@@ -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
index 56fe475..2857959 100644 (file)
@@ -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');
                }