* Cleanup for r108175: made if easier for extensions to interact with each other...
authorAaron Schulz <aaron@users.mediawiki.org>
Fri, 6 Jan 2012 06:16:05 +0000 (06:16 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Fri, 6 Jan 2012 06:16:05 +0000 (06:16 +0000)
* Added some hook doc comments.

docs/hooks.txt
includes/GlobalFunctions.php
includes/Hooks.php
includes/Title.php

index b1a153c..b5d0ad5 100644 (file)
@@ -1928,11 +1928,10 @@ $redirid: database ID of the created redirect
 
 'TitleReadWhitelist': called at the end of read permissions checks, just before
        adding the default error message if nothing allows the user to read the page.
-       Return false will prevent core from adding its error message, but you need
-       to removed extensions' error messages from $errors yourself.
+       If a handler wants a title to *not* be whitelisted, it should also return false.
 $title: Title object being checked against
 $user: Current user object
-&$errors: errors 
+&$whitelisted: Boolean value of whether this title is whitelisted
 
 'UndeleteForm::showHistory': called in UndeleteForm::showHistory, after a
 PageArchive object has been created but before any further processing is done.
index 231dc65..db2ff35 100644 (file)
@@ -3754,7 +3754,7 @@ function wfGetParserCacheStorage() {
  *
  * @param $event String: event name
  * @param $args Array: parameters passed to hook functions
- * @return Boolean
+ * @return Boolean True if no handler aborted the hook
  */
 function wfRunHooks( $event, $args = array() ) {
        return Hooks::run( $event, $args );
index bfec82e..e1c1d50 100644 (file)
@@ -86,7 +86,7 @@ class Hooks {
         *
         * @param $event String: event name
         * @param $args Array: parameters passed to hook functions
-        * @return Boolean
+        * @return Boolean True if no handler aborted the hook
         */
        public static function run( $event, $args = array() ) {
                global $wgHooks;
index 86aa4ee..cb36e1a 100644 (file)
@@ -1965,12 +1965,11 @@ class Title {
         * @return Array list of errors
         */
        private function checkReadPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
-               global $wgWhitelistRead;
+               global $wgWhitelistRead, $wgGroupPermissions, $wgRevokePermissions;;
                static $useShortcut = null;
 
                # Initialize the $useShortcut boolean, to determine if we can skip quite a bit of code below
                if ( is_null( $useShortcut ) ) {
-                       global $wgGroupPermissions, $wgRevokePermissions;
                        $useShortcut = true;
                        if ( empty( $wgGroupPermissions['*']['read'] ) ) {
                                # Not a public wiki, so no shortcut
@@ -1993,7 +1992,6 @@ class Title {
                }
 
                $whitelisted = false;
-
                if ( $useShortcut ) {
                        # Shortcut for public wikis, allows skipping quite a bit of code
                        $whitelisted = true;
@@ -2036,11 +2034,12 @@ class Title {
                        }
                }
 
-               # If the user is allowed to read tge page; don't call the hook
-               if ( $whitelisted && !count( $errors ) ) {
-                       return array();
-               } elseif ( wfRunHooks( 'TitleReadWhitelist', array( $this, $user, &$errors ) ) && !$whitelisted ) {
-                       $errors[] = $this->missingPermissionError( $action, $short );
+               if ( !$whitelisted ) {
+                       # If the title is not whitelisted, give extensions a chance to do so...
+                       wfRunHooks( 'TitleReadWhitelist', array( $this, $user, &$whitelisted ) );
+                       if ( !$whitelisted ) {
+                               $errors[] = $this->missingPermissionError( $action, $short );
+                       }
                }
 
                return $errors;