Avoid create_function. Making explicit functions.
authorPlatonides <platonides@users.mediawiki.org>
Wed, 22 Dec 2010 00:02:49 +0000 (00:02 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Wed, 22 Dec 2010 00:02:49 +0000 (00:02 +0000)
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
maintenance/upgrade1_5.php

index ce21e77..fd9152e 100644 (file)
@@ -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 );
        }
 
index 45fbd21..cc09b06 100644 (file)
@@ -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,
                        '',