From 29ba65c6ec1db267fac2230bc71ee1dfabe421a4 Mon Sep 17 00:00:00 2001 From: Platonides Date: Wed, 22 Dec 2010 00:02:49 +0000 Subject: [PATCH] Avoid create_function. Making explicit functions. Not using self:: in the callbacks for PHP 5.2 compatibility. $sourceFields = array_keys( array_filter( $fields, array( $this, 'notUpgradeNull' ) ) ); works flawlessly too, but might begin throwing warnings in the future. --- maintenance/fuzz-tester.php | 17 +++++++++-------- maintenance/upgrade1_5.php | 9 +++++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/maintenance/fuzz-tester.php b/maintenance/fuzz-tester.php index ce21e771f9..fd9152e701 100644 --- a/maintenance/fuzz-tester.php +++ b/maintenance/fuzz-tester.php @@ -816,7 +816,14 @@ class wikiFuzz { } } - + /** + * Returns the matched character slash-escaped as in a C string + * Helper for makeTitleSafe callback + */ + static private function stringEscape($matches) { + return sprintf( "\\x%02x", ord( $matches[1] ) ); + } + /** ** Strips out the stuff that Mediawiki balks at in a page's title. ** Implementation copied/pasted from cleanupTable.inc & cleanupImages.php @@ -824,13 +831,7 @@ class wikiFuzz { static public function makeTitleSafe( $str ) { $legalTitleChars = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF"; return preg_replace_callback( - "/([^$legalTitleChars])/", - create_function( - // single quotes are essential here, - // or alternative escape all $ as \$ - '$matches', - 'return sprintf( "\\x%02x", ord( $matches[1] ) );' - ), + "/([^$legalTitleChars])/", 'wikiFuzz::stringEscape', $str ); } diff --git a/maintenance/upgrade1_5.php b/maintenance/upgrade1_5.php index 45fbd21cc8..cc09b067e0 100644 --- a/maintenance/upgrade1_5.php +++ b/maintenance/upgrade1_5.php @@ -320,6 +320,12 @@ class FiveUpgrade extends Maintenance { $this->dbw->insert( $this->chunkTable, $chunk, $this->chunkFunction, $this->chunkOptions ); } + /** + * Helper function for copyTable array_filter + */ + static private function notUpgradeNull($x) { + return $x !== MW_UPGRADE_NULL; + } /** * Copy and transcode a table to table_temp. @@ -349,8 +355,7 @@ class FiveUpgrade extends Maintenance { $this->setChunkScale( 100, $numRecords, $name_temp, __METHOD__ ); // Pull all records from the second, streaming database connection. - $sourceFields = array_keys( array_filter( $fields, - create_function( '$x', 'return $x !== MW_UPGRADE_NULL;' ) ) ); + $sourceFields = array_keys( array_filter( $fields, 'FiveUpgrade::notUpgradeNull' ) ); $result = $this->dbr->select( $name, $sourceFields, '', -- 2.20.1