r108193 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108192‎ | r108193 | r108194 >
Date:06:16, 6 January 2012
Author:aaron
Status:ok
Tags:
Comment:
* Cleanup for r108175: made if easier for extensions to interact with each other in TitleReadWhitelist hook. A handler can set $whitelisted to true to whitelist the page or it can set it to false and return false (most restrictive wins).
* Added some hook doc comments.
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Hooks.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -1928,11 +1928,10 @@
19291929
19301930 'TitleReadWhitelist': called at the end of read permissions checks, just before
19311931 adding the default error message if nothing allows the user to read the page.
1932 - Return false will prevent core from adding its error message, but you need
1933 - to removed extensions' error messages from $errors yourself.
 1932+ If a handler wants a title to *not* be whitelisted, it should also return false.
19341933 $title: Title object being checked against
19351934 $user: Current user object
1936 -&$errors: errors
 1935+&$whitelisted: Boolean value of whether this title is whitelisted
19371936
19381937 'UndeleteForm::showHistory': called in UndeleteForm::showHistory, after a
19391938 PageArchive object has been created but before any further processing is done.
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -3754,7 +3754,7 @@
37553755 *
37563756 * @param $event String: event name
37573757 * @param $args Array: parameters passed to hook functions
3758 - * @return Boolean
 3758+ * @return Boolean True if no handler aborted the hook
37593759 */
37603760 function wfRunHooks( $event, $args = array() ) {
37613761 return Hooks::run( $event, $args );
Index: trunk/phase3/includes/Hooks.php
@@ -86,7 +86,7 @@
8787 *
8888 * @param $event String: event name
8989 * @param $args Array: parameters passed to hook functions
90 - * @return Boolean
 90+ * @return Boolean True if no handler aborted the hook
9191 */
9292 public static function run( $event, $args = array() ) {
9393 global $wgHooks;
Index: trunk/phase3/includes/Title.php
@@ -1965,12 +1965,11 @@
19661966 * @return Array list of errors
19671967 */
19681968 private function checkReadPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
1969 - global $wgWhitelistRead;
 1969+ global $wgWhitelistRead, $wgGroupPermissions, $wgRevokePermissions;;
19701970 static $useShortcut = null;
19711971
19721972 # Initialize the $useShortcut boolean, to determine if we can skip quite a bit of code below
19731973 if ( is_null( $useShortcut ) ) {
1974 - global $wgGroupPermissions, $wgRevokePermissions;
19751974 $useShortcut = true;
19761975 if ( empty( $wgGroupPermissions['*']['read'] ) ) {
19771976 # Not a public wiki, so no shortcut
@@ -1993,7 +1992,6 @@
19941993 }
19951994
19961995 $whitelisted = false;
1997 -
19981996 if ( $useShortcut ) {
19991997 # Shortcut for public wikis, allows skipping quite a bit of code
20001998 $whitelisted = true;
@@ -2036,11 +2034,12 @@
20372035 }
20382036 }
20392037
2040 - # If the user is allowed to read tge page; don't call the hook
2041 - if ( $whitelisted && !count( $errors ) ) {
2042 - return array();
2043 - } elseif ( wfRunHooks( 'TitleReadWhitelist', array( $this, $user, &$errors ) ) && !$whitelisted ) {
2044 - $errors[] = $this->missingPermissionError( $action, $short );
 2038+ if ( !$whitelisted ) {
 2039+ # If the title is not whitelisted, give extensions a chance to do so...
 2040+ wfRunHooks( 'TitleReadWhitelist', array( $this, $user, &$whitelisted ) );
 2041+ if ( !$whitelisted ) {
 2042+ $errors[] = $this->missingPermissionError( $action, $short );
 2043+ }
20452044 }
20462045
20472046 return $errors;

Follow-up revisions

RevisionCommit summaryAuthorDate
r108332Remove empty statement added in r108193platonides22:49, 7 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108175Per request of Aaron Schulz, follow-up r102187: added new 'TitleReadWhitelist...ialex20:29, 5 January 2012

Status & tagging log