jenkins-bot has submitted this change and it was merged.

Change subject: Cleanup backwards-compatibility code
......................................................................


Cleanup backwards-compatibility code

https://www.mediawiki.org/wiki/Extension:Scribunto says that master
requires 1.25+, so let's remove checks for stuff that was added before
that.

* PPFrame::getTTL() was in 1.24.
* PPFrame::setTTL() was in 1.24.
* PPFrame::isVolatile() was in 1.24.
* Parser::fetchCurrentRevisionOfTitle() was in 1.24.
* ObjectCache::getLocalServerInstance() was added in 1.27, so restore the call 
to ObjectCache::newAccelerator() as BC.

This also removes BC with the php-luasandbox extension older than 1.6, which
was released before MediaWiki 1.22.

Bug: T148012
Change-Id: I36e37f3b65d0f167e1d28b00e0842d9721feee31
---
D Scribunto.i18n.php
M Scribunto.php
M common/ApiScribuntoConsole.php
M common/Hooks.php
M common/ScribuntoContent.php
M engines/LuaCommon/LuaCommon.php
M engines/LuaCommon/LuaInterpreter.php
M engines/LuaCommon/TitleLibrary.php
M engines/LuaSandbox/Engine.php
M engines/LuaStandalone/LuaStandaloneEngine.php
M tests/engines/LuaCommon/CommonTest.php
M tests/engines/LuaCommon/LanguageLibraryTest.php
M tests/engines/LuaSandbox/SandboxTest.php
13 files changed, 57 insertions(+), 134 deletions(-)

Approvals:
  Paladox: Looks good to me, but someone else must approve
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Scribunto.i18n.php b/Scribunto.i18n.php
deleted file mode 100644
index 838da4e..0000000
--- a/Scribunto.i18n.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * This is a backwards-compatibility shim, generated by:
- * 
https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php
- *
- * Beginning with MediaWiki 1.23, translation strings are stored in json files,
- * and the EXTENSION.i18n.php file only exists to provide compatibility with
- * older releases of MediaWiki. For more information about this migration, see:
- * https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format
- *
- * This shim maintains compatibility back to MediaWiki 1.17.
- */
-$messages = array();
-if ( !function_exists( 'wfJsonI18nShimc5d9278c8d74fbc1' ) ) {
-       function wfJsonI18nShimc5d9278c8d74fbc1( $cache, $code, &$cachedData ) {
-               $codeSequence = array_merge( array( $code ), 
$cachedData['fallbackSequence'] );
-               foreach ( $codeSequence as $csCode ) {
-                       $fileName = __DIR__ . "/i18n/$csCode.json";
-                       if ( is_readable( $fileName ) ) {
-                               $data = FormatJson::decode( file_get_contents( 
$fileName ), true );
-                               foreach ( array_keys( $data ) as $key ) {
-                                       if ( $key === '' || $key[0] === '@' ) {
-                                               unset( $data[$key] );
-                                       }
-                               }
-                               $cachedData['messages'] = array_merge( $data, 
$cachedData['messages'] );
-                       }
-
-                       $cachedData['deps'][] = new FileDependency( $fileName );
-               }
-               return true;
-       }
-
-       $GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 
'wfJsonI18nShimc5d9278c8d74fbc1';
-}
diff --git a/Scribunto.php b/Scribunto.php
index 883b663..9e4f09f 100644
--- a/Scribunto.php
+++ b/Scribunto.php
@@ -51,6 +51,8 @@
 $wgAutoloadClasses['Scribunto_LuaError'] = __DIR__ . 
'/engines/LuaCommon/LuaCommon.php';
 $wgAutoloadClasses['Scribunto_LuaInterpreterNotFoundError'] =
        __DIR__ . '/engines/LuaCommon/LuaInterpreter.php';
+$wgAutoloadClasses['Scribunto_LuaInterpreterBadVersionError'] =
+       __DIR__ . '/engines/LuaCommon/LuaInterpreter.php';
 $wgAutoloadClasses['Scribunto_LuaSandboxInterpreter'] = __DIR__ . 
'/engines/LuaSandbox/Engine.php';
 $wgAutoloadClasses['Scribunto_LuaSandboxCallback'] = __DIR__ . 
'/engines/LuaSandbox/Engine.php';
 $wgAutoloadClasses['Scribunto_LuaStandaloneInterpreterFunction'] =
diff --git a/common/ApiScribuntoConsole.php b/common/ApiScribuntoConsole.php
index 7276b3c..56ecd5f 100644
--- a/common/ApiScribuntoConsole.php
+++ b/common/ApiScribuntoConsole.php
@@ -149,23 +149,4 @@
                        ),
                );
        }
-
-       /**
-        * @deprecated since MediaWiki core 1.25
-        */
-       public function getParamDescription() {
-               return array(
-                       'title' => 'The module title to test',
-                       'content' => 'The new content of the module',
-                       'question' => 'The next line to evaluate as a script',
-                       'clear' => 'Set this to true to clear the current 
session state',
-               );
-       }
-
-       /**
-        * @deprecated since MediaWiki core 1.25
-        */
-       public function getDescription() {
-               return 'Internal module for servicing XHR requests from the 
Scribunto console';
-       }
 }
diff --git a/common/Hooks.php b/common/Hooks.php
index baccde3..86449af 100644
--- a/common/Hooks.php
+++ b/common/Hooks.php
@@ -83,11 +83,6 @@
        public static function invokeHook( Parser &$parser, PPFrame $frame, 
array $args ) {
                global $wgScribuntoGatherFunctionStats;
 
-               if ( !defined( get_class( $frame ) . '::SUPPORTS_INDEX_OFFSET' 
) ) {
-                       throw new MWException(
-                               'Scribunto needs MediaWiki 1.20 or later 
(Preprocessor::SUPPORTS_INDEX_OFFSET)' );
-               }
-
                try {
                        if ( count( $args ) < 2 ) {
                                throw new ScribuntoException( 
'scribunto-common-nofunction' );
@@ -190,7 +185,12 @@
                static $cache;
 
                if ( !$cache ) {
-                       $cache = ObjectCache::getLocalServerInstance( 
CACHE_NONE );
+                       /// @todo: Clean up when support for MW < 1.27 is 
dropped
+                       if ( is_callable( 'ObjectCache::getLocalServerInstance' 
) ) {
+                               $cache = ObjectCache::getLocalServerInstance( 
CACHE_NONE );
+                       } else {
+                               $cache = ObjectCache::newAccelerator( 
CACHE_NONE );
+                       }
                }
 
                // To control the sampling rate, we keep a compact histogram of
diff --git a/common/ScribuntoContent.php b/common/ScribuntoContent.php
index f90251f..89f3058 100644
--- a/common/ScribuntoContent.php
+++ b/common/ScribuntoContent.php
@@ -161,8 +161,7 @@
 
        /**
         * Fetch the text from a ParserOutput
-        * @todo Once support for MW without ParserOutput::getRawText() is 
dropped,
-        *  inline this.
+        * @todo Once support for MW < 1.27 is dropped, inline this.
         * @param ParserOutput $po
         * @return string
         */
diff --git a/engines/LuaCommon/LuaCommon.php b/engines/LuaCommon/LuaCommon.php
index 9de4784..06b70f1 100644
--- a/engines/LuaCommon/LuaCommon.php
+++ b/engines/LuaCommon/LuaCommon.php
@@ -219,7 +219,7 @@
                );
                $this->expandCache = array();
 
-               // @todo Once support for PHP 5.3 is dropped, lose $ref and 
just use
+               // @todo Once support for PHP 5.3 (MW < 1.27) is dropped, lose 
$ref and just use
                // $this->currentFrames directly in the callback.
                $ref = &$this->currentFrames;
                $ref2 = &$this->expandCache;
@@ -315,7 +315,12 @@
                static $cache = null;
 
                if ( !$cache ) {
-                       $cache = ObjectCache::getLocalServerInstance( 'hash' );
+                       /// @todo: Clean up when support for MW < 1.27 is 
dropped
+                       if ( is_callable( 'ObjectCache::getLocalServerInstance' 
) ) {
+                               $cache = ObjectCache::getLocalServerInstance( 
'hash' );
+                       } else {
+                               $cache = ObjectCache::newAccelerator( 'hash' );
+                       }
                }
 
                $mtime = filemtime( $fileName );
@@ -611,9 +616,7 @@
                $this->checkNumber( 'setTTL', $args, 0 );
 
                $frame = $this->getFrameById( 'current' );
-               if ( is_callable( array( $frame, 'setTTL' ) ) ) {
-                       $frame->setTTL( $ttl );
-               }
+               $frame->setTTL( $ttl );
        }
 
        /**
@@ -836,7 +839,7 @@
                        $dom = $input;
                }
                $ret = $frame->expand( $dom );
-               if ( !is_callable( array( $frame, 'isVolatile' ) ) || 
!$frame->isVolatile() ) {
+               if ( !$frame->isVolatile() ) {
                        if ( count( $this->expandCache ) > 
self::MAX_EXPAND_CACHE_SIZE ) {
                                reset( $this->expandCache );
                                $oldHash = key( $this->expandCache );
diff --git a/engines/LuaCommon/LuaInterpreter.php 
b/engines/LuaCommon/LuaInterpreter.php
index 4db9678..c729e3f 100644
--- a/engines/LuaCommon/LuaInterpreter.php
+++ b/engines/LuaCommon/LuaInterpreter.php
@@ -62,3 +62,6 @@
 
 // @codingStandardsIgnoreLine Squiz.Classes.ValidClassName.NotCamelCaps
 class Scribunto_LuaInterpreterNotFoundError extends MWException {}
+
+// @codingStandardsIgnoreLine Squiz.Classes.ValidClassName.NotCamelCaps
+class Scribunto_LuaInterpreterBadVersionError extends MWException {}
diff --git a/engines/LuaCommon/TitleLibrary.php 
b/engines/LuaCommon/TitleLibrary.php
index 862c046..6c46399 100644
--- a/engines/LuaCommon/TitleLibrary.php
+++ b/engines/LuaCommon/TitleLibrary.php
@@ -266,11 +266,7 @@
                        $this->getParser()->getOutput()->setFlag( 
'vary-revision' );
                }
 
-               if ( is_callable( array( $this->getParser(), 
'fetchCurrentRevisionOfTitle' ) ) ) {
-                       $rev = $this->getParser()->fetchCurrentRevisionOfTitle( 
$title );
-               } else {
-                       $rev = Revision::newFromTitle( $title );
-               }
+               $rev = $this->getParser()->fetchCurrentRevisionOfTitle( $title 
);
                return $rev ? $rev->getContent() : null;
        }
 
diff --git a/engines/LuaSandbox/Engine.php b/engines/LuaSandbox/Engine.php
index ad867bc..22eb1e5 100644
--- a/engines/LuaSandbox/Engine.php
+++ b/engines/LuaSandbox/Engine.php
@@ -12,23 +12,19 @@
        }
 
        public function getSoftwareInfo( array &$software ) {
-               if ( !extension_loaded( 'luasandbox' ) ) {
+               try {
+                       
Scribunto_LuaSandboxInterpreter::checkLuaSandboxVersion();
+               } catch ( Scribunto_LuaInterpreterNotFoundError $e ) {
                        // They shouldn't be using this engine if the extension 
isn't
                        // loaded. But in case they do for some reason, let's 
not have
                        // Special:Version fatal.
                        return;
+               } catch ( Scribunto_LuaInterpreterBadVersionError $e ) {
+                       // Same for if the extension is too old.
+                       return;
                }
 
-               if ( is_callable( 'LuaSandbox::getVersionInfo' ) ) {
-                       $versions = LuaSandbox::getVersionInfo();
-               } else {
-                       $sandbox = new LuaSandbox;
-                       list( $luaver ) = $sandbox->loadString( 'return 
_VERSION' )->call();
-                       $versions = array(
-                               'LuaSandbox' => phpversion( "LuaSandbox" ),
-                               'Lua' => $luaver,
-                       );
-               }
+               $versions = LuaSandbox::getVersionInfo();
                
$software['[https://www.mediawiki.org/wiki/Extension:Scribunto#LuaSandbox 
LuaSandbox]'] =
                        $versions['LuaSandbox'];
                $software['[http://www.lua.org/ Lua]'] = str_replace( 'Lua ', 
'', $versions['Lua'] );
@@ -250,24 +246,38 @@
        const SECONDS = 1;
        const PERCENT = 2;
 
-       function __construct( $engine, array $options ) {
+       /**
+        * Check that php-luasandbox is available and of a recent-enough version
+        * @throws Scribunto_LuaInterpreterNotFoundError
+        * @throws Scribunto_LuaInterpreterBadVersionError
+        */
+       public static function checkLuaSandboxVersion() {
                if ( !extension_loaded( 'luasandbox' ) ) {
                        throw new Scribunto_LuaInterpreterNotFoundError(
                                'The luasandbox extension is not present, this 
engine cannot be used.' );
                }
+
+               if ( !is_callable( 'LuaSandbox::getVersionInfo' ) ) {
+                       throw new Scribunto_LuaInterpreterBadVersionError(
+                               'The luasandbox extension is too old (version 
1.6+ is required), ' .
+                                       'this engine cannot be used.'
+                       );
+               }
+       }
+
+       function __construct( $engine, array $options ) {
+               self::checkLuaSandboxVersion();
+
                $this->engine = $engine;
                $this->sandbox = new LuaSandbox;
                $this->sandbox->setMemoryLimit( $options['memoryLimit'] );
                $this->sandbox->setCPULimit( $options['cpuLimit'] );
-               if ( is_callable( array( $this->sandbox, 'enableProfiler' ) ) )
-               {
-                       if ( !isset( $options['profilerPeriod'] ) ) {
-                               $options['profilerPeriod'] = 0.02;
-                       }
-                       if ( $options['profilerPeriod'] ) {
-                               $this->profilerEnabled = true;
-                               $this->sandbox->enableProfiler( 
$options['profilerPeriod'] );
-                       }
+               if ( !isset( $options['profilerPeriod'] ) ) {
+                       $options['profilerPeriod'] = 0.02;
+               }
+               if ( $options['profilerPeriod'] ) {
+                       $this->profilerEnabled = true;
+                       $this->sandbox->enableProfiler( 
$options['profilerPeriod'] );
                }
        }
 
@@ -333,23 +343,7 @@
        }
 
        public function wrapPhpFunction( $callable ) {
-               if ( is_callable( array( $this->sandbox, 'wrapPhpFunction' ) ) 
) {
-                       return $this->sandbox->wrapPhpFunction( $callable );
-               }
-
-               // We have to hack around the lack of the wrapper function by 
loading a
-               // dummy library with $callable, then extracting the function, 
and then
-               // for good measure nilling out the library table.
-               list( $name ) = $this->sandbox->loadString( '
-                       for i = 0, math.huge do
-                               if not _G["*LuaSandbox* temp" .. i] then return 
"*LuaSandbox* temp" .. i end
-                       end
-                       ' )->call();
-               $this->sandbox->registerLibrary( $name, array( 'func' => 
$callable ) );
-               list( $func ) = $this->sandbox->loadString(
-                       "local ret = _G['$name'].func _G['$name'] = nil return 
ret"
-               )->call();
-               return $func;
+               return $this->sandbox->wrapPhpFunction( $callable );
        }
 
        public function isLuaFunction( $object ) {
@@ -380,15 +374,11 @@
        }
 
        public function pauseUsageTimer() {
-               if ( is_callable( array( $this->sandbox, 'pauseUsageTimer' ) ) 
) {
-                       $this->sandbox->pauseUsageTimer();
-               }
+               $this->sandbox->pauseUsageTimer();
        }
 
        public function unpauseUsageTimer() {
-               if ( is_callable( array( $this->sandbox, 'unpauseUsageTimer' ) 
) ) {
-                       $this->sandbox->unpauseUsageTimer();
-               }
+               $this->sandbox->unpauseUsageTimer();
        }
 }
 
diff --git a/engines/LuaStandalone/LuaStandaloneEngine.php 
b/engines/LuaStandalone/LuaStandaloneEngine.php
index 10adb24..598ad4a 100644
--- a/engines/LuaStandalone/LuaStandaloneEngine.php
+++ b/engines/LuaStandalone/LuaStandaloneEngine.php
@@ -270,7 +270,7 @@
                                throw $this->engine->newException( 
'scribunto-luastandalone-proc-error-msg',
                                        array( 'args' => array( $err['message'] 
) ) );
                        } elseif ( wfIniGetBool( 'safe_mode' ) ) {
-                               /** @todo: Remove this case once we no longer 
support PHP 5.3 */
+                               /** @todo: Remove this case once we no longer 
support PHP 5.3 (MW < 1.27) */
                                throw $this->engine->newException( 
'scribunto-luastandalone-proc-error-safe-mode' );
                        } else {
                                throw $this->engine->newException( 
'scribunto-luastandalone-proc-error' );
diff --git a/tests/engines/LuaCommon/CommonTest.php 
b/tests/engines/LuaCommon/CommonTest.php
index 51b2f20..a4cebb5 100644
--- a/tests/engines/LuaCommon/CommonTest.php
+++ b/tests/engines/LuaCommon/CommonTest.php
@@ -522,10 +522,6 @@
                $engine = $this->getEngine();
                $pp = $engine->getParser()->getPreprocessor();
 
-               if ( !is_callable( array( $pp->newFrame(), 'getTTL' ) ) ) {
-                       $this->markTestSkipped( "PPFrame::getTTL is not 
available" );
-               }
-
                $this->extraModules['Module:DateTime'] = '
                local p = {}
                function p.day()
@@ -618,10 +614,6 @@
                $engine = $this->getEngine();
                $parser = $engine->getParser();
                $pp = $parser->getPreprocessor();
-
-               if ( !is_callable( array( $pp->newFrame(), 'isVolatile' ) ) ) {
-                       $this->markTestSkipped( "PPFrame::isVolatile is not 
available" );
-               }
 
                $count = 0;
                $parser->setHook( 'scribuntocount', function ( $str, $argv, 
$parser, $frame ) use ( &$count ) {
diff --git a/tests/engines/LuaCommon/LanguageLibraryTest.php 
b/tests/engines/LuaCommon/LanguageLibraryTest.php
index 965aaad..c0d8e29 100644
--- a/tests/engines/LuaCommon/LanguageLibraryTest.php
+++ b/tests/engines/LuaCommon/LanguageLibraryTest.php
@@ -35,10 +35,6 @@
                $engine = $this->getEngine();
                $pp = $engine->getParser()->getPreprocessor();
 
-               if ( !is_callable( array( $pp->newFrame(), 'getTTL' ) ) ) {
-                       $this->markTestSkipped( "PPFrame::getTTL is not 
available" );
-               }
-
                $ttl = null;
                $wgContLang->sprintfDate( 's', '20130101000000', null, $ttl );
                if ( $ttl === null ) {
diff --git a/tests/engines/LuaSandbox/SandboxTest.php 
b/tests/engines/LuaSandbox/SandboxTest.php
index 6b45403..66afda6 100644
--- a/tests/engines/LuaSandbox/SandboxTest.php
+++ b/tests/engines/LuaSandbox/SandboxTest.php
@@ -20,10 +20,6 @@
                }
 
                $engine = $this->getEngine();
-               if ( !is_callable( array( $engine->getInterpreter()->sandbox, 
'pauseUsageTimer' ) ) ) {
-                       $this->markTestSkipped( "LuaSandbox::pauseUsageTimer is 
not available" );
-               }
-
                $parser = $engine->getParser();
                $pp = $parser->getPreprocessor();
                $frame = $pp->newFrame();

-- 
To view, visit https://gerrit.wikimedia.org/r/315689
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I36e37f3b65d0f167e1d28b00e0842d9721feee31
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Paladox <thomasmulhall...@yahoo.com>
Gerrit-Reviewer: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to