From cf05ed8e1567b7da2d04a0596b80b84bb27612e4 Mon Sep 17 00:00:00 2001 From: adamkarminski Date: Mon, 18 Aug 2014 14:00:38 +0000 Subject: [PATCH 1/6] Add method to fetch shared modules --- extensions/Scribunto/common/Base.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/extensions/Scribunto/common/Base.php b/extensions/Scribunto/common/Base.php index 462829bafcc5..73967422aac0 100644 --- a/extensions/Scribunto/common/Base.php +++ b/extensions/Scribunto/common/Base.php @@ -136,6 +136,26 @@ function fetchModuleFromParser( Title $title ) { } return $this->modules[$key]; } + /** + * Wikia change by adamk@wikia-inc.com + * Load shared a module from dev.wikia.com. + * @param GlobalTitle $title GlobalTitle instance of a shared module. + * @return mixed Returns a module if found and null otherwise. + */ + function fetchSharedModule( GlobalTitle $title ) { + $key = $title->getPrefixedText(); + + 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]; + } /** * Validates the script and returns a Status object containing the syntax From 50d33026e451b82815e313c643b767dd78d3168d Mon Sep 17 00:00:00 2001 From: adamkarminski Date: Mon, 18 Aug 2014 14:00:55 +0000 Subject: [PATCH 2/6] Add support for loading shared modules --- .../Scribunto/engines/LuaCommon/LuaCommon.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/extensions/Scribunto/engines/LuaCommon/LuaCommon.php b/extensions/Scribunto/engines/LuaCommon/LuaCommon.php index 1735e1469cb0..4643f5c4a0bd 100644 --- a/extensions/Scribunto/engines/LuaCommon/LuaCommon.php +++ b/extensions/Scribunto/engines/LuaCommon/LuaCommon.php @@ -314,12 +314,21 @@ function loadPackage( $name ) { return array( $init ); } - $title = Title::newFromText( $name ); - if ( !$title || $title->getNamespace() != NS_MODULE ) { - return array(); + if ( preg_match( "/^Dev:/", $name ) ) { + $sDevName = preg_replace( "/^Dev:/", "", $name ); + $title = GlobalTitle::newFromText( $sDevName, NS_MODULE, 7931 ); + if ( !$title ) { + return array(); + } + $module = $this->fetchSharedModule( $title ); + } else { + $title = Title::newFromText( $name ); + if ( !$title || $title->getNamespace() != NS_MODULE ) { + return array(); + } + $module = $this->fetchModuleFromParser( $title ); } - $module = $this->fetchModuleFromParser( $title ); if ( $module ) { return array( $module->getInitChunk() ); } else { From 0447b129027e2b4931b328178c121fc7864dea0a Mon Sep 17 00:00:00 2001 From: adamkarminski Date: Mon, 25 Aug 2014 11:41:23 +0000 Subject: [PATCH 3/6] Move Dev parameters to constants --- .../Scribunto/engines/LuaCommon/LuaCommon.php | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/extensions/Scribunto/engines/LuaCommon/LuaCommon.php b/extensions/Scribunto/engines/LuaCommon/LuaCommon.php index 4643f5c4a0bd..c59a7ddb99be 100644 --- a/extensions/Scribunto/engines/LuaCommon/LuaCommon.php +++ b/extensions/Scribunto/engines/LuaCommon/LuaCommon.php @@ -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 + */ + const SHARED_MODULES_PREFIX = "Dev:"; + const SHARED_MODULES_DEV_CITYID = 7931; + /** + * Wikia change end + */ + /** * Create a new interpreter object * @return Scribunto_LuaInterpreter @@ -314,20 +325,28 @@ function loadPackage( $name ) { return array( $init ); } - if ( preg_match( "/^Dev:/", $name ) ) { - $sDevName = preg_replace( "/^Dev:/", "", $name ); - $title = GlobalTitle::newFromText( $sDevName, NS_MODULE, 7931 ); + /** + * Wikia change begin + * Support modules shared from dev.wikia.com + * @author Adam Karmiński + */ + if ( strpos( SHARED_MODULES_PREFIX, $name ) !== FALSE ) { + $sNameOnDev = substr( $name, strlen( SHARED_MODULES_PREFIX ) ); + $title = GlobalTitle::newFromText( $sNameOnDev, NS_MODULE, SHARED_MODULES_DEV_CITYID ); if ( !$title ) { return array(); } $module = $this->fetchSharedModule( $title ); - } else { + } else { $title = Title::newFromText( $name ); if ( !$title || $title->getNamespace() != NS_MODULE ) { return array(); } $module = $this->fetchModuleFromParser( $title ); } + /** + * Wikia change end + */ if ( $module ) { return array( $module->getInitChunk() ); From e8b95860beae5076c315e89e68b6f6666fc8d039 Mon Sep 17 00:00:00 2001 From: adamkarminski Date: Mon, 25 Aug 2014 11:50:43 +0000 Subject: [PATCH 4/6] Distinguish keys for local and shared modules --- extensions/Scribunto/common/Base.php | 10 +++++++--- extensions/Scribunto/engines/LuaCommon/LuaCommon.php | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/extensions/Scribunto/common/Base.php b/extensions/Scribunto/common/Base.php index 73967422aac0..249924633382 100644 --- a/extensions/Scribunto/common/Base.php +++ b/extensions/Scribunto/common/Base.php @@ -137,13 +137,14 @@ function fetchModuleFromParser( Title $title ) { return $this->modules[$key]; } /** - * Wikia change by adamk@wikia-inc.com + * Wikia change begin * Load shared a module from dev.wikia.com. + * @author Adam Karmiński * @param GlobalTitle $title GlobalTitle instance of a shared module. * @return mixed Returns a module if found and null otherwise. */ - function fetchSharedModule( GlobalTitle $title ) { - $key = $title->getPrefixedText(); + function fetchSharedModule( GlobalTitle $title, $prefix ) { + $key = $prefix . $title->getText(); if( !array_key_exists( $key, $this->modules ) ) { $text = $title->getContent(); @@ -156,6 +157,9 @@ function fetchSharedModule( GlobalTitle $title ) { return $this->modules[$key]; } + /** + * Wikia change end + */ /** * Validates the script and returns a Status object containing the syntax diff --git a/extensions/Scribunto/engines/LuaCommon/LuaCommon.php b/extensions/Scribunto/engines/LuaCommon/LuaCommon.php index c59a7ddb99be..d31b833017d9 100644 --- a/extensions/Scribunto/engines/LuaCommon/LuaCommon.php +++ b/extensions/Scribunto/engines/LuaCommon/LuaCommon.php @@ -342,7 +342,7 @@ function loadPackage( $name ) { if ( !$title || $title->getNamespace() != NS_MODULE ) { return array(); } - $module = $this->fetchModuleFromParser( $title ); + $module = $this->fetchModuleFromParser( $title, SHARED_MODULES_PREFIX ); } /** * Wikia change end From 18c4d18a6d6c7a15ba7f9cea75394a68b6cff212 Mon Sep 17 00:00:00 2001 From: adamkarminski Date: Mon, 25 Aug 2014 11:54:09 +0000 Subject: [PATCH 5/6] Typo fix. --- extensions/Scribunto/common/Base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/Scribunto/common/Base.php b/extensions/Scribunto/common/Base.php index 249924633382..4db5f5e44e65 100644 --- a/extensions/Scribunto/common/Base.php +++ b/extensions/Scribunto/common/Base.php @@ -138,7 +138,7 @@ function fetchModuleFromParser( Title $title ) { } /** * Wikia change begin - * Load shared a module from dev.wikia.com. + * Load a shared module from dev.wikia.com. * @author Adam Karmiński * @param GlobalTitle $title GlobalTitle instance of a shared module. * @return mixed Returns a module if found and null otherwise. From 915926aa110f51cbc2d62ef9a7a2295b58ae4e05 Mon Sep 17 00:00:00 2001 From: adamkarminski Date: Tue, 26 Aug 2014 14:49:44 +0000 Subject: [PATCH 6/6] Matching conventions and constants fix --- extensions/Scribunto/common/Base.php | 3 ++- extensions/Scribunto/engines/LuaCommon/LuaCommon.php | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/extensions/Scribunto/common/Base.php b/extensions/Scribunto/common/Base.php index 4db5f5e44e65..d0e24fb5a934 100644 --- a/extensions/Scribunto/common/Base.php +++ b/extensions/Scribunto/common/Base.php @@ -136,6 +136,7 @@ function fetchModuleFromParser( Title $title ) { } return $this->modules[$key]; } + /** * Wikia change begin * Load a shared module from dev.wikia.com. @@ -146,7 +147,7 @@ function fetchModuleFromParser( Title $title ) { function fetchSharedModule( GlobalTitle $title, $prefix ) { $key = $prefix . $title->getText(); - if( !array_key_exists( $key, $this->modules ) ) { + if ( !array_key_exists( $key, $this->modules ) ) { $text = $title->getContent(); if ( $text === false ) { $this->modules[$key] = null; diff --git a/extensions/Scribunto/engines/LuaCommon/LuaCommon.php b/extensions/Scribunto/engines/LuaCommon/LuaCommon.php index d31b833017d9..1c3b9d1fec34 100644 --- a/extensions/Scribunto/engines/LuaCommon/LuaCommon.php +++ b/extensions/Scribunto/engines/LuaCommon/LuaCommon.php @@ -42,7 +42,7 @@ abstract class Scribunto_LuaEngine extends ScribuntoEngineBase { * Set constants for modules shared from dev.wikia.com * @author Adam Karmiński */ - const SHARED_MODULES_PREFIX = "Dev:"; + const SHARED_MODULES_PREFIX = 'Dev:'; const SHARED_MODULES_DEV_CITYID = 7931; /** * Wikia change end @@ -330,19 +330,19 @@ function loadPackage( $name ) { * Support modules shared from dev.wikia.com * @author Adam Karmiński */ - if ( strpos( SHARED_MODULES_PREFIX, $name ) !== FALSE ) { - $sNameOnDev = substr( $name, strlen( SHARED_MODULES_PREFIX ) ); - $title = GlobalTitle::newFromText( $sNameOnDev, NS_MODULE, SHARED_MODULES_DEV_CITYID ); + 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 ); + $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, SHARED_MODULES_PREFIX ); + $module = $this->fetchModuleFromParser( $title ); } /** * Wikia change end