r110211 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110210‎ | r110211 | r110212 >
Date:16:46, 28 January 2012
Author:reedy
Status:ok
Tags:
Comment:
Use get accessors

Add/Improve documentation

Remove trailing whitespace
Modified paths:
  • /trunk/extensions/Scripting/common/Common.php (modified) (history)
  • /trunk/extensions/Scripting/common/Hooks.php (modified) (history)
  • /trunk/extensions/Scripting/common/LinkUpdates.php (modified) (history)
  • /trunk/extensions/Scripting/engines/LuaSandbox/Engine.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Scripting/common/Hooks.php
@@ -56,16 +56,15 @@
5757
5858 /**
5959 * Handles the {{#invoke:module|func}} construction.
60 - *
61 - * @static
62 - * @param $parser Parser
63 - * @param $frame
64 - * @param $args
 60+ *
 61+ * @param $parser Parser
 62+ * @param $frame PPFrame
 63+ * @param $args array
6564 * @return string
6665 */
6766 public static function callHook( &$parser, $frame, $args ) {
6867 if( count( $args ) < 2 ) {
69 - throw new ScriptingException( 'nofunction', 'common' ); // scripting-exceptions-common-nofunction
 68+ throw new ScriptingException( 'nofunction', 'common' ); // scripting-exceptions-common-nofunction
7069 }
7170
7271 $module = $parser->mStripState->unstripBoth( array_shift( $args ) );
@@ -75,11 +74,10 @@
7675
7776 /**
7877 * Handles the transclusion of the script ({{script:module}} hook).
79 - *
80 - * @static
81 - * @param $parser Parser
82 - * @param $frame
83 - * @param $args
 78+ *
 79+ * @param $parser Parser
 80+ * @param $frame PPFrame
 81+ * @param $args
8482 * @return string
8583 */
8684 public static function transcludeHook( &$parser, $frame, $args ) {
@@ -87,6 +85,15 @@
8886 return self::doRunHook( $parser, $frame, $module, 'main', $args );
8987 }
9088
 89+ /**
 90+ * @param $parser Parser
 91+ * @param $frame PPFrame
 92+ * @param $module
 93+ * @param $function
 94+ * @param $args
 95+ * @return string
 96+ * @throws ScriptingException
 97+ */
9198 private static function doRunHook( &$parser, $frame, $module, $function, $args ) {
9299 wfProfileIn( __METHOD__ );
93100
@@ -118,11 +125,10 @@
119126 /**
120127 * Overrides the standard view for modules. Enables syntax highlighting when
121128 * possible.
122 - *
123 - * @static
124 - * @param $text
125 - * @param $title Title
126 - * @param $output OutputPage
 129+ *
 130+ * @param $text string
 131+ * @param $title Title
 132+ * @param $output OutputPage
127133 * @return bool
128134 */
129135 public static function handleScriptView( $text, $title, $output ) {
@@ -157,6 +163,9 @@
158164
159165 /**
160166 * Indicates that modules are not wikitext.
 167+ * @param $title Title
 168+ * @param $result
 169+ * @return bool
161170 */
162171 public static function isWikitextPage( $title, &$result ) {
163172 if( $title->getNamespace() == NS_MODULE ) {
@@ -169,9 +178,8 @@
170179 /**
171180 * Adds report of number of evaluations by the single wikitext page.
172181 *
173 - * @static
174 - * @param $parser Parser
175 - * @param $report
 182+ * @param $parser Parser
 183+ * @param $report
176184 * @return bool
177185 */
178186 public static function reportLimits( $parser, &$report ) {
@@ -218,7 +226,7 @@
219227
220228 return true;
221229 }
222 -
 230+
223231 return true;
224232 }
225233 }
Index: trunk/extensions/Scripting/common/LinkUpdates.php
@@ -58,17 +58,21 @@
5959
6060 /**
6161 * Purges cache for all the pages where the script is used.
 62+ * @param $article Article
 63+ * @param $editInfo
 64+ * @param $changed
 65+ * @return bool
6266 */
6367 public static function purgeCache( &$article, &$editInfo, $changed ) {
6468 global $wgDeferredUpdateList, $wgParser;
6569
66 - if( $article->mTitle->getNamespace() == NS_MODULE ) {
 70+ if( $article->getTitle()->getNamespace() == NS_MODULE ) {
6771 // Invalidate the script cache
6872 $engine = Scripting::getEngine( $wgParser );
69 - $engine->invalidateModuleCache( $article->mTitle );
 73+ $engine->invalidateModuleCache( $article->getTitle() );
7074
7175 // Invalidate caches of articles which include the script
72 - $wgDeferredUpdateList[] = new HTMLCacheUpdate( $article->mTitle, 'scriptlinks' );
 76+ $wgDeferredUpdateList[] = new HTMLCacheUpdate( $article->getTitle(), 'scriptlinks' );
7377 }
7478
7579 return true;
@@ -88,6 +92,10 @@
8993
9094 /**
9195 * Adds scriptlinks to the list of tables supported by BacklinkCache.
 96+ * @param $table
 97+ * @param $title Title
 98+ * @param $conds
 99+ * @return bool
92100 */
93101 public static function getBacklinkCacheConditions( $table, $title, &$conds ) {
94102 if( $table == 'scriptlinks' ) {
Index: trunk/extensions/Scripting/common/Common.php
@@ -8,21 +8,21 @@
99
1010 protected static function getEngineClass() {
1111 global $wgScriptingEngine, $wgScriptingEngines;
12 -
 12+
1313 if( !$wgScriptingEngine ) {
1414 throw new MWException( 'Scripting extension is enabled but $wgScriptingEngine is not set' );
1515 }
16 -
 16+
1717 if( !isset( $wgScriptingEngines[$wgScriptingEngine] ) ) {
1818 throw new MWException( 'Invalid scripting engine is specified in $wgScriptingEngine' );
1919 }
20 -
 20+
2121 return $wgScriptingEngines[$wgScriptingEngine];
2222 }
23 -
 23+
2424 public static function getEngine( $parser ) {
2525 global $wgScriptingEngineConf;
26 -
 26+
2727 if( !isset( $parser->scripting_engine ) || !$parser->scripting_engine ) {
2828 $class = self::getEngineClass();
2929 $parser->scripting_engine = new $class( $parser );
@@ -30,7 +30,7 @@
3131 }
3232 return $parser->scripting_engine;
3333 }
34 -
 34+
3535 public static function resetEngine( $parser ) {
3636 $parser->scripting_engine = null;
3737 }
Index: trunk/extensions/Scripting/engines/LuaSandbox/Engine.php
@@ -2,16 +2,17 @@
33
44 class LuaSandboxEngine extends ScriptingEngineBase {
55 public $mSandbox;
6 -
 6+
77 public function load() {
8 - if( $this->mLoaded )
 8+ if( $this->mLoaded ) {
99 return;
 10+ }
1011
11 - if( !class_exists('luasandbox') ) {
 12+ if( !MWInit::classExists( 'luasandbox' ) ) {
1213 throw new MWException( 'luasandbox PHP extension is not installed' );
1314 }
1415
15 - $this->mSandbox = new LuaSandbox;
 16+ $this->mSandbox = new LuaSandbox;
1617 $this->mSandbox->setMemoryLimit( $this->mOptions['memoryLimit'] );
1718 $this->mSandbox->setCPULimit( $this->mOptions['maxCPU'] );
1819 $this->mSandbox->registerLibrary( 'mw', array( 'import' => array( $this, 'importModule' ) ) );
@@ -78,12 +79,13 @@
7980 protected $mInitialized;
8081
8182 function initialize() {
82 - if( $this->mInitialized )
 83+ if( $this->mInitialized ) {
8384 return;
 85+ }
8486 $this->mEngine->load();
85 -
 87+
8688 // FIXME: caching?
87 -
 89+
8890 try {
8991 $this->mBody = $this->mEngine->mSandbox->loadString( $this->mCode );
9092 $output = $this->mBody->call();

Status & tagging log