Jim Wilson <wilson.jim.r@...> writes:
Well, one thing I notice is that in both methods, if the preg_match()
succeeds, then no return value is returned from the functions. It may
not make a difference, but you probably want to return true or false
depending on whether you want to give other hooking methods chance to
run. I believe newer versions of MediaWiki will choke when no return
value is provided.
That aside, you may need to do a $wgOut->disable() prior to your
header() calls, not sure if this makes a difference.
Also, not all browsers will report a referrer at all. You can turn
this off in many browsers, or if there is any kind of proxy being
used, you may get no referrer information.
Since you're doing the forwarding on both ends, I think the best
option is to store the "return to" information in some place and make
sure it gets carried through until ArticleSaveComplete. This could
either be a URL parameter (like "&returnto=Came_From"), or a Cookie as
you suggested, or you could store it in the user's Session data.
Personally, I like the URL parameter best because it prevents
lingering data in the case someone gets to the edit page and closes
their browser. However, this method is somewhat more difficult since
you may have to hook more Article and EditPage places to ensure that
the data sails through form POSTs.
Could you please tell me what the $wgOut->disable() statement is good for?
I am also still thinking about, why I don't get any return if I use this
function in combination with the ArticleSaveComplete-Hook?
Maybe I use the wrong vareables?
Because in combination with the ArticleSave-Hook it works!?!
function ArticleReturn(&$text) {
global $wgOut, $wgUser, $wgRequest, $wgTitle, $wgParser;
// get the title for the current article
$articleText = $text->getContent();
/* $articleText = $text->mContent->getText(); */
$referer = $_SERVER['HTTP_REFERER'];
if (preg_match('/<section begin=/', $articleText)) {
header("Location: $referer");
} else {
return true;
}
}