r36465 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36464‎ | r36465 | r36466 >
Date:15:59, 19 June 2008
Author:minuteelectron
Status:old
Tags:
Comment:
* Break Setup, Magic, and Render functions into a seperate class to decrease startup time.
Modified paths:
  • /trunk/extensions/Babel/Babel.class.php (modified) (history)
  • /trunk/extensions/Babel/Babel.php (modified) (history)
  • /trunk/extensions/Babel/BabelStatic.class.php (added) (history)

Diff [purge]

Index: trunk/extensions/Babel/Babel.class.php
@@ -55,57 +55,11 @@
5656 }
5757
5858 /**
59 - * Registers the parser function hook.
60 - *
61 - * @return true
 59+ * Render the Babel tower.
 60+ *
 61+ * @param parser $parser Parser object.
 62+ * @return string Babel tower.
6263 */
63 - static public function Setup() {
64 -
65 - /* Get the location of the language codes file.
66 - */
67 - global $wgLanguageCodesFiles;
68 -
69 - /* Initialise the Babel object.
70 - */
71 - global $wgBabel;
72 - $wgBabel = new Babel( $wgLanguageCodesFiles );
73 -
74 - /* Register the hook within the parser object.
75 - */
76 - global $wgParser;
77 - $wgParser->setFunctionHook( 'babel', array( $wgBabel, 'Render' ) );
78 -
79 - /* Return true to ensure processing is continued and an exception is not
80 - * generated.
81 - */
82 - return true;
83 -
84 - }
85 -
86 - /**
87 - * Registers the parser function magic word.
88 - *
89 - * @param array $magicWords The associative array of magic words on the
90 - * wiki for adding too.
91 - * @param string $langCode Content language code of the wiki.
92 - * @return true
93 - */
94 - static public function Magic( array $magicWords, $langCode ) {
95 -
96 - /* Register the magic word, maybe one day this could be localised by adding
97 - * synonyms into the array -- but there is currently no simple way of doing
98 - * that given the current way of localisation. The first element is set to
99 - * 0 so that it can be case insensitive.
100 - */
101 - $magicWords[ 'babel' ] = array( 0, 'babel' );
102 -
103 - /* Return true to ensure processing is continued and an exception is not
104 - * generated.
105 - */
106 - return true;
107 -
108 - }
109 -
11064 public function Render( $parser ) {
11165
11266 /* Store all the parameters passed to this function in an array.
Index: trunk/extensions/Babel/BabelStatic.class.php
@@ -0,0 +1,88 @@
 2+<?php
 3+
 4+/**
 5+ * Static functions related to Babel.
 6+ *
 7+ * @addtogroup Extensions
 8+ */
 9+
 10+class BabelStatic {
 11+
 12+ /**
 13+ * Registers the parser function hook.
 14+ *
 15+ * @return true
 16+ */
 17+ public static function Setup() {
 18+
 19+ /* Register the hook within the parser object.
 20+ */
 21+ global $wgParser;
 22+ $wgParser->setFunctionHook( 'babel', 'BabelStatic::Render' );
 23+
 24+ /* Return true to ensure processing is continued and an exception is not
 25+ * generated.
 26+ */
 27+ return true;
 28+
 29+ }
 30+
 31+ /**
 32+ * Registers the parser function magic word.
 33+ *
 34+ * @param array $magicWords The associative array of magic words on the
 35+ * wiki for adding too.
 36+ * @param string $langCode Content language code of the wiki.
 37+ * @return true
 38+ */
 39+ public static function Magic( array $magicWords, $langCode ) {
 40+
 41+ /* Register the magic word, maybe one day this could be localised by adding
 42+ * synonyms into the array -- but there is currently no simple way of doing
 43+ * that given the current way of localisation. The first element is set to
 44+ * 0 so that it can be case insensitive.
 45+ */
 46+ $magicWords[ 'babel' ] = array( 0, 'babel' );
 47+
 48+ /* Return true to ensure processing is continued and an exception is not
 49+ * generated.
 50+ */
 51+ return true;
 52+
 53+ }
 54+
 55+ /**
 56+ * Return Babel tower, initializing the Babel object if necessery,
 57+ *
 58+ * @param parser $parser Parser object.
 59+ * @return string Babel tower.
 60+ */
 61+ public static function Render( $parser ) {
 62+
 63+ /* Get the location of the language codes file.
 64+ */
 65+ global $wgLanguageCodesFiles;
 66+
 67+ /* Grab the Babel object.
 68+ */
 69+ global $wgBabel;
 70+
 71+ /* Initialize Babel object if not already initialized.
 72+ */
 73+ if( !is_object( $wgBabel ) ) {
 74+
 75+ $wgBabel = new Babel( $wgLanguageCodesFiles );
 76+
 77+ }
 78+
 79+ /* Get arguments passed to this function.
 80+ */
 81+ $args = func_get_args();
 82+
 83+ /* Render the Babel tower and return.
 84+ */
 85+ return call_user_func_array( array( $wgBabel, 'render' ), $args );
 86+
 87+ }
 88+
 89+}
\ No newline at end of file
Property changes on: trunk/extensions/Babel/BabelStatic.class.php
___________________________________________________________________
Added: svn:eol-style
190 + native
Index: trunk/extensions/Babel/Babel.php
@@ -30,19 +30,20 @@
3131
3232 // Register setup function.
3333 if( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
34 - $wgHooks[ 'ParserFirstCallInit' ][] = 'Babel::Setup';
 34+ $wgHooks[ 'ParserFirstCallInit' ][] = 'BabelStatic::Setup';
3535 } else {
36 - $wgExtensionFunctions[] = 'Babel::Setup';
 36+ $wgExtensionFunctions[] = 'BabelStatic::Setup';
3737 }
3838
3939 // Register required hooks.
40 -$wgHooks[ 'LanguageGetMagic' ][] = 'Babel::Magic';
 40+$wgHooks[ 'LanguageGetMagic' ][] = 'BabelStatic::Magic';
4141
4242 // Register internationalisation file.
4343 $wgExtensionMessagesFiles[ 'Babel' ] = dirname( __FILE__ ) . '/Babel.i18n.php';
4444
4545 // Register autoload classes.
46 -$wgAutoloadClasses[ 'Babel' ] = dirname( __FILE__ ) . '/Babel.class.php';
 46+$wgAutoloadClasses[ 'Babel' ] = dirname( __FILE__ ) . '/Babel.class.php';
 47+$wgAutoloadClasses[ 'BabelStatic' ] = dirname( __FILE__ ) . '/BabelStatic.class.php';
4748
4849 // Definitions.
4950 define( 'ISO_639_1', 1 );

Status & tagging log