Index: trunk/extensions/Lua/Lua.wrapper.php |
— | — | @@ -19,7 +19,6 @@ |
20 | 20 | * @param $parameter \type{\string} Optional parameter for that message |
21 | 21 | */ |
22 | 22 | public function __construct($msg, $parameter = ''){ |
23 | | - |
24 | 23 | $this->message = '<strong class="error">' . wfMsgForContent( "lua_$msg", htmlspecialchars( $parameter ) ) . '</strong>'; |
25 | 24 | } |
26 | 25 | } |
— | — | @@ -67,7 +66,7 @@ |
68 | 67 | 1 => array('pipe', 'w')), |
69 | 68 | $this->pipes, null, null); |
70 | 69 | if (!is_resource($this->proc)) { |
71 | | - $this->defunct = TRUE; |
| 70 | + $this->defunct = true; |
72 | 71 | throw new LuaError('interp_notfound'); |
73 | 72 | } |
74 | 73 | stream_set_blocking($this->pipes[0], 0); |
— | — | @@ -76,12 +75,12 @@ |
77 | 76 | stream_set_write_buffer($this->pipes[1], 0); |
78 | 77 | |
79 | 78 | # Ready to go. |
80 | | - $this->defunct = FALSE; |
81 | | - return TRUE; |
| 79 | + $this->defunct = false; |
| 80 | + return true; |
82 | 81 | } elseif ( $wgLuaExtension === 'lua' ) { |
83 | 82 | # We're using the extension - verify it exists |
84 | 83 | if (!class_exists('lua')) { |
85 | | - $this->defunct = TRUE; |
| 84 | + $this->defunct = true; |
86 | 85 | throw new LuaError('extension_notfound'); |
87 | 86 | } |
88 | 87 | |
— | — | @@ -96,11 +95,11 @@ |
97 | 96 | } |
98 | 97 | |
99 | 98 | # Ready to go. |
100 | | - $this->defunct = FALSE; |
| 99 | + $this->defunct = false; |
101 | 100 | return TRUE; |
102 | 101 | } elseif ( $wgLuaExtension === 'luasandbox' ) { |
103 | 102 | if (!class_exists('luasandbox')) { |
104 | | - $this->defunct = TRUE; |
| 103 | + $this->defunct = true; |
105 | 104 | throw new LuaError( 'extension_notfound' ); |
106 | 105 | } |
107 | 106 | |
— | — | @@ -217,7 +216,7 @@ |
218 | 217 | public function destroy() { |
219 | 218 | # If we're already defunct, we're done |
220 | 219 | if ($this->defunct) |
221 | | - return FALSE; |
| 220 | + return false; |
222 | 221 | |
223 | 222 | # Destroy the lua instance and/or external process and pipes |
224 | 223 | if ( isset( $this->sandbox ) ) { |
— | — | @@ -233,8 +232,8 @@ |
234 | 233 | } |
235 | 234 | |
236 | 235 | # Mark this instance defunct |
237 | | - $this->defunct = TRUE; |
238 | | - return TRUE; |
| 236 | + $this->defunct = true; |
| 237 | + return true; |
239 | 238 | } |
240 | 239 | |
241 | 240 | public function luaPrint() { |
Index: trunk/extensions/Lua/Lua.php |
— | — | @@ -23,8 +23,12 @@ |
24 | 24 | $wgAutoloadClasses['LuaError'] = $dir . 'Lua.wrapper.php'; |
25 | 25 | $wgAutoloadClasses['LuaWrapper'] = $dir . 'Lua.wrapper.php'; |
26 | 26 | |
27 | | -$wgLuaExternalInterpreter = FALSE; |
28 | | -$wgLuaExternalCompiler = FALSE; |
| 27 | +/** |
| 28 | + * @var $wgLua LuaWrapper |
| 29 | + */ |
| 30 | +$wgLua = null; |
| 31 | +$wgLuaExternalInterpreter = false; |
| 32 | +$wgLuaExternalCompiler = false; |
29 | 33 | $wgLuaExtension = 'lua'; |
30 | 34 | $wgLuaMaxLines = 1000000; |
31 | 35 | $wgLuaMaxCalls = 2000; |
Index: trunk/extensions/Lua/Lua.hooks.php |
— | — | @@ -9,7 +9,11 @@ |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class LuaHooks { |
13 | | - /** ParserFirstCallInit hook */ |
| 13 | + /** |
| 14 | + * ParserFirstCallInit hook |
| 15 | + * @param $parser Parser |
| 16 | + * @return bool |
| 17 | + */ |
14 | 18 | public static function parserInit( &$parser ) { |
15 | 19 | $parser->setHook( 'lua', 'LuaHooks::renderTag' ); |
16 | 20 | $parser->setFunctionHook('luaexpr', 'LuaHooks::renderExpr'); |
— | — | @@ -19,19 +23,26 @@ |
20 | 24 | /** ParserBeforeTidy hook */ |
21 | 25 | public static function beforeTidy(&$parser, &$text) { |
22 | 26 | global $wgLua; |
23 | | - if (isset($wgLua)) { |
| 27 | + if ( $wgLua !== null ) { |
24 | 28 | $wgLua->destroy(); |
25 | 29 | } |
26 | | - return TRUE; |
| 30 | + return true; |
27 | 31 | } |
28 | 32 | |
29 | | - /** Parser hook for the <lua> tag */ |
| 33 | + /** |
| 34 | + * Parser hook for the <lua> tag |
| 35 | + * @param $input |
| 36 | + * @param $args |
| 37 | + * @param $parser Parser |
| 38 | + * @return string |
| 39 | + */ |
30 | 40 | public static function renderTag($input, $args, $parser) { |
31 | 41 | try { |
32 | 42 | global $wgLua; |
33 | 43 | # Create a new LuaWrapper if needed |
34 | | - if (!isset($wgLua)) |
| 44 | + if ( $wgLua === null ) { |
35 | 45 | $wgLua = new LuaWrapper; |
| 46 | + } |
36 | 47 | |
37 | 48 | # Process the tag's arguments into a chunk of Lua code |
38 | 49 | # that initializes them in the Lua sandbox |
— | — | @@ -55,17 +66,24 @@ |
56 | 67 | return $e->getMessage(); |
57 | 68 | } |
58 | 69 | } |
59 | | - |
60 | | - /** Parser function hook for the #luaexpr function */ |
| 70 | + |
| 71 | + /** |
| 72 | + * Parser function hook for the #luaexpr function |
| 73 | + * @param $parser Parser |
| 74 | + * @param $param1 bool |
| 75 | + * @return string |
| 76 | + */ |
61 | 77 | public static function renderExpr(&$parser, $param1 = FALSE) { |
62 | 78 | global $wgLua; |
63 | 79 | # Create a new LuaWrapper if needed |
64 | | - if (!isset($wgLua)) |
65 | | - $wgLua = LuaWrapper::create(); |
| 80 | + if ( $wgLua === null ) { |
| 81 | + $wgLua = new LuaWrapper; |
| 82 | + } |
66 | 83 | |
67 | 84 | # Execute this Lua chunk, wrapped in io.write(). |
68 | | - if ($param1 == FALSE) |
| 85 | + if ( $param1 == false ) { |
69 | 86 | return ''; |
| 87 | + } |
70 | 88 | try { |
71 | 89 | return $wgLua->wrap("io.write($param1)"); |
72 | 90 | } catch (LuaError $e) { |