r54813 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54812‎ | r54813 | r54814 >
Date:21:30, 11 August 2009
Author:siebrand
Status:deferred
Tags:
Comment:
stylize.php, formatting updates, trailing whitespace removed
Modified paths:
  • /trunk/extensions/CategoryTests/CategoryTests.i18n.magic.php (modified) (history)
  • /trunk/extensions/CategoryTests/CategoryTests.i18n.php (modified) (history)
  • /trunk/extensions/CategoryTests/CategoryTests.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryTests/CategoryTests.i18n.magic.php
@@ -21,4 +21,4 @@
2222 * Unlike the English one above where the array has two values, all translations must have THREE values, like so:
2323 * 'ifcategory' => array( 0, 'translation_goes_here', 'ifcategory' )
2424 * 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 @@
22 <?php
33 /**
44 * Internationalization file for the CategoryTests extension
5 -*/
 5+ */
66
77 $messages = array();
88
@@ -10,4 +10,4 @@
1111 */
1212 $messages['en'] = array(
1313 'categorytests' => 'Functions for category testing'
14 -);
\ No newline at end of file
 14+);
Index: trunk/extensions/CategoryTests/CategoryTests.php
@@ -5,12 +5,12 @@
66 * Check http://www.mediawiki.org/wiki/Extension:CategoryTests for more info on what everything does
77 */
88
9 -if( !defined( 'MEDIAWIKI' ) ) {
 9+if ( !defined( 'MEDIAWIKI' ) ) {
1010 echo "This file is an extension of the MediaWiki software and cannot be used standalone\n";
1111 die( 1 );
1212 }
1313
14 -//credits and hooks
 14+// credits and hooks
1515 $wgExtensionFunctions[] = 'wfCategoryTests';
1616 $wgExtensionCredits['parserhook'][] = array(
1717 'path' => __FILE__,
@@ -23,84 +23,84 @@
2424 );
2525
2626 $wgHooks['LanguageGetMagic'][] = 'wfCategoryTestsLanguageGetMagic';
27 -$wgExtensionMessagesFiles['CategoryTests'] = dirname(__FILE__) . '/CategoryTests.i18n.php';
 27+$wgExtensionMessagesFiles['CategoryTests'] = dirname( __FILE__ ) . '/CategoryTests.i18n.php';
2828
2929 function wfCategoryTests() {
3030 global $wgParser, $wgExtCategoryTests;
31 -
 31+
3232 $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' ) );
3636 }
3737
3838 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 ) ) {
4141 $functions = $words['en'];
4242 } else {
43 - $functions = array_merge($words[$langCode], $words['en']);
 43+ $functions = array_merge( $words[$langCode], $words['en'] );
4444 }
45 - foreach($functions as $key => $value) {
 45+ foreach ( $functions as $key => $value ) {
4646 $magicWords[$key] = $value;
4747 }
4848 return true;
49 -}
 49+}
5050
5151 Class ExtCategoryTests {
52 -
 52+
5353 function ifcategory( &$parser, $category = '', $then = '', $else = '', $pagename = '' ) {
54 - if($category === '') {
 54+ if ( $category === '' ) {
5555 return $then;
5656 }
57 - if($pagename === '') {
 57+ if ( $pagename === '' ) {
5858 $title = $parser->getTitle();
5959 $page = $title->getDBkey();
6060 $ns = $title->getNamespace();
6161 } else {
62 - $title = Title::newFromText($pagename);
63 - if(!$title->exists())
 62+ $title = Title::newFromText( $pagename );
 63+ if ( !$title->exists() )
6464 return $else;
6565 $page = $title->getDBkey();
6666 $ns = $title->getNamespace();
6767 }
68 - $cattitle = Title::makeTitleSafe(NS_CATEGORY, $category);
 68+ $cattitle = Title::makeTitleSafe( NS_CATEGORY, $category );
6969 $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(
7272 'page_id=cl_from',
7373 'page_namespace' => $ns,
7474 '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 )
7878 return $else;
7979 return $then;
8080 }
8181
8282 function ifnocategories( &$parser, $then = '', $else = '', $pagename = '' ) {
83 - if($pagename === '') {
 83+ if ( $pagename === '' ) {
8484 $title = $parser->getTitle();
8585 $page = $title->getDBkey();
8686 $ns = $title->getNamespace();
8787 } else {
88 - $title = Title::newFromText($pagename);
89 - if(!$title->exists())
 88+ $title = Title::newFromText( $pagename );
 89+ if ( !$title->exists() )
9090 return $then;
9191 $page = $title->getDBkey();
9292 $ns = $title->getNamespace();
9393 }
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(
9696 'page_id=cl_from',
9797 '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 )
101101 return $then;
102102 return $else;
103103 }
104 -
 104+
105105 function switchcategory( &$parser ) {
106106 $args = func_get_args();
107107 array_shift( $args );
@@ -108,15 +108,15 @@
109109 $parts = null;
110110 $default = null;
111111 $page = '';
112 - foreach( $args as $arg ) {
 112+ foreach ( $args as $arg ) {
113113 $parts = array_map( 'trim', explode( '=', $arg, 2 ) );
114114 if ( count( $parts ) == 2 ) {
115115 $mwPage = MagicWord::get( 'page' );
116 - if( $mwPage->matchStartAndRemove( $parts[0] ) ) {
 116+ if ( $mwPage->matchStartAndRemove( $parts[0] ) ) {
117117 $page = $parts[1];
118118 continue;
119119 }
120 - if ( $found || $this->ifcategory($parser, $parts[0], true, false, $page) ) {
 120+ if ( $found || $this->ifcategory( $parser, $parts[0], true, false, $page ) ) {
121121 return $parts[1];
122122 } else {
123123 $mwDefault = MagicWord::get( 'default' );
@@ -125,13 +125,13 @@
126126 }
127127 }
128128 } elseif ( count( $parts ) == 1 ) {
129 - if ( $this->ifcategory($parser, $parts[0], true, false, $page) ) {
 129+ if ( $this->ifcategory( $parser, $parts[0], true, false, $page ) ) {
130130 $found = true;
131131 }
132132 }
133133 }
134 -
135 - if ( count( $parts ) == 1) {
 134+
 135+ if ( count( $parts ) == 1 ) {
136136 return $parts[0];
137137 } elseif ( !is_null( $default ) ) {
138138 return $default;

Status & tagging log