Index: trunk/extensions/CategoryTests/CategoryTests.i18n.magic.php |
— | — | @@ -21,4 +21,4 @@ |
22 | 22 | * Unlike the English one above where the array has two values, all translations must have THREE values, like so: |
23 | 23 | * 'ifcategory' => array( 0, 'translation_goes_here', 'ifcategory' ) |
24 | 24 | * The third value should be the same as the name of the key string you are translating for |
25 | | -*/ |
\ No newline at end of file |
| 25 | + */ |
Index: trunk/extensions/CategoryTests/CategoryTests.i18n.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * Internationalization file for the CategoryTests extension |
5 | | -*/ |
| 5 | + */ |
6 | 6 | |
7 | 7 | $messages = array(); |
8 | 8 | |
— | — | @@ -10,4 +10,4 @@ |
11 | 11 | */ |
12 | 12 | $messages['en'] = array( |
13 | 13 | 'categorytests' => 'Functions for category testing' |
14 | | -); |
\ No newline at end of file |
| 14 | +); |
Index: trunk/extensions/CategoryTests/CategoryTests.php |
— | — | @@ -5,12 +5,12 @@ |
6 | 6 | * Check http://www.mediawiki.org/wiki/Extension:CategoryTests for more info on what everything does |
7 | 7 | */ |
8 | 8 | |
9 | | -if( !defined( 'MEDIAWIKI' ) ) { |
| 9 | +if ( !defined( 'MEDIAWIKI' ) ) { |
10 | 10 | echo "This file is an extension of the MediaWiki software and cannot be used standalone\n"; |
11 | 11 | die( 1 ); |
12 | 12 | } |
13 | 13 | |
14 | | -//credits and hooks |
| 14 | +// credits and hooks |
15 | 15 | $wgExtensionFunctions[] = 'wfCategoryTests'; |
16 | 16 | $wgExtensionCredits['parserhook'][] = array( |
17 | 17 | 'path' => __FILE__, |
— | — | @@ -23,84 +23,84 @@ |
24 | 24 | ); |
25 | 25 | |
26 | 26 | $wgHooks['LanguageGetMagic'][] = 'wfCategoryTestsLanguageGetMagic'; |
27 | | -$wgExtensionMessagesFiles['CategoryTests'] = dirname(__FILE__) . '/CategoryTests.i18n.php'; |
| 27 | +$wgExtensionMessagesFiles['CategoryTests'] = dirname( __FILE__ ) . '/CategoryTests.i18n.php'; |
28 | 28 | |
29 | 29 | function wfCategoryTests() { |
30 | 30 | global $wgParser, $wgExtCategoryTests; |
31 | | - |
| 31 | + |
32 | 32 | $wgExtCategoryTests = new ExtCategoryTests(); |
33 | | - $wgParser->setFunctionHook( 'ifcategory', array(&$wgExtCategoryTests, 'ifcategory') ); |
34 | | - $wgParser->setFunctionHook( 'ifnocategories', array(&$wgExtCategoryTests, 'ifnocategories') ); |
35 | | - $wgParser->setFunctionHook( 'switchcategory', array(&$wgExtCategoryTests, 'switchcategory') ); |
| 33 | + $wgParser->setFunctionHook( 'ifcategory', array( &$wgExtCategoryTests, 'ifcategory' ) ); |
| 34 | + $wgParser->setFunctionHook( 'ifnocategories', array( &$wgExtCategoryTests, 'ifnocategories' ) ); |
| 35 | + $wgParser->setFunctionHook( 'switchcategory', array( &$wgExtCategoryTests, 'switchcategory' ) ); |
36 | 36 | } |
37 | 37 | |
38 | 38 | function wfCategoryTestsLanguageGetMagic( &$magicWords, $langCode ) { |
39 | | - require_once(dirname(__FILE__) . '/CategoryTests.i18n.magic.php'); |
40 | | - if( $langCode == 'en' || !array_key_exists($langCode, $words) ) { |
| 39 | + require_once( dirname( __FILE__ ) . '/CategoryTests.i18n.magic.php' ); |
| 40 | + if ( $langCode == 'en' || !array_key_exists( $langCode, $words ) ) { |
41 | 41 | $functions = $words['en']; |
42 | 42 | } else { |
43 | | - $functions = array_merge($words[$langCode], $words['en']); |
| 43 | + $functions = array_merge( $words[$langCode], $words['en'] ); |
44 | 44 | } |
45 | | - foreach($functions as $key => $value) { |
| 45 | + foreach ( $functions as $key => $value ) { |
46 | 46 | $magicWords[$key] = $value; |
47 | 47 | } |
48 | 48 | return true; |
49 | | -} |
| 49 | +} |
50 | 50 | |
51 | 51 | Class ExtCategoryTests { |
52 | | - |
| 52 | + |
53 | 53 | function ifcategory( &$parser, $category = '', $then = '', $else = '', $pagename = '' ) { |
54 | | - if($category === '') { |
| 54 | + if ( $category === '' ) { |
55 | 55 | return $then; |
56 | 56 | } |
57 | | - if($pagename === '') { |
| 57 | + if ( $pagename === '' ) { |
58 | 58 | $title = $parser->getTitle(); |
59 | 59 | $page = $title->getDBkey(); |
60 | 60 | $ns = $title->getNamespace(); |
61 | 61 | } else { |
62 | | - $title = Title::newFromText($pagename); |
63 | | - if(!$title->exists()) |
| 62 | + $title = Title::newFromText( $pagename ); |
| 63 | + if ( !$title->exists() ) |
64 | 64 | return $else; |
65 | 65 | $page = $title->getDBkey(); |
66 | 66 | $ns = $title->getNamespace(); |
67 | 67 | } |
68 | | - $cattitle = Title::makeTitleSafe(NS_CATEGORY, $category); |
| 68 | + $cattitle = Title::makeTitleSafe( NS_CATEGORY, $category ); |
69 | 69 | $catkey = $cattitle->getDBkey(); |
70 | | - $db = wfGetDB(DB_SLAVE); |
71 | | - $res = $db->select(array('page', 'categorylinks'), 'cl_from', array( |
| 70 | + $db = wfGetDB( DB_SLAVE ); |
| 71 | + $res = $db->select( array( 'page', 'categorylinks' ), 'cl_from', array( |
72 | 72 | 'page_id=cl_from', |
73 | 73 | 'page_namespace' => $ns, |
74 | 74 | 'page_title' => $page, |
75 | | - 'cl_to' => $catkey), __METHOD__, |
76 | | - array('LIMIT' => 1)); |
77 | | - if($db->numRows($res) == 0) |
| 75 | + 'cl_to' => $catkey ), __METHOD__, |
| 76 | + array( 'LIMIT' => 1 ) ); |
| 77 | + if ( $db->numRows( $res ) == 0 ) |
78 | 78 | return $else; |
79 | 79 | return $then; |
80 | 80 | } |
81 | 81 | |
82 | 82 | function ifnocategories( &$parser, $then = '', $else = '', $pagename = '' ) { |
83 | | - if($pagename === '') { |
| 83 | + if ( $pagename === '' ) { |
84 | 84 | $title = $parser->getTitle(); |
85 | 85 | $page = $title->getDBkey(); |
86 | 86 | $ns = $title->getNamespace(); |
87 | 87 | } else { |
88 | | - $title = Title::newFromText($pagename); |
89 | | - if(!$title->exists()) |
| 88 | + $title = Title::newFromText( $pagename ); |
| 89 | + if ( !$title->exists() ) |
90 | 90 | return $then; |
91 | 91 | $page = $title->getDBkey(); |
92 | 92 | $ns = $title->getNamespace(); |
93 | 93 | } |
94 | | - $db = wfGetDB(DB_SLAVE); |
95 | | - $res = $db->select(array('page', 'categorylinks'), 'cl_from', array( |
| 94 | + $db = wfGetDB( DB_SLAVE ); |
| 95 | + $res = $db->select( array( 'page', 'categorylinks' ), 'cl_from', array( |
96 | 96 | 'page_id=cl_from', |
97 | 97 | 'page_namespace' => $ns, |
98 | | - 'page_title' => $page), __METHOD__, |
99 | | - array('LIMIT' => 1)); |
100 | | - if($db->numRows($res) == 0) |
| 98 | + 'page_title' => $page ), __METHOD__, |
| 99 | + array( 'LIMIT' => 1 ) ); |
| 100 | + if ( $db->numRows( $res ) == 0 ) |
101 | 101 | return $then; |
102 | 102 | return $else; |
103 | 103 | } |
104 | | - |
| 104 | + |
105 | 105 | function switchcategory( &$parser ) { |
106 | 106 | $args = func_get_args(); |
107 | 107 | array_shift( $args ); |
— | — | @@ -108,15 +108,15 @@ |
109 | 109 | $parts = null; |
110 | 110 | $default = null; |
111 | 111 | $page = ''; |
112 | | - foreach( $args as $arg ) { |
| 112 | + foreach ( $args as $arg ) { |
113 | 113 | $parts = array_map( 'trim', explode( '=', $arg, 2 ) ); |
114 | 114 | if ( count( $parts ) == 2 ) { |
115 | 115 | $mwPage = MagicWord::get( 'page' ); |
116 | | - if( $mwPage->matchStartAndRemove( $parts[0] ) ) { |
| 116 | + if ( $mwPage->matchStartAndRemove( $parts[0] ) ) { |
117 | 117 | $page = $parts[1]; |
118 | 118 | continue; |
119 | 119 | } |
120 | | - if ( $found || $this->ifcategory($parser, $parts[0], true, false, $page) ) { |
| 120 | + if ( $found || $this->ifcategory( $parser, $parts[0], true, false, $page ) ) { |
121 | 121 | return $parts[1]; |
122 | 122 | } else { |
123 | 123 | $mwDefault = MagicWord::get( 'default' ); |
— | — | @@ -125,13 +125,13 @@ |
126 | 126 | } |
127 | 127 | } |
128 | 128 | } elseif ( count( $parts ) == 1 ) { |
129 | | - if ( $this->ifcategory($parser, $parts[0], true, false, $page) ) { |
| 129 | + if ( $this->ifcategory( $parser, $parts[0], true, false, $page ) ) { |
130 | 130 | $found = true; |
131 | 131 | } |
132 | 132 | } |
133 | 133 | } |
134 | | - |
135 | | - if ( count( $parts ) == 1) { |
| 134 | + |
| 135 | + if ( count( $parts ) == 1 ) { |
136 | 136 | return $parts[0]; |
137 | 137 | } elseif ( !is_null( $default ) ) { |
138 | 138 | return $default; |