Remove some PHP 5.3 compat code

Change-Id: I433ab9754606e2cbbaef534a1a5b70bad9b9387c
This commit is contained in:
Kunal Mehta 2017-08-21 14:16:32 -07:00
parent b8ff734aa4
commit f49ad9081c
6 changed files with 14 additions and 44 deletions

View file

@ -245,13 +245,9 @@ abstract class Scribunto_LuaEngine extends ScribuntoEngineBase {
];
$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;
} );
}

View file

@ -62,12 +62,9 @@ class Scribunto_LuaTextLibrary extends Scribunto_LuaLibraryBase {
}
function getEntityTable() {
$flags = ENT_QUOTES;
// PHP 5.3 compat
if ( defined( "ENT_HTML5" ) ) {
$flags |= constant( "ENT_HTML5" );
}
$table = array_flip( get_html_translation_table( HTML_ENTITIES, $flags, "UTF-8" ) );
$table = array_flip(
get_html_translation_table( HTML_ENTITIES, ENT_QUOTES | ENT_HTML5, "UTF-8" )
);
return [ $table ];
}

View file

@ -15,13 +15,6 @@ class Scribunto_LuaUstringLibrary extends Scribunto_LuaLibraryBase {
*/
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.
@ -41,7 +34,6 @@ class Scribunto_LuaUstringLibrary extends Scribunto_LuaLibraryBase {
$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 @@ class Scribunto_LuaUstringLibrary extends Scribunto_LuaLibraryBase {
] );
}
// 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 @@ class Scribunto_LuaUstringLibrary extends Scribunto_LuaLibraryBase {
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 @@ class Scribunto_LuaUstringLibrary extends Scribunto_LuaLibraryBase {
public function ustringToNFC( $s ) {
$this->checkString( 'toNFC', $s, false );
if ( !$this->checkEncoding( $s ) ) {
if ( !mb_check_encoding( $s, 'UTF-8' ) ) {
return [ null ];
}
return [ UtfNormal::toNFC( $s ) ];
@ -183,7 +165,7 @@ class Scribunto_LuaUstringLibrary extends Scribunto_LuaLibraryBase {
public function ustringToNFD( $s ) {
$this->checkString( 'toNFD', $s, false );
if ( !$this->checkEncoding( $s ) ) {
if ( !mb_check_encoding( $s, 'UTF-8' ) ) {
return [ null ];
}
return [ UtfNormal::toNFD( $s ) ];
@ -191,7 +173,7 @@ class Scribunto_LuaUstringLibrary extends Scribunto_LuaLibraryBase {
public function ustringToNFKC( $s ) {
$this->checkString( 'toNFKC', $s, false );
if ( !$this->checkEncoding( $s ) ) {
if ( !mb_check_encoding( $s, 'UTF-8' ) ) {
return [ null ];
}
return [ UtfNormal::toNFKC( $s ) ];
@ -199,7 +181,7 @@ class Scribunto_LuaUstringLibrary extends Scribunto_LuaLibraryBase {
public function ustringToNFKD( $s ) {
$this->checkString( 'toNFKD', $s, false );
if ( !$this->checkEncoding( $s ) ) {
if ( !mb_check_encoding( $s, 'UTF-8' ) ) {
return [ null ];
}
return [ UtfNormal::toNFKD( $s ) ];
@ -231,7 +213,7 @@ class Scribunto_LuaUstringLibrary extends Scribunto_LuaLibraryBase {
public function ustringLen( $s ) {
$this->checkString( 'len', $s, false );
if ( !$this->checkEncoding( $s ) ) {
if ( !mb_check_encoding( $s, 'UTF-8' ) ) {
return [ null ];
}
return [ mb_strlen( $s, 'UTF-8' ) ];
@ -273,7 +255,7 @@ class Scribunto_LuaUstringLibrary extends Scribunto_LuaLibraryBase {
$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 ) {

View file

@ -247,9 +247,6 @@ class Scribunto_LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
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' );
}

View file

@ -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.",

View file

@ -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}}",