Legoktm has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/372898 )
Change subject: Remove some PHP 5.3 compat code
......................................................................
Remove some PHP 5.3 compat code
Change-Id: I433ab9754606e2cbbaef534a1a5b70bad9b9387c
---
M engines/LuaCommon/LuaCommon.php
M engines/LuaCommon/TextLibrary.php
M engines/LuaCommon/UstringLibrary.php
M engines/LuaStandalone/LuaStandaloneEngine.php
M i18n/en.json
M i18n/qqq.json
6 files changed, 12 insertions(+), 43 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto
refs/changes/98/372898/1
diff --git a/engines/LuaCommon/LuaCommon.php b/engines/LuaCommon/LuaCommon.php
index 954c60d..335476f 100644
--- a/engines/LuaCommon/LuaCommon.php
+++ b/engines/LuaCommon/LuaCommon.php
@@ -245,13 +245,9 @@
];
$this->expandCache = [];
- // @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;
- return new ScopedCallback( function () use ( &$ref, &$ref2,
$oldFrames, $oldExpandCache ) {
- $ref = $oldFrames;
- $ref2 = $oldExpandCache;
+ return new ScopedCallback( function () use ( $oldFrames,
$oldExpandCache ) {
+ $this->currentFrames = $oldFrames;
+ $this->expandCache = $oldExpandCache;
} );
}
diff --git a/engines/LuaCommon/TextLibrary.php
b/engines/LuaCommon/TextLibrary.php
index df55fc5..5453ed9 100644
--- a/engines/LuaCommon/TextLibrary.php
+++ b/engines/LuaCommon/TextLibrary.php
@@ -62,11 +62,7 @@
}
function getEntityTable() {
- $flags = ENT_QUOTES;
- // PHP 5.3 compat
- if ( defined( "ENT_HTML5" ) ) {
- $flags |= constant( "ENT_HTML5" );
- }
+ $flags = ENT_QUOTES | ENT_HTML5;
$table = array_flip( get_html_translation_table( HTML_ENTITIES,
$flags, "UTF-8" ) );
return [ $table ];
}
diff --git a/engines/LuaCommon/UstringLibrary.php
b/engines/LuaCommon/UstringLibrary.php
index d651672..9c7b62c 100644
--- a/engines/LuaCommon/UstringLibrary.php
+++ b/engines/LuaCommon/UstringLibrary.php
@@ -16,13 +16,6 @@
private $stringLengthLimit = null;
/**
- * PHP 5.3's mb_check_encoding does not reject characters above
U+10FFFF.
- * When using that version, we'll need to check that manually.
- * @var boolean
- */
- private $manualCheckForU110000AndUp = false;
-
- /**
* PHP until 5.6.9 are buggy when the regex in preg_replace an
* preg_match_all matches the empty string.
* @var boolean
@@ -41,7 +34,6 @@
$this->stringLengthLimit = $wgMaxArticleSize * 1024;
}
- $this->manualCheckForU110000AndUp = mb_check_encoding(
"\xf4\x90\x80\x80", "UTF-8" );
$this->phpBug53823 = preg_replace( '//us', 'x', "\xc3\xa1" )
=== "x\xc3x\xa1x";
$this->patternRegexCache = new MapCacheLRU( 100 );
@@ -89,22 +81,12 @@
] );
}
- // Once we no longer support PHP < 5.4, calls to this method may be
replaced with
- // mb_check_encoding( $s, 'UTF-8' )
- private function checkEncoding( $s ) {
- $ok = mb_check_encoding( $s, 'UTF-8' );
- if ( $ok && $this->manualCheckForU110000AndUp ) {
- $ok = !preg_match( '/\xf4[\x90-\xbf]|[\xf5-\xff]/', $s
);
- }
- return $ok;
- }
-
private function checkString( $name, $s, $checkEncoding = true ) {
if ( $this->getLuaType( $s ) == 'number' ) {
$s = (string)$s;
} else {
$this->checkType( $name, 1, $s, 'string' );
- if ( $checkEncoding && !$this->checkEncoding( $s ) ) {
+ if ( $checkEncoding && !mb_check_encoding( $s, 'UTF-8'
) ) {
throw new Scribunto_LuaError( "bad argument #1
to '$name' (string is not UTF-8)" );
}
if ( strlen( $s ) > $this->stringLengthLimit ) {
@@ -117,7 +99,7 @@
public function ustringIsUtf8( $s ) {
$this->checkString( 'isutf8', $s, false );
- return [ $this->checkEncoding( $s ) ];
+ return [ mb_check_encoding( $s, 'UTF-8' ) ];
}
public function ustringByteoffset( $s, $l = 1, $i = 1 ) {
@@ -175,7 +157,7 @@
public function ustringToNFC( $s ) {
$this->checkString( 'toNFC', $s, false );
- if ( !$this->checkEncoding( $s ) ) {
+ if ( !mb_check_encoding( $s, 'UTF-8' )( $s ) ) {
return [ null ];
}
return [ UtfNormal::toNFC( $s ) ];
@@ -183,7 +165,7 @@
public function ustringToNFD( $s ) {
$this->checkString( 'toNFD', $s, false );
- if ( !$this->checkEncoding( $s ) ) {
+ if ( !mb_check_encoding( $s, 'UTF-8' )( $s ) ) {
return [ null ];
}
return [ UtfNormal::toNFD( $s ) ];
@@ -191,7 +173,7 @@
public function ustringToNFKC( $s ) {
$this->checkString( 'toNFKC', $s, false );
- if ( !$this->checkEncoding( $s ) ) {
+ if ( !mb_check_encoding( $s, 'UTF-8' )( $s ) ) {
return [ null ];
}
return [ UtfNormal::toNFKC( $s ) ];
@@ -199,7 +181,7 @@
public function ustringToNFKD( $s ) {
$this->checkString( 'toNFKD', $s, false );
- if ( !$this->checkEncoding( $s ) ) {
+ if ( !mb_check_encoding( $s, 'UTF-8' )( $s ) ) {
return [ null ];
}
return [ UtfNormal::toNFKD( $s ) ];
@@ -231,7 +213,7 @@
public function ustringLen( $s ) {
$this->checkString( 'len', $s, false );
- if ( !$this->checkEncoding( $s ) ) {
+ if ( !mb_check_encoding( $s, 'UTF-8' )( $s ) ) {
return [ null ];
}
return [ mb_strlen( $s, 'UTF-8' ) ];
@@ -273,7 +255,7 @@
$pattern = (string)$pattern;
}
$this->checkType( $name, 2, $pattern, 'string' );
- if ( !$this->checkEncoding( $pattern ) ) {
+ if ( !mb_check_encoding( $pattern, 'UTF-8' ) ) {
throw new Scribunto_LuaError( "bad argument #2 to
'$name' (string is not UTF-8)" );
}
if ( strlen( $pattern ) > $this->patternLengthLimit ) {
diff --git a/engines/LuaStandalone/LuaStandaloneEngine.php
b/engines/LuaStandalone/LuaStandaloneEngine.php
index f863472..1f808b5 100644
--- a/engines/LuaStandalone/LuaStandaloneEngine.php
+++ b/engines/LuaStandalone/LuaStandaloneEngine.php
@@ -247,9 +247,6 @@
if ( !empty( $err['message'] ) ) {
throw $this->engine->newException(
'scribunto-luastandalone-proc-error-msg',
[ 'args' => [ $err['message'] ] ] );
- } elseif ( wfIniGetBool( 'safe_mode' ) ) {
- /** @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/i18n/en.json b/i18n/en.json
index 57bf597..f98c807 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -42,7 +42,6 @@
"scribunto-luastandalone-proc-error": "Lua error: Cannot create
process.",
"scribunto-luastandalone-proc-error-msg": "Lua error: Cannot create
process: $2",
"scribunto-luastandalone-proc-error-proc-open": "Lua error: Cannot
create process: proc_open is not available. Check PHP's \"disable_functions\"
configuration directive.",
- "scribunto-luastandalone-proc-error-safe-mode": "Lua error: Cannot
create process. Note that PHP's deprecated \"safe_mode\" configuration
directive is enabled.",
"scribunto-luastandalone-decode-error": "Lua error: Internal error:
Unable to decode message.",
"scribunto-luastandalone-write-error": "Lua error: Internal error:
Error writing to pipe.",
"scribunto-luastandalone-read-error": "Lua error: Internal error: Error
reading from pipe.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 8af8be0..3815dd5 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -52,7 +52,6 @@
"scribunto-luastandalone-proc-error": "Exception message.",
"scribunto-luastandalone-proc-error-msg": "Exception message.
Parameters:\n* $1 - (Unused)\n* $2 - Warning/error text from PHP",
"scribunto-luastandalone-proc-error-proc-open": "Exception message
displayed when PHP's <tt>proc_open</tt> function is not available, which is
needed by the LuaStandalone engine. <tt>proc_open</tt> is a PHP function name
and <tt>disable_functions</tt> is the name of a PHP configuration. Both these
names aren't localized, thus shouldn't be translated. \n\nSee also:\n*
proc_open: http://www.php.net/manual/en/function.proc-open.php\n*
disable_functions: http://www.php.net/manual/en/ini.core.php",
- "scribunto-luastandalone-proc-error-safe-mode": "Exception message
displayed when PHP's \"safe_mode\" configuration directive is enabled.",
"scribunto-luastandalone-decode-error": "Exception message.",
"scribunto-luastandalone-write-error": "Exception message. A
[[wikipedia:unix pipe|unix pipe]] is similar to an electronic pipeline for
data.\n\nSee also:\n* {{msg-mw|Scribunto-luastandalone-read-error}}",
"scribunto-luastandalone-read-error": "Exception message.\nA
[[wikipedia:unix pipe|unix pipe]] is similar to an electronic pipeline for
data.\n\nSee also:\n* {{msg-mw|Scribunto-luastandalone-write-error}}",
--
To view, visit https://gerrit.wikimedia.org/r/372898
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I433ab9754606e2cbbaef534a1a5b70bad9b9387c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits