MediaWiki and reCAPTCHA fixes for PHP 5.3

A couple days ago I upgraded our production systems to PHP 5.3, which went well… except for two pieces of software: MediaWiki (version 1.14) and reCAPTCHA for MediaWiki (version 1.8).

PHP 5.3 introduces the ability to automatically detect when a reference is used on a calling function within a class/namespace. Prior to 5.3, you had to specify this in the function argument list using the ampersand (“&”) directive, e.g.

function whatever(&$reference, $whatever) { ... }

This is no longer needed — and now throws warnings in PHP 5.3. The warnings:

  • MediaWiki — Warning: Parameter 1 to Language::getMagic() expected to be a reference, value given in .../includes/StubObject.php on line 58
  • reCAPTCHA — Warning: Parameter 1 to ReCaptcha::confirmEdit() expected to be a reference, value given in .../includes/Hooks.php on line 117

Fixing these problems is as simple as a one-line, one-byte change: you literally remove the ampersand (“&”) in the function argument declarations. The below outlines how to fix this, and is shown in diff format (e.g. the original line starts with a hyphen, the replacement starts with a plus).

MediaWiki fix — file languages/Language.php, approximately line 1900:

-	function getMagic( &$mw ) {
+	function getMagic( $mw ) {

reCAPTCHA fix — file recaptcha/ReCaptcha.php, approximately line 100:

-	function confirmEdit( &$editPage, $newtext, $section ) {
+	function confirmEdit( $editPage, $newtext, $section ) {

The trunk/devel version of MediaWiki (which will be 1.16) has already addressed this. reCAPTCHA, however, doesn’t — and their forum has no mention of the issue either. Hopefully folks searching the web will find my above explanation/fix sufficient.