How to trigger a signal / hook on edit of a specif

2019-09-04 15:23发布

问题:

Is it possible to trigger some kind of signal or configure a hook (e.g. execution of defined / hard coded shell script) after editing one specific page of a MediaWiki?

The scenario is as follows.
Up to now a RSS feed is generated from the content of one specific MediaWiki page (call it wiki/index.php?title=News) each time the RSS feed is requested. As this page gets edited only once in a couple of days, having a Perl::CGI oder PHP script as the source of the RSS feed (e.g. URL for feed readers: example.com/rss-feed.php) should be better - in terms of server load. This script generates a static RSS feed (e.g. at example.com/rss.xml) only when the wiki page got edited.

Remark:
The wiki page I'm talking about is protected and only trusted users can edit it. I can not think about a security issue within the proposed workflow above. I'm happy getting otherwise convinced.

回答1:

Sure, entirely possible.

The ArticleSaveComplete hook's $article parameter contains the title and namespace of the article that's just been saved (specifically, you want to access the properties of $article->mTitle).

Simply define a function with an if statement that will just return true if the title (and namespace!) don't match the given data. If they do match, it will generate the static file you need.

The MediaWiki Hooks manual page has some examples and further info on how hooks work and how to go about writing a new function that will work with a specific hook.

That said, I would really advise you to consider dropping this idea, unless you're actually seeing adverse performance effects on your machine. Under a normal configuration, MediaWiki should use parser cache to take care of the most load-intensive operation for queries like this one.