Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -1926,6 +1926,14 @@ |
1927 | 1927 | $pageid: database ID of the page that's been moved |
1928 | 1928 | $redirid: database ID of the created redirect |
1929 | 1929 | |
| 1930 | +'TitleReadWhitelist': called at the end of read permissions checks, just before |
| 1931 | + 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. |
| 1934 | +$title: Title object being checked against |
| 1935 | +$user: Current user object |
| 1936 | +&$errors: errors |
| 1937 | + |
1930 | 1938 | 'UndeleteForm::showHistory': called in UndeleteForm::showHistory, after a |
1931 | 1939 | PageArchive object has been created but before any further processing is done. |
1932 | 1940 | &$archive: PageArchive object |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -1965,6 +1965,7 @@ |
1966 | 1966 | * @return Array list of errors |
1967 | 1967 | */ |
1968 | 1968 | private function checkReadPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) { |
| 1969 | + global $wgWhitelistRead; |
1969 | 1970 | static $useShortcut = null; |
1970 | 1971 | |
1971 | 1972 | # Initialize the $useShortcut boolean, to determine if we can skip quite a bit of code below |
— | — | @@ -1991,61 +1992,57 @@ |
1992 | 1993 | } |
1993 | 1994 | } |
1994 | 1995 | |
1995 | | - # Shortcut for public wikis, allows skipping quite a bit of code |
1996 | | - if ( $useShortcut ) { |
1997 | | - return $errors; |
1998 | | - } |
| 1996 | + $whitelisted = false; |
1999 | 1997 | |
2000 | | - # If the user is allowed to read pages, he is allowed to read all pages |
2001 | | - if ( $user->isAllowed( 'read' ) ) { |
2002 | | - return $errors; |
2003 | | - } |
2004 | | - |
2005 | | - # Always grant access to the login page. |
2006 | | - # Even anons need to be able to log in. |
2007 | | - if ( $this->isSpecial( 'Userlogin' ) |
| 1998 | + if ( $useShortcut ) { |
| 1999 | + # Shortcut for public wikis, allows skipping quite a bit of code |
| 2000 | + $whitelisted = true; |
| 2001 | + } elseif ( $user->isAllowed( 'read' ) ) { |
| 2002 | + # If the user is allowed to read pages, he is allowed to read all pages |
| 2003 | + $whitelisted = true; |
| 2004 | + } elseif ( $this->isSpecial( 'Userlogin' ) |
2008 | 2005 | || $this->isSpecial( 'ChangePassword' ) |
2009 | 2006 | || $this->isSpecial( 'PasswordReset' ) |
2010 | 2007 | ) { |
2011 | | - return $errors; |
2012 | | - } |
2013 | | - |
2014 | | - # Time to check the whitelist |
2015 | | - global $wgWhitelistRead; |
2016 | | - |
2017 | | - # Only do these checks is there's something to check against |
2018 | | - if ( is_array( $wgWhitelistRead ) && count( $wgWhitelistRead ) ) { |
2019 | | - # Check for explicit whitelisting |
| 2008 | + # Always grant access to the login page. |
| 2009 | + # Even anons need to be able to log in. |
| 2010 | + $whitelisted = true; |
| 2011 | + } elseif ( is_array( $wgWhitelistRead ) && count( $wgWhitelistRead ) ) { |
| 2012 | + # Time to check the whitelist |
| 2013 | + # Only do these checks is there's something to check against |
2020 | 2014 | $name = $this->getPrefixedText(); |
2021 | 2015 | $dbName = $this->getPrefixedDBKey(); |
2022 | 2016 | |
2023 | 2017 | // Check with and without underscores |
2024 | 2018 | if ( in_array( $name, $wgWhitelistRead, true ) || in_array( $dbName, $wgWhitelistRead, true ) ) { |
2025 | | - return $errors; |
2026 | | - } |
2027 | | - |
2028 | | - # Old settings might have the title prefixed with |
2029 | | - # a colon for main-namespace pages |
2030 | | - if ( $this->getNamespace() == NS_MAIN ) { |
| 2019 | + # Check for explicit whitelisting |
| 2020 | + $whitelisted = true; |
| 2021 | + } elseif ( $this->getNamespace() == NS_MAIN ) { |
| 2022 | + # Old settings might have the title prefixed with |
| 2023 | + # a colon for main-namespace pages |
2031 | 2024 | if ( in_array( ':' . $name, $wgWhitelistRead ) ) { |
2032 | | - return $errors; |
| 2025 | + $whitelisted = true; |
2033 | 2026 | } |
2034 | | - } |
2035 | | - |
2036 | | - # If it's a special page, ditch the subpage bit and check again |
2037 | | - if ( $this->isSpecialPage() ) { |
| 2027 | + } elseif ( $this->isSpecialPage() ) { |
| 2028 | + # If it's a special page, ditch the subpage bit and check again |
2038 | 2029 | $name = $this->getDBkey(); |
2039 | 2030 | list( $name, /* $subpage */ ) = SpecialPageFactory::resolveAlias( $name ); |
2040 | 2031 | if ( $name !== false ) { |
2041 | 2032 | $pure = SpecialPage::getTitleFor( $name )->getPrefixedText(); |
2042 | 2033 | if ( in_array( $pure, $wgWhitelistRead, true ) ) { |
2043 | | - return $errors; |
| 2034 | + $whitelisted = true; |
2044 | 2035 | } |
2045 | 2036 | } |
2046 | 2037 | } |
2047 | 2038 | } |
2048 | 2039 | |
2049 | | - $errors[] = $this->missingPermissionError( $action, $short ); |
| 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 ); |
| 2045 | + } |
| 2046 | + |
2050 | 2047 | return $errors; |
2051 | 2048 | } |
2052 | 2049 | |