r60006 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60005‎ | r60006 | r60007 >
Date:21:50, 12 December 2009
Author:ialex
Status:deferred
Tags:
Comment:
* Drop pre-1.7 compat :)
* Add description to credits
* Pass the items in $wgDisabledSpecialPages through SpecialPage::resolveAlias() for sanity
* @addtogroup -> @ingroup in comment
Modified paths:
  • /trunk/extensions/DisableSpecialPages/DisableSpecialPages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DisableSpecialPages/DisableSpecialPages.php
@@ -3,67 +3,56 @@
44 /**
55 * Extension allows wiki administrators to make a special page unavailable
66 *
7 - * @addtogroup Extensions
 7+ * @file
 8+ * @ingroup Extensions
89 * @author Rob Church <robchur@gmail.com>
910 * @copyright © 2006 Rob Church
1011 * @licence GNU General Public Licence 2.0 or later
1112 */
1213
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+}
1418
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+);
4125
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] );
5043 }
 44+ return true;
 45+}
5146
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;
5953 }
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 );
6954 }
7055
 56+function efDspWhitelisted( $title ) {
 57+ static $whitelist = array( 'Search', 'Userlogin', 'Userlogout' );
 58+ return in_array( $title, $whitelist );
 59+}
\ No newline at end of file

Status & tagging log