r114733 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114732‎ | r114733 | r114734 >
Date:03:53, 5 April 2012
Author:tstarling
Status:deferred
Tags:
Comment:
* Remove old-fashioned "m" prefix from member variables
* Make ScriptingEngineBase::getDefaultOptions() non-abstract since there is a reasonable default behaviour which can be implemented
Modified paths:
  • /trunk/extensions/Scripting/common/Base.php (modified) (history)
  • /trunk/extensions/Scripting/common/Common.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/Common.php
@@ -37,9 +37,8 @@
3838 }
3939
4040 /**
41 - * Exceptions which represents user-originating error in the script.
42 - * Please do not use it for internal errors like "oh god, this should have never happened".
43 - * Use casual MWException for that.
 41+ * An exception class which represents an error in the script. This does not
 42+ * normally abort the request, instead it is caught and shown to the user.
4443 */
4544 class ScriptingException extends MWException {
4645 function __construct( $exceptionID, $engine, $module = null, $line = null, $params = array() ) {
@@ -51,13 +50,13 @@
5251 }
5352 parent::__construct( $msg );
5453
55 - $this->mExceptionID = $exceptionID;
56 - $this->mLine = $line;
57 - $this->mModule = $module;
58 - $this->mParams = $params;
 54+ $this->exceptionID = $exceptionID;
 55+ $this->line = $line;
 56+ $this->module = $module;
 57+ $this->params = $params;
5958 }
6059
6160 public function getExceptionID() {
62 - return $this->mExceptionID;
 61+ return $this->exceptionID;
6362 }
6463 }
Index: trunk/extensions/Scripting/common/Base.php
@@ -28,9 +28,9 @@
2929 */
3030 abstract class ScriptingEngineBase {
3131 protected
32 - $mParser,
33 - $mModules = array(),
34 - $mModuleTitles = array();
 32+ $parser,
 33+ $modules = array(),
 34+ $moduleTitles = array();
3535
3636 /**
3737 * Creates a new module object within this engine
@@ -40,7 +40,9 @@
4141 /**
4242 * Returns the default options of the engine.
4343 */
44 - abstract public function getDefaultOptions();
 44+ public function getDefaultOptions() {
 45+ return array();
 46+ }
4547
4648 /**
4749 * Is called by setOptions() in order to notify the engine
@@ -54,7 +56,7 @@
5557 * @param $parser Parser Wikitext parser
5658 */
5759 public function __construct( $parser ) {
58 - $this->mParser = $parser;
 60+ $this->parser = $parser;
5961 }
6062
6163 /**
@@ -78,7 +80,7 @@
7981
8082 // Check if it is already loaded
8183 $key = $title->getPrefixedText();
82 - if( !isset( $this->mModules[$key] ) ) {
 84+ if( !isset( $this->modules[$key] ) ) {
8385 // Fetch the text
8486 $rev = $this->getModuleRev( $title, $source );
8587 if( !$rev ) {
@@ -89,10 +91,10 @@
9092 }
9193
9294 // Create the class
93 - $this->mModules[$key] = $this->newModule( $title, $rev->getText(), $rev->getID(), $source );
94 - $this->mModuleTitles[] = $title;
 95+ $this->modules[$key] = $this->newModule( $title, $rev->getText(), $rev->getID(), $source );
 96+ $this->moduleTitles[] = $title;
9597 }
96 - return $this->mModules[$key];
 98+ return $this->modules[$key];
9799 }
98100
99101 /**
@@ -114,7 +116,7 @@
115117 * Sets the engine-specific options from $wgScriptingEngineConf.
116118 */
117119 function setOptions( $options ) {
118 - $this->mOptions = array_merge( $this->getDefaultOptions(), $options );
 120+ $this->options = array_merge( $this->getDefaultOptions(), $options );
119121 $this->updateOptions();
120122 }
121123
@@ -152,7 +154,7 @@
153155 * engine.
154156 */
155157 public function getUsedModules() {
156 - return $this->mModuleTitles;
 158+ return $this->moduleTitles;
157159 }
158160
159161 /**
@@ -183,22 +185,22 @@
184186 * and maintaining the contents of the module.
185187 */
186188 abstract class ScriptingModuleBase {
187 - var $mEngine, $mTitle, $mCode, $mRevisionID, $mSource;
 189+ var $engine, $title, $code, $revisionID, $source;
188190
189191 public function __construct( $engine, $title, $code, $revisionID, $source ) {
190 - $this->mEngine = $engine;
191 - $this->mTitle = $title;
192 - $this->mCode = $code;
193 - $this->mRevisionID = $revisionID;
194 - $this->mSource = $source;
 192+ $this->engine = $engine;
 193+ $this->title = $title;
 194+ $this->code = $code;
 195+ $this->revisionID = $revisionID;
 196+ $this->source = $source;
195197 }
196198
197199 /** Accessors **/
198 - public function getEngine() { return $this->mEngine; }
199 - public function getTitle() { return $this->mTitle; }
200 - public function getCode() { return $this->mCode; }
201 - public function getRevisionID() { return $this->mRevisionID; }
202 - public function getSource() { return $this->mSource; }
 200+ public function getEngine() { return $this->engine; }
 201+ public function getTitle() { return $this->title; }
 202+ public function getCode() { return $this->code; }
 203+ public function getRevisionID() { return $this->revisionID; }
 204+ public function getSource() { return $this->source; }
203205
204206 /**
205207 * Initialize the module. That means parse it and load the
@@ -227,10 +229,10 @@
228230 protected $mName, $mContents, $mModule, $mEngine;
229231
230232 public function __construct( $module, $name, $contents ) {
231 - $this->mName = $name;
232 - $this->mContents = $contents;
233 - $this->mModule = $module;
234 - $this->mEngine = $module->getEngine();
 233+ $this->name = $name;
 234+ $this->contents = $contents;
 235+ $this->module = $module;
 236+ $this->engine = $module->getEngine();
235237 }
236238
237239 /**
@@ -242,7 +244,7 @@
243245 abstract public function call( $args, $frame );
244246
245247 /** Accessors **/
246 - public function getName() { return $this->mName; }
247 - public function getModule() { return $this->mModule; }
248 - public function getEngine() { return $this->mEngine; }
 248+ public function getName() { return $this->name; }
 249+ public function getModule() { return $this->module; }
 250+ public function getEngine() { return $this->engine; }
249251 }
Index: trunk/extensions/Scripting/common/LinkUpdates.php
@@ -115,12 +115,12 @@
116116 * with templates.
117117 */
118118 class ScriptLinksUpdate {
119 - var $mUpdate, $mId, $mNew;
 119+ var $update, $id, $new;
120120
121121 public function __construct( $update, $new ) {
122 - $this->mUpdate = $update;
123 - $this->mId = $update->mId;
124 - $this->mNew = $new;
 122+ $this->update = $update;
 123+ $this->id = $update->mId;
 124+ $this->new = $new;
125125 }
126126
127127 public function run() {
@@ -129,14 +129,14 @@
130130 wfProfileIn( __METHOD__ );
131131
132132 if( $wgUseDumbLinkUpdate ) {
133 - $this->mUpdate->dumbTableUpdate( 'scriptlinks', $this->getScriptInsertions(), 'sl_from' );
 133+ $this->update->dumbTableUpdate( 'scriptlinks', $this->getScriptInsertions(), 'sl_from' );
134134 } else {
135135 $existing = $this->getExistingScripts();
136 - $this->mUpdate->incrTableUpdate( 'scriptlinks', 'sl', $this->getScriptDeletions( $existing ),
 136+ $this->update->incrTableUpdate( 'scriptlinks', 'sl', $this->getScriptDeletions( $existing ),
137137 $this->getScriptInsertions( $existing ) );
138138 }
139139
140 - if( $this->mUpdate->mRecursive && $this->mUpdate->mTitle->getNamespace() == NS_MODULE ) {
 140+ if( $this->update->mRecursive && $this->update->mTitle->getNamespace() == NS_MODULE ) {
141141 $this->queueRecursiveJobs();
142142 }
143143
@@ -146,8 +146,8 @@
147147 protected function getExistingScripts() {
148148 $result = array();
149149
150 - $res = $this->mUpdate->mDb->select( 'scriptlinks', array( 'sl_to' ),
151 - array( 'sl_from' => $this->mId ), __METHOD__, $this->mUpdate->mOptions );
 150+ $res = $this->update->mDb->select( 'scriptlinks', array( 'sl_to' ),
 151+ array( 'sl_from' => $this->id ), __METHOD__, $this->update->mOptions );
152152 foreach ( $res as $row ) {
153153 $result[] = $row->sl_to;
154154 }
@@ -158,9 +158,9 @@
159159 protected function getScriptInsertions( $existing = array() ) {
160160 $result = array();
161161
162 - foreach( array_diff( $this->mNew, $existing ) as $module ) {
 162+ foreach( array_diff( $this->new, $existing ) as $module ) {
163163 $result[] = array(
164 - 'sl_from' => $this->mId,
 164+ 'sl_from' => $this->id,
165165 'sl_to' => $module,
166166 );
167167 }
@@ -171,9 +171,9 @@
172172 protected function getScriptDeletions( $existing = array() ) {
173173 $result = array();
174174
175 - foreach( array_diff( $existing, $this->mNew ) as $module ) {
 175+ foreach( array_diff( $existing, $this->new ) as $module ) {
176176 $result[] = array(
177 - 'sl_from' => $this->mId,
 177+ 'sl_from' => $this->id,
178178 'sl_to' => $module,
179179 );
180180 }
@@ -185,7 +185,7 @@
186186 global $wgUpdateRowsPerJob;
187187 wfProfileIn( __METHOD__ );
188188
189 - $cache = $this->mUpdate->mTitle->getBacklinkCache();
 189+ $cache = $this->update->mTitle->getBacklinkCache();
190190 $batches = $cache->partition( 'scriptlinks', $wgUpdateRowsPerJob );
191191 if ( !$batches ) {
192192 wfProfileOut( __METHOD__ );
@@ -199,7 +199,7 @@
200200 'start' => $start,
201201 'end' => $end,
202202 );
203 - $jobs[] = new RefreshLinksJob2( $this->mUpdate->mTitle, $params );
 203+ $jobs[] = new RefreshLinksJob2( $this->update->mTitle, $params );
204204 }
205205 Job::batchInsert( $jobs );
206206
Index: trunk/extensions/Scripting/engines/LuaSandbox/Engine.php
@@ -1,14 +1,14 @@
22 <?php
33
44 class LuaSandboxEngine extends ScriptingEngineBase {
5 - public $mSandbox, $mLoaded = false;
 5+ public $sandbox, $loaded = false;
66
77 public function newModule( $title, $code, $revisionID, $source ) {
88 return new LuaSandboxEngineModule( $this, $title, $code, $revisionID, $source );
99 }
1010
1111 public function load() {
12 - if( $this->mLoaded ) {
 12+ if( $this->loaded ) {
1313 return;
1414 }
1515
@@ -16,18 +16,18 @@
1717 throw new MWException( 'luasandbox PHP extension is not installed' );
1818 }
1919
20 - $this->mSandbox = new LuaSandbox;
21 - $this->mSandbox->setMemoryLimit( $this->mOptions['memoryLimit'] );
22 - $this->mSandbox->setCPULimit( $this->mOptions['maxCPU'] );
23 - $this->mSandbox->registerLibrary( 'mw', array( 'import' => array( $this, 'importModule' ) ) );
 20+ $this->sandbox = new LuaSandbox;
 21+ $this->sandbox->setMemoryLimit( $this->options['memoryLimit'] );
 22+ $this->sandbox->setCPULimit( $this->options['maxCPU'] );
 23+ $this->sandbox->registerLibrary( 'mw', array( 'import' => array( $this, 'importModule' ) ) );
2424
25 - $this->mLoaded = true;
 25+ $this->loaded = true;
2626 }
2727
2828 protected function updateOptions() {
29 - if( $this->mLoaded ) {
30 - $this->mSandbox->setMemoryLimit( $this->mOptions['memoryLimit'] );
31 - $this->mSandbox->setCPULimit( $this->mOptions['maxCPU'] );
 29+ if( $this->loaded ) {
 30+ $this->sandbox->setMemoryLimit( $this->options['memoryLimit'] );
 31+ $this->sandbox->setCPULimit( $this->options['maxCPU'] );
3232 }
3333 }
3434
@@ -53,7 +53,7 @@
5454 public function getLimitsReport() {
5555 $this->load();
5656
57 - $usage = $this->mSandbox->getMemoryUsage();
 57+ $usage = $this->sandbox->getMemoryUsage();
5858 if( $usage < 8 * 1024 ) {
5959 $usageStr = $usage . " bytes";
6060 } elseif( $usage < 8 * 1024 * 1024 ) {
@@ -74,27 +74,27 @@
7575
7676 $module = $this->getModule( $args[0] );
7777 $module->initialize();
78 - return $module->mContents;
 78+ return $module->contents;
7979 }
8080 }
8181
8282 class LuaSandboxEngineModule extends ScriptingModuleBase {
83 - protected $mInitialized;
 83+ protected $initialized;
8484
8585 function initialize() {
86 - if( $this->mInitialized ) {
 86+ if( $this->initialized ) {
8787 return;
8888 }
89 - $this->mEngine->load();
 89+ $this->engine->load();
9090
9191 // FIXME: caching?
9292
9393 try {
94 - $this->mBody = $this->mEngine->mSandbox->loadString(
95 - $this->mCode,
 94+ $this->body = $this->engine->sandbox->loadString(
 95+ $this->code,
9696 // Prepending an "@" to the chunk name makes Lua think it is a file name
9797 '@' . $this->getTitle()->getPrefixedDBkey() );
98 - $output = $this->mBody->call();
 98+ $output = $this->body->call();
9999 } catch( LuaSandboxError $e ) {
100100 throw new ScriptingException( 'error', 'luasandbox', null, null, array( $e->getMessage() ) );
101101 }
@@ -109,21 +109,21 @@
110110 throw new ScriptingException( 'notarrayreturn', 'luasandbox' );
111111 }
112112
113 - $this->mContents = $output[0];
114 - $this->mFunctions = array();
115 - foreach( $this->mContents as $key => $content ) {
 113+ $this->contents = $output[0];
 114+ $this->functions = array();
 115+ foreach( $this->contents as $key => $content ) {
116116 if( $content instanceof LuaSandboxFunction )
117 - $this->mFunctions[] = $key;
 117+ $this->functions[] = $key;
118118 }
119119
120 - $this->mInitialized = true;
 120+ $this->initialized = true;
121121 }
122122
123123 function getFunction( $name ) {
124124 $this->initialize();
125125
126 - if( isset( $this->mContents[$name] ) ) {
127 - return new LuaSandboxEngineFunction( $this, $name, $this->mContents[$name] );
 126+ if( isset( $this->contents[$name] ) ) {
 127+ return new LuaSandboxEngineFunction( $this, $name, $this->contents[$name] );
128128 } else {
129129 return null;
130130 }
@@ -131,14 +131,14 @@
132132
133133 function getFunctions() {
134134 $this->initialize();
135 - return $this->mFunctions;
 135+ return $this->functions;
136136 }
137137 }
138138
139139 class LuaSandboxEngineFunction extends ScriptingFunctionBase {
140140 public function call( $args, $frame ) {
141141 try {
142 - $result = call_user_func_array( array( $this->mContents, 'call' ), $args );
 142+ $result = call_user_func_array( array( $this->contents, 'call' ), $args );
143143 } catch( LuaSandboxError $e ) {
144144 throw new ScriptingException( 'error', 'luasandbox', null, null, array( $e->getMessage() ) );
145145 }

Status & tagging log