Index: trunk/extensions/DisableSpecialPages/DisableSpecialPages.php |
— | — | @@ -3,67 +3,56 @@ |
4 | 4 | /** |
5 | 5 | * Extension allows wiki administrators to make a special page unavailable |
6 | 6 | * |
7 | | - * @addtogroup Extensions |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
8 | 9 | * @author Rob Church <robchur@gmail.com> |
9 | 10 | * @copyright © 2006 Rob Church |
10 | 11 | * @licence GNU General Public Licence 2.0 or later |
11 | 12 | */ |
12 | 13 | |
13 | | -if( defined( 'MEDIAWIKI' ) ) { |
| 14 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 15 | + echo( "This file is an extension to the MediaWiki software, and cannot be used standalone.\n" ); |
| 16 | + die( 1 ); |
| 17 | +} |
14 | 18 | |
15 | | - $wgExtensionCredits['other'][] = array( 'path' => __FILE__, 'name' => 'Disable Special Pages', 'author' => 'Rob Church' ); |
16 | | - |
17 | | - if( version_compare( $wgVersion, '1.7.0' ) ) { |
18 | | - # Use the new hooks in 1.7+ |
19 | | - $wgHooks['SpecialPage_initList'][] = 'efDspHook'; |
20 | | - } else { |
21 | | - # Fall back to the older method |
22 | | - require_once( 'SpecialPage.php' ); |
23 | | - $wgExtensionFunctions[] = 'efDspOldMethod'; |
24 | | - } |
25 | | - |
26 | | - /** |
27 | | - * Titles of special pages to disable; Special:Userlogin, Special:Userlogout |
28 | | - * and Special:Search cannot be disabled via this interface |
29 | | - */ |
30 | | - $wgDisabledSpecialPages = array(); |
31 | | - |
32 | | - function efDspHook( &$list ) { |
33 | | - global $wgDisabledSpecialPages; |
34 | | - foreach( $wgDisabledSpecialPages as $page ) { |
35 | | - $title = efDspMakeTitle( $page ); |
36 | | - if( $title && !efDspWhitelisted( $title ) && isset( $list[ $title->getText() ] ) ) |
37 | | - unset( $list[ $title->getText() ] ); |
38 | | - } |
39 | | - return true; |
40 | | - } |
| 19 | +$wgExtensionCredits['other'][] = array( |
| 20 | + 'path' => __FILE__, |
| 21 | + 'name' => 'Disable Special Pages', |
| 22 | + 'author' => 'Rob Church', |
| 23 | + 'description' => 'Allow wiki administrators to make a special page unavailable' |
| 24 | +); |
41 | 25 | |
42 | | - function efDspOldMethod() { |
43 | | - global $wgDisabledSpecialPages, $wgSpecialPages; |
44 | | - foreach( $wgDisabledSpecialPages as $page ) { |
45 | | - $title = efDspMakeTitle( $page ); |
46 | | - if( $title && !efDspWhitelisted( $title ) && isset( $wgSpecialPages[ $title->getText() ] ) ) |
47 | | - SpecialPage::removePage( $title->getText() ); |
48 | | - } |
49 | | - return true; |
| 26 | +$wgHooks['SpecialPage_initList'][] = 'efDspHook'; |
| 27 | + |
| 28 | +/** |
| 29 | + * Titles of special pages to disable; Special:Userlogin, Special:Userlogout |
| 30 | + * and Special:Search cannot be disabled via this interface |
| 31 | + */ |
| 32 | +$wgDisabledSpecialPages = array(); |
| 33 | + |
| 34 | +function efDspHook( &$list ) { |
| 35 | + global $wgDisabledSpecialPages; |
| 36 | + foreach( $wgDisabledSpecialPages as $page ) { |
| 37 | + $title = efDspMakeTitle( $page ); |
| 38 | + if ( !$title ) |
| 39 | + continue; |
| 40 | + $canonicalName = SpecialPage::resolveAlias( $title->getDBkey() ); |
| 41 | + if( !efDspWhitelisted( $canonicalName ) && isset( $list[$canonicalName] ) ) |
| 42 | + unset( $list[$canonicalName] ); |
50 | 43 | } |
| 44 | + return true; |
| 45 | +} |
51 | 46 | |
52 | | - function efDspMakeTitle( $page ) { |
53 | | - $title = Title::newFromText( $page ); |
54 | | - if( is_object( $title ) ) { |
55 | | - return $title->getNamespace() == NS_SPECIAL ? $title : Title::makeTitle( NS_SPECIAL, $title->getText() ); |
56 | | - } else { |
57 | | - return false; |
58 | | - } |
| 47 | +function efDspMakeTitle( $page ) { |
| 48 | + $title = Title::newFromText( $page ); |
| 49 | + if( is_object( $title ) ) { |
| 50 | + return $title->getNamespace() == NS_SPECIAL ? $title : Title::makeTitle( NS_SPECIAL, $title->getText() ); |
| 51 | + } else { |
| 52 | + return false; |
59 | 53 | } |
60 | | - |
61 | | - function efDspWhitelisted( &$title ) { |
62 | | - $whitelist = array( 'Search', 'Userlogin', 'Userlogout' ); |
63 | | - return in_array( $title->getText(), $whitelist ); |
64 | | - } |
65 | | - |
66 | | -} else { |
67 | | - echo( "This file is an extension to the MediaWiki software, and cannot be used standalone.\n" ); |
68 | | - die( 1 ); |
69 | 54 | } |
70 | 55 | |
| 56 | +function efDspWhitelisted( $title ) { |
| 57 | + static $whitelist = array( 'Search', 'Userlogin', 'Userlogout' ); |
| 58 | + return in_array( $title, $whitelist ); |
| 59 | +} |
\ No newline at end of file |