r78759 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78758‎ | r78759 | r78760 >
Date:00:02, 22 December 2010
Author:platonides
Status:ok (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/maintenance/fuzz-tester.php (modified) (history)
  • /trunk/phase3/maintenance/upgrade1_5.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/fuzz-tester.php
@@ -816,21 +816,22 @@
817817 }
818818 }
819819
820 -
821820 /**
 821+ * Returns the matched character slash-escaped as in a C string
 822+ * Helper for makeTitleSafe callback
 823+ */
 824+ static private function stringEscape($matches) {
 825+ return sprintf( "\\x%02x", ord( $matches[1] ) );
 826+ }
 827+
 828+ /**
822829 ** Strips out the stuff that Mediawiki balks at in a page's title.
823830 ** Implementation copied/pasted from cleanupTable.inc & cleanupImages.php
824831 */
825832 static public function makeTitleSafe( $str ) {
826833 $legalTitleChars = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF";
827834 return preg_replace_callback(
828 - "/([^$legalTitleChars])/",
829 - create_function(
830 - // single quotes are essential here,
831 - // or alternative escape all $ as \$
832 - '$matches',
833 - 'return sprintf( "\\x%02x", ord( $matches[1] ) );'
834 - ),
 835+ "/([^$legalTitleChars])/", 'wikiFuzz::stringEscape',
835836 $str );
836837 }
837838
Index: trunk/phase3/maintenance/upgrade1_5.php
@@ -320,6 +320,12 @@
321321 $this->dbw->insert( $this->chunkTable, $chunk, $this->chunkFunction, $this->chunkOptions );
322322 }
323323
 324+ /**
 325+ * Helper function for copyTable array_filter
 326+ */
 327+ static private function notUpgradeNull($x) {
 328+ return $x !== MW_UPGRADE_NULL;
 329+ }
324330
325331 /**
326332 * Copy and transcode a table to table_temp.
@@ -349,8 +355,7 @@
350356 $this->setChunkScale( 100, $numRecords, $name_temp, __METHOD__ );
351357
352358 // Pull all records from the second, streaming database connection.
353 - $sourceFields = array_keys( array_filter( $fields,
354 - create_function( '$x', 'return $x !== MW_UPGRADE_NULL;' ) ) );
 359+ $sourceFields = array_keys( array_filter( $fields, 'FiveUpgrade::notUpgradeNull' ) );
355360 $result = $this->dbr->select( $name,
356361 $sourceFields,
357362 '',

Follow-up revisions

RevisionCommit summaryAuthorDate
r78760Four more spaces, per r78759 CRplatonides00:06, 22 December 2010

Comments

#Comment by Reedy (talk | contribs)   00:05, 22 December 2010

You should really be doing

+	static private function notUpgradeNull( $x ) {

rather than

+	static private function notUpgradeNull($x) {
)

Status & tagging log