https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114702
Revision: 114702
Author: tstarling
Date: 2012-04-04 06:10:32 +0000 (Wed, 04 Apr 2012)
Log Message:
-----------
First-pass cleanup:
* Removed ScriptingEngineBase::load(), inappropriate interface specification,
only used by child classes and more properly defined by them
* Fixed inappropriate use of final
* Fixed case of a class constant to conform with MediaWiki conventions
* Use a factory function interface for module creation instead of a class name
accessor
* Don't pass unnecessary $engine parameter to
ScriptingFunctionBase::__construct(). Pass parent object as the first parameter
per convention.
* Fixed unnecessary reference parameter in doRunHook()
* Have LuaSandboxEngineFunction::call() return the first result or null, per
the base class documentation, instead of imploding.
* Use strval() to avoid a warning in case call() returns an array or object
* Improved some comments
Modified Paths:
--------------
trunk/extensions/Scripting/common/Base.php
trunk/extensions/Scripting/common/Common.php
trunk/extensions/Scripting/common/Hooks.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-04 05:10:47 UTC (rev
114701)
+++ trunk/extensions/Scripting/common/Base.php 2012-04-04 06:10:32 UTC (rev
114702)
@@ -3,7 +3,6 @@
/**
* Wikitext scripting infrastructure for MediaWiki: base classes.
* Copyright (C) 2012 Victor Vasiliev <[email protected]> et al
- * Based on MediaWiki file LinksUpdate.php
* http://www.mediawiki.org/
*
* This program is free software; you can redistribute it and/or modify
@@ -31,21 +30,14 @@
protected
$mParser,
$mModules = array(),
- $mModuleTitles = array(),
- $mLoaded = false;
+ $mModuleTitles = array();
/**
- * Required for the lazy-loading of the engine. Should have a sentinel
- * inside checking whether it is already loaded.
+ * Creates a new module object within this engine
*/
- abstract public function load();
+ abstract protected function newModule( $title, $code, $revisionID,
$source );
/**
- * Returns the name of your module class.
- */
- abstract protected function getModuleClassName();
-
- /**
* Returns the default options of the engine.
*/
abstract public function getDefaultOptions();
@@ -61,7 +53,7 @@
*
* @param $parser Parser Wikitext parser
*/
- public final function __construct( $parser ) {
+ public function __construct( $parser ) {
$this->mParser = $parser;
}
@@ -74,7 +66,7 @@
* @param $source string Source of the module
* @return ScriptingEngineModule
*/
- public function getModule( $title, $source = Scripting::Local ) {
+ public function getModule( $title, $source = Scripting::LOCAL ) {
// Convert string to title
if( !$title instanceof Title ) {
$titleobj = Title::newFromText( (string)$title,
NS_MODULE );
@@ -97,8 +89,7 @@
}
// Create the class
- $class = $this->getModuleClassName();
- $this->mModules[$key] = new $class( $this, $title,
$rev->getText(), $rev->getID(), $source );
+ $this->mModules[$key] = $this->newModule( $title,
$rev->getText(), $rev->getID(), $source );
$this->mModuleTitles[] = $title;
}
return $this->mModules[$key];
@@ -108,7 +99,7 @@
* Fetches the revision for given module title.
*/
private function getModuleRev( $title, $source ) {
- if( $source != Scripting::Local ) {
+ if( $source != Scripting::LOCAL ) {
throw new MWException( 'Non-local scripts are not
supported at this point' );
}
@@ -128,7 +119,7 @@
}
/**
- * Validates the script and returns an array of the syntax erros for the
+ * Validates the script and returns an array of the syntax errors for
the
* given code.
*
* @param $code Code to validate
@@ -136,8 +127,7 @@
* @return array
*/
function validate( $code, $title ) {
- $class = $this->getModuleClassName();
- $module = new $class( $this, $title, $code, 0, Scripting::Local
);
+ $module = $this->newModule( $title, $code, 0, Scripting::LOCAL
);
try {
$module->initialize();
@@ -195,7 +185,7 @@
abstract class ScriptingModuleBase {
var $mEngine, $mTitle, $mCode, $mRevisionID, $mSource;
- public final function __construct( $engine, $title, $code, $revisionID,
$source ) {
+ public function __construct( $engine, $title, $code, $revisionID,
$source ) {
$this->mEngine = $engine;
$this->mTitle = $title;
$this->mCode = $code;
@@ -236,11 +226,11 @@
abstract class ScriptingFunctionBase {
protected $mName, $mContents, $mModule, $mEngine;
- public final function __construct( $name, $contents, $module, $engine )
{
+ public function __construct( $module, $name, $contents ) {
$this->mName = $name;
$this->mContents = $contents;
$this->mModule = $module;
- $this->mEngine = $engine;
+ $this->mEngine = $module->getEngine();
}
/**
Modified: trunk/extensions/Scripting/common/Common.php
===================================================================
--- trunk/extensions/Scripting/common/Common.php 2012-04-04 05:10:47 UTC
(rev 114701)
+++ trunk/extensions/Scripting/common/Common.php 2012-04-04 06:10:32 UTC
(rev 114702)
@@ -4,7 +4,7 @@
* Generic scripting functions.
*/
class Scripting {
- const Local = 'local';
+ const LOCAL = 'local';
protected static function getEngineClass() {
global $wgScriptingEngine, $wgScriptingEngines;
Modified: trunk/extensions/Scripting/common/Hooks.php
===================================================================
--- trunk/extensions/Scripting/common/Hooks.php 2012-04-04 05:10:47 UTC (rev
114701)
+++ trunk/extensions/Scripting/common/Hooks.php 2012-04-04 06:10:32 UTC (rev
114702)
@@ -21,7 +21,7 @@
*/
/**
- * Hooks for Scripting extension.
+ * Hooks for the Scripting extension.
*/
class ScriptingHooks {
/**
@@ -35,7 +35,7 @@
}
/**
- * Called when interpreter is to be reset.
+ * Called when the interpreter is to be reset.
*
* @static
* @param $parser Parser
@@ -47,7 +47,7 @@
}
/**
- * Adds scriptlinks table to parser tests.
+ * Add scriptlinks table to parser tests.
*/
public static function addTestTables( &$tables ) {
$tables[] = 'scriptlinks';
@@ -55,7 +55,7 @@
}
/**
- * Handles the {{#invoke:module|func}} construction.
+ * Hook function for {{#invoke:module|func}}
*
* @param $parser Parser
* @param $frame PPFrame
@@ -73,7 +73,7 @@
}
/**
- * Handles the transclusion of the script ({{script:module}} hook).
+ * Hook function for {{script:module}}
*
* @param $parser Parser
* @param $frame PPFrame
@@ -94,7 +94,7 @@
* @return string
* @throws ScriptingException
*/
- private static function doRunHook( &$parser, $frame, $module,
$function, $args ) {
+ private static function doRunHook( $parser, $frame, $module, $function,
$args ) {
wfProfileIn( __METHOD__ );
try {
@@ -104,7 +104,7 @@
$arg = $frame->expand( $arg );
}
- $module = $engine->getModule( $module, Scripting::Local
);
+ $module = $engine->getModule( $module, Scripting::LOCAL
);
$functionObj = $module->getFunction( $function );
if( !$functionObj ) {
@@ -114,7 +114,7 @@
$result = $functionObj->call( $args, $frame );
wfProfileOut( __METHOD__ );
- return trim( $result );
+ return trim( strval( $result ) );
} catch( ScriptingException $e ) {
$msg = $e->getMessage();
wfProfileOut( __METHOD__ );
Modified: trunk/extensions/Scripting/common/LinkUpdates.php
===================================================================
--- trunk/extensions/Scripting/common/LinkUpdates.php 2012-04-04 05:10:47 UTC
(rev 114701)
+++ trunk/extensions/Scripting/common/LinkUpdates.php 2012-04-04 06:10:32 UTC
(rev 114702)
@@ -31,7 +31,7 @@
*/
class ScriptLinksUpdateHooks {
/**
- * Appends script links to the output.
+ * Append script links to the output.
*/
public static function appendToOutput( &$parser, &$text ) {
if( isset( $parser->scripting_engine ) ) {
@@ -41,7 +41,7 @@
}
/**
- * Runs the link updater.
+ * Run the link updater.
*/
public static function updateLinks( &$update ) {
$output = $update->mParserOutput;
@@ -57,7 +57,7 @@
}
/**
- * Purges cache for all the pages where the script is used.
+ * Purge cache for all the pages where the script is used.
* @param $article Article
* @param $editInfo
* @param $changed
@@ -71,7 +71,7 @@
$engine = Scripting::getEngine( $wgParser );
$engine->invalidateModuleCache( $article->getTitle() );
- // Invalidate caches of articles which include the
script
+ // Invalidate the caches of articles which include the
script
$wgDeferredUpdateList[] = new HTMLCacheUpdate(
$article->getTitle(), 'scriptlinks' );
}
@@ -79,7 +79,7 @@
}
/**
- * Adds scriptlinks to the list of tables supported by BacklinkCache.
+ * Add scriptlinks to the list of tables supported by BacklinkCache.
*/
public static function getBacklinkCachePrefix( $table, &$prefix ) {
if( $table == 'scriptlinks' ) {
@@ -91,7 +91,7 @@
}
/**
- * Adds scriptlinks to the list of tables supported by BacklinkCache.
+ * Add scriptlinks to the list of tables supported by BacklinkCache.
* @param $table
* @param $title Title
* @param $conds
@@ -111,7 +111,7 @@
}
/**
- * A class that updates links on scripts like phase3/includes/LinksUpdate.php
does that
+ * A class that updates links on scripts like what
phase3/includes/LinksUpdate.php does
* with templates.
*/
class ScriptLinksUpdate {
Modified: trunk/extensions/Scripting/engines/LuaSandbox/Engine.php
===================================================================
--- trunk/extensions/Scripting/engines/LuaSandbox/Engine.php 2012-04-04
05:10:47 UTC (rev 114701)
+++ trunk/extensions/Scripting/engines/LuaSandbox/Engine.php 2012-04-04
06:10:32 UTC (rev 114702)
@@ -1,8 +1,12 @@
<?php
class LuaSandboxEngine extends ScriptingEngineBase {
- public $mSandbox;
+ public $mSandbox, $mLoaded = false;
+ public function newModule( $title, $code, $revisionID, $source ) {
+ return new LuaSandboxEngineModule( $this, $title, $code,
$revisionID, $source );
+ }
+
public function load() {
if( $this->mLoaded ) {
return;
@@ -119,7 +123,7 @@
$this->initialize();
if( isset( $this->mContents[$name] ) ) {
- return new LuaSandboxEngineFunction( $name,
$this->mContents[$name], $this, $this->mEngine );
+ return new LuaSandboxEngineFunction( $this, $name,
$this->mContents[$name] );
} else {
return null;
}
@@ -139,6 +143,10 @@
throw new ScriptingException( 'error', 'luasandbox',
null, null, array( $e->getMessage() ) );
}
- return implode( '', $result );
+ if ( isset( $result[0] ) ) {
+ return $result[0];
+ } else {
+ return null;
+ }
}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs