[Mediawiki-l] ArticleSave hook

Brion Vibber brion at pobox.com
Wed Mar 2 21:50:03 UTC 2005


ngungo wrote:
[snip]
> 2. I have to resister the hook in DefaultSettings.php with like this:

You should never edit DefaultSettings.php unless you're hacking up the
main software itself; avoiding that is why we have extension hooks in
the first place. Put customizations in LocalSettings.php.

> function myFunction() {
>    // Call function Article::updateArticle
>    //  (to post this statistics on a Special:TextStatistics page).
>    return true;
> }

This function won't actually do anything, obviously, as it consists only
of a comment and a true return. It won't even produce any evidence that
it's being run unless you're stepping line by line in a debugger; how
are you checking whether or not it's running successfully? What's the
problem that you're posting about?

> 4. Where do I write the above 'myFunction'? On what class? Article (or
> editPage)?

In your own file, which you can include from LocalSettings.php. The
purpose of hooks is to allow adding in some functions *without* changing
the core code.

I tried putting this into my test REL1_4 installation's LocalSettings.php:

$wgHooks['ArticleSave'][] = 'myFunction';   // new
function myFunction() {
	die("Testing!");
}

When I try to save, the script dies and prints "Testing!" as expected,
showing clearly that the hook is run.

-- brion vibber (brion @ pobox.com)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : http://lists.wikimedia.org/pipermail/mediawiki-l/attachments/20050302/343e145c/attachment.pgp 


More information about the MediaWiki-l mailing list