Index: trunk/extensions/Babel/Babel.class.php |
— | — | @@ -55,57 +55,11 @@ |
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
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. |
62 | 63 | */ |
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 | | - |
110 | 64 | public function Render( $parser ) { |
111 | 65 | |
112 | 66 | /* 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 |
1 | 90 | + native |
Index: trunk/extensions/Babel/Babel.php |
— | — | @@ -30,19 +30,20 @@ |
31 | 31 | |
32 | 32 | // Register setup function. |
33 | 33 | if( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { |
34 | | - $wgHooks[ 'ParserFirstCallInit' ][] = 'Babel::Setup'; |
| 34 | + $wgHooks[ 'ParserFirstCallInit' ][] = 'BabelStatic::Setup'; |
35 | 35 | } else { |
36 | | - $wgExtensionFunctions[] = 'Babel::Setup'; |
| 36 | + $wgExtensionFunctions[] = 'BabelStatic::Setup'; |
37 | 37 | } |
38 | 38 | |
39 | 39 | // Register required hooks. |
40 | | -$wgHooks[ 'LanguageGetMagic' ][] = 'Babel::Magic'; |
| 40 | +$wgHooks[ 'LanguageGetMagic' ][] = 'BabelStatic::Magic'; |
41 | 41 | |
42 | 42 | // Register internationalisation file. |
43 | 43 | $wgExtensionMessagesFiles[ 'Babel' ] = dirname( __FILE__ ) . '/Babel.i18n.php'; |
44 | 44 | |
45 | 45 | // 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'; |
47 | 48 | |
48 | 49 | // Definitions. |
49 | 50 | define( 'ISO_639_1', 1 ); |