https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114733
Revision: 114733
Author: tstarling
Date: 2012-04-05 03:53:05 +0000 (Thu, 05 Apr 2012)
Log Message:
-----------
* 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
trunk/extensions/Scripting/common/Common.php
trunk/extensions/Scripting/common/LinkUpdates.php
trunk/extensions/Scripting/engines/LuaSandbox/Engine.php
Modified: trunk/extensions/Scripting/common/Base.php
===================================================================
--- trunk/extensions/Scripting/common/Base.php 2012-04-05 00:47:45 UTC (rev
114732)
+++ trunk/extensions/Scripting/common/Base.php 2012-04-05 03:53:05 UTC (rev
114733)
@@ -28,9 +28,9 @@
*/
abstract class ScriptingEngineBase {
protected
- $mParser,
- $mModules = array(),
- $mModuleTitles = array();
+ $parser,
+ $modules = array(),
+ $moduleTitles = array();
/**
* Creates a new module object within this engine
@@ -40,7 +40,9 @@
/**
* Returns the default options of the engine.
*/
- abstract public function getDefaultOptions();
+ public function getDefaultOptions() {
+ return array();
+ }
/**
* Is called by setOptions() in order to notify the engine
@@ -54,7 +56,7 @@
* @param $parser Parser Wikitext parser
*/
public function __construct( $parser ) {
- $this->mParser = $parser;
+ $this->parser = $parser;
}
/**
@@ -78,7 +80,7 @@
// Check if it is already loaded
$key = $title->getPrefixedText();
- if( !isset( $this->mModules[$key] ) ) {
+ if( !isset( $this->modules[$key] ) ) {
// Fetch the text
$rev = $this->getModuleRev( $title, $source );
if( !$rev ) {
@@ -89,10 +91,10 @@
}
// Create the class
- $this->mModules[$key] = $this->newModule( $title,
$rev->getText(), $rev->getID(), $source );
- $this->mModuleTitles[] = $title;
+ $this->modules[$key] = $this->newModule( $title,
$rev->getText(), $rev->getID(), $source );
+ $this->moduleTitles[] = $title;
}
- return $this->mModules[$key];
+ return $this->modules[$key];
}
/**
@@ -114,7 +116,7 @@
* Sets the engine-specific options from $wgScriptingEngineConf.
*/
function setOptions( $options ) {
- $this->mOptions = array_merge( $this->getDefaultOptions(),
$options );
+ $this->options = array_merge( $this->getDefaultOptions(),
$options );
$this->updateOptions();
}
@@ -152,7 +154,7 @@
* engine.
*/
public function getUsedModules() {
- return $this->mModuleTitles;
+ return $this->moduleTitles;
}
/**
@@ -183,22 +185,22 @@
* and maintaining the contents of the module.
*/
abstract class ScriptingModuleBase {
- var $mEngine, $mTitle, $mCode, $mRevisionID, $mSource;
+ var $engine, $title, $code, $revisionID, $source;
public function __construct( $engine, $title, $code, $revisionID,
$source ) {
- $this->mEngine = $engine;
- $this->mTitle = $title;
- $this->mCode = $code;
- $this->mRevisionID = $revisionID;
- $this->mSource = $source;
+ $this->engine = $engine;
+ $this->title = $title;
+ $this->code = $code;
+ $this->revisionID = $revisionID;
+ $this->source = $source;
}
/** Accessors **/
- public function getEngine() { return $this->mEngine; }
- public function getTitle() { return $this->mTitle; }
- public function getCode() { return $this->mCode; }
- public function getRevisionID() { return $this->mRevisionID; }
- public function getSource() { return $this->mSource; }
+ public function getEngine() { return $this->engine; }
+ public function getTitle() { return $this->title; }
+ public function getCode() { return $this->code; }
+ public function getRevisionID() { return $this->revisionID; }
+ public function getSource() { return $this->source; }
/**
* Initialize the module. That means parse it and load the
@@ -227,10 +229,10 @@
protected $mName, $mContents, $mModule, $mEngine;
public function __construct( $module, $name, $contents ) {
- $this->mName = $name;
- $this->mContents = $contents;
- $this->mModule = $module;
- $this->mEngine = $module->getEngine();
+ $this->name = $name;
+ $this->contents = $contents;
+ $this->module = $module;
+ $this->engine = $module->getEngine();
}
/**
@@ -242,7 +244,7 @@
abstract public function call( $args, $frame );
/** Accessors **/
- public function getName() { return $this->mName; }
- public function getModule() { return $this->mModule; }
- public function getEngine() { return $this->mEngine; }
+ public function getName() { return $this->name; }
+ public function getModule() { return $this->module; }
+ public function getEngine() { return $this->engine; }
}
Modified: trunk/extensions/Scripting/common/Common.php
===================================================================
--- trunk/extensions/Scripting/common/Common.php 2012-04-05 00:47:45 UTC
(rev 114732)
+++ trunk/extensions/Scripting/common/Common.php 2012-04-05 03:53:05 UTC
(rev 114733)
@@ -37,9 +37,8 @@
}
/**
- * Exceptions which represents user-originating error in the script.
- * Please do not use it for internal errors like "oh god, this should have
never happened".
- * Use casual MWException for that.
+ * An exception class which represents an error in the script. This does not
+ * normally abort the request, instead it is caught and shown to the user.
*/
class ScriptingException extends MWException {
function __construct( $exceptionID, $engine, $module = null, $line =
null, $params = array() ) {
@@ -51,13 +50,13 @@
}
parent::__construct( $msg );
- $this->mExceptionID = $exceptionID;
- $this->mLine = $line;
- $this->mModule = $module;
- $this->mParams = $params;
+ $this->exceptionID = $exceptionID;
+ $this->line = $line;
+ $this->module = $module;
+ $this->params = $params;
}
public function getExceptionID() {
- return $this->mExceptionID;
+ return $this->exceptionID;
}
}
Modified: trunk/extensions/Scripting/common/LinkUpdates.php
===================================================================
--- trunk/extensions/Scripting/common/LinkUpdates.php 2012-04-05 00:47:45 UTC
(rev 114732)
+++ trunk/extensions/Scripting/common/LinkUpdates.php 2012-04-05 03:53:05 UTC
(rev 114733)
@@ -115,12 +115,12 @@
* with templates.
*/
class ScriptLinksUpdate {
- var $mUpdate, $mId, $mNew;
+ var $update, $id, $new;
public function __construct( $update, $new ) {
- $this->mUpdate = $update;
- $this->mId = $update->mId;
- $this->mNew = $new;
+ $this->update = $update;
+ $this->id = $update->mId;
+ $this->new = $new;
}
public function run() {
@@ -129,14 +129,14 @@
wfProfileIn( __METHOD__ );
if( $wgUseDumbLinkUpdate ) {
- $this->mUpdate->dumbTableUpdate( 'scriptlinks',
$this->getScriptInsertions(), 'sl_from' );
+ $this->update->dumbTableUpdate( 'scriptlinks',
$this->getScriptInsertions(), 'sl_from' );
} else {
$existing = $this->getExistingScripts();
- $this->mUpdate->incrTableUpdate( 'scriptlinks', 'sl',
$this->getScriptDeletions( $existing ),
+ $this->update->incrTableUpdate( 'scriptlinks', 'sl',
$this->getScriptDeletions( $existing ),
$this->getScriptInsertions( $existing ) );
}
- if( $this->mUpdate->mRecursive &&
$this->mUpdate->mTitle->getNamespace() == NS_MODULE ) {
+ if( $this->update->mRecursive &&
$this->update->mTitle->getNamespace() == NS_MODULE ) {
$this->queueRecursiveJobs();
}
@@ -146,8 +146,8 @@
protected function getExistingScripts() {
$result = array();
- $res = $this->mUpdate->mDb->select( 'scriptlinks', array(
'sl_to' ),
- array( 'sl_from' => $this->mId ), __METHOD__,
$this->mUpdate->mOptions );
+ $res = $this->update->mDb->select( 'scriptlinks', array(
'sl_to' ),
+ array( 'sl_from' => $this->id ), __METHOD__,
$this->update->mOptions );
foreach ( $res as $row ) {
$result[] = $row->sl_to;
}
@@ -158,9 +158,9 @@
protected function getScriptInsertions( $existing = array() ) {
$result = array();
- foreach( array_diff( $this->mNew, $existing ) as $module ) {
+ foreach( array_diff( $this->new, $existing ) as $module ) {
$result[] = array(
- 'sl_from' => $this->mId,
+ 'sl_from' => $this->id,
'sl_to' => $module,
);
}
@@ -171,9 +171,9 @@
protected function getScriptDeletions( $existing = array() ) {
$result = array();
- foreach( array_diff( $existing, $this->mNew ) as $module ) {
+ foreach( array_diff( $existing, $this->new ) as $module ) {
$result[] = array(
- 'sl_from' => $this->mId,
+ 'sl_from' => $this->id,
'sl_to' => $module,
);
}
@@ -185,7 +185,7 @@
global $wgUpdateRowsPerJob;
wfProfileIn( __METHOD__ );
- $cache = $this->mUpdate->mTitle->getBacklinkCache();
+ $cache = $this->update->mTitle->getBacklinkCache();
$batches = $cache->partition( 'scriptlinks',
$wgUpdateRowsPerJob );
if ( !$batches ) {
wfProfileOut( __METHOD__ );
@@ -199,7 +199,7 @@
'start' => $start,
'end' => $end,
);
- $jobs[] = new RefreshLinksJob2( $this->mUpdate->mTitle,
$params );
+ $jobs[] = new RefreshLinksJob2( $this->update->mTitle,
$params );
}
Job::batchInsert( $jobs );
Modified: trunk/extensions/Scripting/engines/LuaSandbox/Engine.php
===================================================================
--- trunk/extensions/Scripting/engines/LuaSandbox/Engine.php 2012-04-05
00:47:45 UTC (rev 114732)
+++ trunk/extensions/Scripting/engines/LuaSandbox/Engine.php 2012-04-05
03:53:05 UTC (rev 114733)
@@ -1,14 +1,14 @@
<?php
class LuaSandboxEngine extends ScriptingEngineBase {
- public $mSandbox, $mLoaded = false;
+ public $sandbox, $loaded = false;
public function newModule( $title, $code, $revisionID, $source ) {
return new LuaSandboxEngineModule( $this, $title, $code,
$revisionID, $source );
}
public function load() {
- if( $this->mLoaded ) {
+ if( $this->loaded ) {
return;
}
@@ -16,18 +16,18 @@
throw new MWException( 'luasandbox PHP extension is not
installed' );
}
- $this->mSandbox = new LuaSandbox;
- $this->mSandbox->setMemoryLimit( $this->mOptions['memoryLimit']
);
- $this->mSandbox->setCPULimit( $this->mOptions['maxCPU'] );
- $this->mSandbox->registerLibrary( 'mw', array( 'import' =>
array( $this, 'importModule' ) ) );
+ $this->sandbox = new LuaSandbox;
+ $this->sandbox->setMemoryLimit( $this->options['memoryLimit'] );
+ $this->sandbox->setCPULimit( $this->options['maxCPU'] );
+ $this->sandbox->registerLibrary( 'mw', array( 'import' =>
array( $this, 'importModule' ) ) );
- $this->mLoaded = true;
+ $this->loaded = true;
}
protected function updateOptions() {
- if( $this->mLoaded ) {
- $this->mSandbox->setMemoryLimit(
$this->mOptions['memoryLimit'] );
- $this->mSandbox->setCPULimit( $this->mOptions['maxCPU']
);
+ if( $this->loaded ) {
+ $this->sandbox->setMemoryLimit(
$this->options['memoryLimit'] );
+ $this->sandbox->setCPULimit( $this->options['maxCPU'] );
}
}
@@ -53,7 +53,7 @@
public function getLimitsReport() {
$this->load();
- $usage = $this->mSandbox->getMemoryUsage();
+ $usage = $this->sandbox->getMemoryUsage();
if( $usage < 8 * 1024 ) {
$usageStr = $usage . " bytes";
} elseif( $usage < 8 * 1024 * 1024 ) {
@@ -74,27 +74,27 @@
$module = $this->getModule( $args[0] );
$module->initialize();
- return $module->mContents;
+ return $module->contents;
}
}
class LuaSandboxEngineModule extends ScriptingModuleBase {
- protected $mInitialized;
+ protected $initialized;
function initialize() {
- if( $this->mInitialized ) {
+ if( $this->initialized ) {
return;
}
- $this->mEngine->load();
+ $this->engine->load();
// FIXME: caching?
try {
- $this->mBody = $this->mEngine->mSandbox->loadString(
- $this->mCode,
+ $this->body = $this->engine->sandbox->loadString(
+ $this->code,
// Prepending an "@" to the chunk name makes
Lua think it is a file name
'@' . $this->getTitle()->getPrefixedDBkey() );
- $output = $this->mBody->call();
+ $output = $this->body->call();
} catch( LuaSandboxError $e ) {
throw new ScriptingException( 'error', 'luasandbox',
null, null, array( $e->getMessage() ) );
}
@@ -109,21 +109,21 @@
throw new ScriptingException( 'notarrayreturn',
'luasandbox' );
}
- $this->mContents = $output[0];
- $this->mFunctions = array();
- foreach( $this->mContents as $key => $content ) {
+ $this->contents = $output[0];
+ $this->functions = array();
+ foreach( $this->contents as $key => $content ) {
if( $content instanceof LuaSandboxFunction )
- $this->mFunctions[] = $key;
+ $this->functions[] = $key;
}
- $this->mInitialized = true;
+ $this->initialized = true;
}
function getFunction( $name ) {
$this->initialize();
- if( isset( $this->mContents[$name] ) ) {
- return new LuaSandboxEngineFunction( $this, $name,
$this->mContents[$name] );
+ if( isset( $this->contents[$name] ) ) {
+ return new LuaSandboxEngineFunction( $this, $name,
$this->contents[$name] );
} else {
return null;
}
@@ -131,14 +131,14 @@
function getFunctions() {
$this->initialize();
- return $this->mFunctions;
+ return $this->functions;
}
}
class LuaSandboxEngineFunction extends ScriptingFunctionBase {
public function call( $args, $frame ) {
try {
- $result = call_user_func_array( array(
$this->mContents, 'call' ), $args );
+ $result = call_user_func_array( array( $this->contents,
'call' ), $args );
} catch( LuaSandboxError $e ) {
throw new ScriptingException( 'error', 'luasandbox',
null, null, array( $e->getMessage() ) );
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs