Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

CE-868 Add support for modules shared from dev.wikia.com #4550

Merged
merged 6 commits into from
Jun 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions extensions/Scribunto/common/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,31 @@ function fetchModuleFromParser( Title $title ) {
return $this->modules[$key];
}

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a whitespace between methods.

* Wikia change begin
* Load a shared module from dev.wikia.com.
* @author Adam Karmiński <adamk@wikia-inc.com>
* @param GlobalTitle $title GlobalTitle instance of a shared module.
* @return mixed Returns a module if found and null otherwise.
*/
function fetchSharedModule( GlobalTitle $title, $prefix ) {
$key = $prefix . $title->getText();

if ( !array_key_exists( $key, $this->modules ) ) {
$text = $title->getContent();
if ( $text === false ) {
$this->modules[$key] = null;
return null;
}
$this->modules[$key] = $this->newModule( $text, $key );
}

return $this->modules[$key];
}
/**
* Wikia change end
*/

/**
* Validates the script and returns a Status object containing the syntax
* errors for the given code.
Expand Down
36 changes: 32 additions & 4 deletions extensions/Scribunto/engines/LuaCommon/LuaCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ abstract class Scribunto_LuaEngine extends ScribuntoEngineBase {

const MAX_EXPAND_CACHE_SIZE = 100;

/**
* Wikia change begin
* Set constants for modules shared from dev.wikia.com
* @author Adam Karmiński <adamk@wikia-inc.com>
*/
const SHARED_MODULES_PREFIX = 'Dev:';
const SHARED_MODULES_DEV_CITYID = 7931;
/**
* Wikia change end
*/

/**
* Create a new interpreter object
* @return Scribunto_LuaInterpreter
Expand Down Expand Up @@ -314,12 +325,29 @@ function loadPackage( $name ) {
return array( $init );
}

$title = Title::newFromText( $name );
if ( !$title || $title->getNamespace() != NS_MODULE ) {
return array();
/**
* Wikia change begin
* Support modules shared from dev.wikia.com
* @author Adam Karmiński <adamk@wikia-inc.com>
*/
if ( strpos( $name, self::SHARED_MODULES_PREFIX ) === 0 ) {
$sNameOnDev = substr( $name, strlen( self::SHARED_MODULES_PREFIX ) );
$title = GlobalTitle::newFromText( $sNameOnDev, NS_MODULE, self::SHARED_MODULES_DEV_CITYID );
if ( !$title ) {
return array();
}
$module = $this->fetchSharedModule( $title, self::SHARED_MODULES_PREFIX );
} else {
$title = Title::newFromText( $name );
if ( !$title || $title->getNamespace() != NS_MODULE ) {
return array();
}
$module = $this->fetchModuleFromParser( $title );
}
/**
* Wikia change end
*/

$module = $this->fetchModuleFromParser( $title );
if ( $module ) {
return array( $module->getInitChunk() );
} else {
Expand Down