[Mediawiki-l] ArticleSave hook

Muzaffer Ozakca mozakca at indiana.edu
Wed Mar 2 21:55:38 UTC 2005


Hi again,

I think now I have an idea about what you're asking. I never used hooks 
before. From what I can tell by looking at hooks.doc, you should (by 
convention) probably put your hook function in an extension file under 
the extension directory. Then you should add a line to LocalSettings.php

require_once('extensions/yourextension.php');

Although I didn't have time to read hooks.doc in full, it's one of the 
most extensive documentation I've ever seen for Mediawiki :)

Read on and try different ways, I suggest.

ngungo wrote:
> Hi Muzaffer,
> 
> Thanks for the advice. I really sound desperate and pitty huh!!!
> I don't how to reduce my problem simpler than I have stated:
> 
> 
>>Problem: I would like to insert into the ArticleSave hook a simple php
>>function (that does nothing but returns true) as following:
>> 
>>  function myFunction() {
>>    return true;
>>  }
>> 
> 
> 
> I also included the background:
> 
> 
>>Background:
>>I need to collect and compile some statistics of all posts and display
>>them to a special page. The most natural way is when the Save Page
>>button is hit, a php function (myFunction) will do the work and after
>>that resume back to saving of the current page as normal. I have
> 
> posted
> 
>>this problem here twice before, Erik Moeller has helped me to analyze
>>the problem and guided me to read /docs/hooks.doc. I understand (I
> 
> think
> 
>>so.) the concept, but have not been able to implemented. The above
>>problem is the most reduced version of what I would like to do. I need
>>to be over that hump before I can do anything else. Please help by
>>giving me a step by step instructions. Please!!!
>> 
> 
> 
> I am new here, this is my first time. I've been back and for with Erik
> and proposed what I should do (I also implemented that unsuccessfully as
> following), but haven heard from him for two days. I guess he is busy. I
> forgot to include what we have discussed:
> 
> Hi Erik,
> 
> doc/hooks.doc is really helpful. It provides me the theory of the hooks
> mechanism. For implementaion I need to learn more. Here's my
> understanding about the specific ArticleSave hook.
> 
> 1. I saw ArticleSave has been hooked twice in the function editForm
> like:
> 
> if (wfRunHooks('ArticleSave', $this->mArticle, $wgUser, $this->textbox1,
> $this->summary, $this->minoredit, $this->watchthis, NULL)) {
> 	...
> 	...
> }
> 
> 
> 2. I have to resister the hook in DefaultSettings.php with like this:
> 
> /**
>  * Global list of hooks.
>  * Add a hook by doing:
>  *     $wgHooks['event_name'][] = $function;
>  * or:
>  *     $wgHooks['event_name'][] = array($function, $data);
>  * or:
>  *     $wgHooks['event_name'][] = array($object, 'method');
>  */
> 	
> $wgHooks = array();
> $wgHooks['ArticleSave'][] = 'myFunction';   // new
> 
> 
> 3. The function will be:
> 
> function myFunction() {
>    // Call function Article::updateArticle
>    //  (to post this statistics on a Special:TextStatistics page).
>    return true;
> }
> 
> 
> 4. Where do I write the above 'myFunction'? On what class? Article (or
> editPage)?
> 
> 
> 
> -----Original Message-----
> From: mediawiki-l-bounces at Wikimedia.org
> [mailto:mediawiki-l-bounces at Wikimedia.org] On Behalf Of Muzaffer Ozakca
> Sent: Wednesday, March 02, 2005 12:54 PM
> To: MediaWiki announcements and site admin list
> Subject: Re: [Mediawiki-l] ArticleSave hook
> 
> Hello,
> 
> I understand your frustration. But, as far as I can tell, and I've been 
> members of this kind of communities, that's not the way to get answers. 
> First of all, you have to describe your question really clearly. Unless 
> you do so not many people will say that they didn't understand what 
> you're asking for. You'll get nothing instead.
> 
> And second, you have to show that you spent some effort trying to solve 
> the problem yourself. Without this nobody will be willing to write code 
> for you while all you do is ask and wait. You should try to understand 
> how the code works, then ask specific smaller questions.
> 
> And third, I've never seen that begging for help works.
> 
> And last, these are not the definitive rules, these are some of my 
> observations and I don't always follow them either.
> 
> 
> 
> _______________________________________________
> MediaWiki-l mailing list
> MediaWiki-l at Wikimedia.org
> http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
> 
> 
> 



More information about the MediaWiki-l mailing list