Question

I'm hacking an existing MediaWiki extension, ProcessCite, that adds a custom hook to the Cite extension. Since migrating to PHP 5.4 and MW 1.22 (from PHP 5.3 and MW 1.19.2), the extension does not appear to work correctly. The problem is with the custom hook not returning the data it should do.

Here are the relevant parts of the code:

ProcessCite.php

# Declare the hook:
$wgHooks['CiteBeforeStackEntry'][] = 'wfProcessCite';

# the function itself
function wfProcessCite($str, $argv){

# process $argv and $str to create a new version of $str
# $argv remains unchanged, $str is set to new value
  ...
  $str = "new string";

  return true;
}

in Cite_body.php

function stack( $str, $key = null, $group, $follow, $call ) {
  # add the call to the CiteBeforeStackEntry hook
  wfRunHooks( 'CiteBeforeStackEntry', array( &$str, &$call ) );

I've added debugging statements to the beginning and end of wfProcessCite, which show that $str is being altered; however, debug statements before and after wfRunHooksshow no change to $str.

Can anyone help?

Était-ce utile?

La solution

Got the answer from Andru Vallance on the Mediawiki mailing list:

Prepending the function argument with an ampersand character causes it to be passed it in by reference. That means you are directly manipulating the original variable inside your function, rather than a copy.

function wfProcessCite( &$str, $argv ){
    $str = ‘new value’; 
    return true;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top