[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mediawiki-l
Subject:    Re: [MediaWiki-l] MediaWiki hooks and event handlers (was: MediaWiki hooks and params)
From:       Andru Vallance <andru () tinymighty ! com>
Date:       2014-03-18 8:42:50
Message-ID: 500FCC8A-E0B7-46FB-ACEB-B2632022C2B0 () tinymighty ! com
[Download RAW message or body]

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, $key, $call ){
> 	$str = ‘new value'; 
> 	return true;

If that doesn't work, there's a problem elsewhere.

Yours
Andru


On 17 Mar, 2014, at 22:56, Amelia Ireland <amelia.ireland@gmod.org> wrote:

> Arcane 21 <arcane <at> live.com> writes:
> 
>> 
>> I recommend using the MW 1.22.4 tarball to base this on. The MW 1.22.3
> extensions are the wrong branch and
>> produce errors, assuming you're using the Cite extension that was bundled
> with the 1.22.3 tarball..
> 
> I've upgraded my MW installation and the extensions, but the problem
> remains. I would guess it's to do with passing references vs values, or
> there is some MediaWiki-specific thing that I am not aware of.
> 
> 
> Perhaps someone can help me sort out the syntax for writing an event
> handler that modifies an existing value.
> 
> Here's where the hook is called:
> 
> wfRunHooks( 'CiteBeforeStackEntry', array( &$str, &$key, &$call ) );
> 
> 
> Here's the hook:
> 
> $wgHooks['CiteBeforeStackEntry'][] = 'wfProcessCite';
> 
> 
> Here's the function:
> 
> function wfProcessCite( $str, $key, $call ){
> 
> ...
> 
> I want to change the value of $str, but leave $key and $call unchanged.
> 
> Can someone indicate the correct syntax?
> 
> Thank you!
> Amelia.
> 
> 
> 
>>> From: amelia.ireland <at> gmod.org
>>> Date: Thu, 13 Mar 2014 14:18:54 -0700
>>> To: mediawiki-l <at> lists.wikimedia.org
>>> Subject: [MediaWiki-l] MediaWiki hooks and parameters
>>> 
>>> Hello,
>>> 
>>> I'm having a little trouble getting a custom hook to perform the
> actions I
>>> want
>>> it to after upgrading from PHP 5.3 / MW 1.19.2 to PHP 5.4 / MW 1.22.3.
>>> 
>>> I am hacking an existing extension, ProcessCite, that integrates into
> the
>>> Cite
>>> extension by adding a custom hook to one of Cite's functions:
>>> 
>>> # from Cite_body.php
>>> function stack( $str, $key = null, $group, $follow, $call ) {
>>>  # add the call to the CiteBeforeStackEntry hook
>>>  wfRunHooks( 'CiteBeforeStackEntry', array( &$str, &$call ) );
>>> 
>>> ProcessCite runs code that creates a value for $str based on the
> contents of
>>> $call. Here are the relevant parts of ProcessCite:
>>> 
>>> # Declare the hook:
>>> $wgHooks['CiteBeforeStackEntry'][] = 'wfProcessCite';
>>> 
>>> 
>>> # the function itself
>>> function wfProcessCite($str, $call){
>>> 
>>> # process $call and $str to create a new version of $str
>>> # $call remains unchanged, $str is set to new value
>>> 
>>>  $str = "new string";
>>> 
>>>  return true;
>>> }
>>> 
>>> Debug statements reveal that wfProcessCite is creating the correct
> value for
>>> $str, but the value is not altered when wfProcessCite finishes. I am not
>>> sure
>>> if I am calling the hook in the wrong way, given that I want to alter
> the
>>> value of $str.
>>> 
>>> The MW manual page on hooks (http://www.mediawiki.org/wiki/Manual:Hooks)
> is
>>> somewhat confusing -- what is the difference between passing $someData
> to a
>>> function versus passing a set of parameters?!
>>> 
>>> Any help would be appreciated!
>>> 
>>> Thank you,
>>> Amelia.
>>> 
>>> --
>>> Amelia Ireland
>>> GMOD Community Support
>>> Generic Model Organism Database project
>>> http://gmod.org ||  <at> gmodproject
>>> _______________________________________________
>>> MediaWiki-l mailing list
>>> MediaWiki-l <at> lists.wikimedia.org
>>> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
>> 
>> _______________________________________________
>> MediaWiki-l mailing list
>> MediaWiki-l <at> lists.wikimedia.org
>> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
>> 
> 
> 
> 
> -- 
> Amelia Ireland
> GMOD Community Support
> Generic Model Organism Database project
> http://gmod.org || @gmodproject
> _______________________________________________
> MediaWiki-l mailing list
> MediaWiki-l@lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l

_______________________________________________
MediaWiki-l mailing list
MediaWiki-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic