Hi @all...
the extension I actually create, tries to call a function by using the ArticleSaveComplete-Hook:
function ArticleReturn(&$text) { global $wgOut, $wgUser, $wgRequest, $wgTitle, $wgParser; $articleText = $text->getContent(); $referer = $_SERVER['HTTP_REFERER']; if (preg_match('/<section begin=/', $articleText)) { header("Location: $referer"); } else { return true; } }
Unfortunately it doesn't work. However, if I use the ArticleSave-Hook in the same case it does. But the changes done, aren't saved of cause.
Anybody who can tell me the problem?
greets, demagggus
ArticleSaveComplete executes after someone has saved an edit to a page - either when the page is first created, or on subsequent edits. So therefor, $_SERVER['HTTP_REFERER'] should always be the Edit version of the page they just saved - or something to that effect.
It's not clear from your code fragment what it is you hope to achieve. If you can provide more info on what it is you want the code to do, I may be able to help more.
-- Jim R. Wilson (jimbojw)
On 10/18/07, demagggus magggus@gmx.de wrote:
Hi @all...
the extension I actually create, tries to call a function by using the ArticleSaveComplete-Hook:
function ArticleReturn(&$text) { global $wgOut, $wgUser, $wgRequest, $wgTitle, $wgParser;
$articleText = $text->getContent(); $referer = $_SERVER['HTTP_REFERER']; if (preg_match('/<section begin=/', $articleText)) { header("Location: $referer"); } else { return true; }}
Unfortunately it doesn't work. However, if I use the ArticleSave-Hook in the same case it does. But the changes done, aren't saved of cause.
Anybody who can tell me the problem?
greets, demagggus
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
ArticleSaveComplete executes after someone has saved an edit to a page
- either when the page is first created, or on subsequent edits. So
therefor, $_SERVER['HTTP_REFERER'] should always be the Edit version of the page they just saved - or something to that effect.
It's not clear from your code fragment what it is you hope to achieve. If you can provide more info on what it is you want the code to do, I may be able to help more.
Hi Jim, hi @all,
here the total code.
I used the LabeledSectionTransclusion to create some kind of variable articles. To enable the user to edit the origin article, the transcluded contents are purchased from I use the function 'EditForwarding'.
When activating the edit-button, the content is checked for the LST-syntax. So far this syntax exists in this content, the origin article-title is filtered out of the syntax. Afterwards the user is forwarded to this article in the edit-mode.
What I know try to do is to 'reforward' the user to the site he came from, after the article is saved. Therefore I want to check, if the content of the saved article contains the string "<section begin=".
It's quite plain to me, that it will not work by using the 'HTTP_REFERER'. I saw this while using the same syntax in combination with the 'ArticleSave-Hook'. But maybe it would be feasible by using cookies.
But I don't understand, why it doesn't work anyway if I change the hook to 'ArticleSaveComplete'. Seems I don't get the right vareables to get the articles content!?!
greets, demagggus
<?php
# get out if not part of mediawiki .. if( !defined( 'MEDIAWIKI' ) ) { echo( "This file is part of an extension to the MediaWiki software and cannot be used standalone.\n" ); die( true ); }
$wgExtensionCredits['other'][] = array( 'name' => 'EditSubstitutionRestore', 'author' => 'Marcus Schäfer', 'url' => '', 'description' => '' );
$wgHooks['AlternateEdit'][] = 'EditForwarding'; $wgHooks['ArticleSaveComplete'][] = 'ArticleReturn';
function EditForwarding(&$editpage) { global $wgOut, $wgUser, $wgRequest, $wgTitle, $wgParser; // get the title for the current article $articleTitle = $editpage->mTitle->getText();
// get the content for the current article $articleText = $editpage->mArticle->getContent();
// check if the current article contains the LST-syntax if (preg_match('/{{#lst:|#lsth:/i', $articleText)) {
// extract the origin article name out of the SelectedTransclusion-Syntax $articleTitle_origin = preg_replace('/{{#lst:||lux}}|\ger}}/', '', $articleText);
// forward to the origin article; enter in edit-mode (using php-header) header("Location: http://localhost/mediawiki/index.php?title=$articleTitle_origin&action=e...");
} else { return true; } }
function ArticleReturn(&$text) { global $wgOut, $wgUser, $wgRequest, $wgTitle, $wgParser;
$articleText = $text->getContent();
$referer = $_SERVER['HTTP_REFERER'];
if (preg_match('/<section begin=/', $articleText)) { header("Location: $referer"); } else { return true; } } ?>
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.
-- Jim
On 10/18/07, demagggus magggus@gmx.de wrote:
ArticleSaveComplete executes after someone has saved an edit to a page
- either when the page is first created, or on subsequent edits. So
therefor, $_SERVER['HTTP_REFERER'] should always be the Edit version of the page they just saved - or something to that effect.
It's not clear from your code fragment what it is you hope to achieve. If you can provide more info on what it is you want the code to do, I may be able to help more.
Hi Jim, hi @all,
here the total code.
I used the LabeledSectionTransclusion to create some kind of variable articles. To enable the user to edit the origin article, the transcluded contents are purchased from I use the function 'EditForwarding'.
When activating the edit-button, the content is checked for the LST-syntax. So far this syntax exists in this content, the origin article-title is filtered out of the syntax. Afterwards the user is forwarded to this article in the edit-mode.
What I know try to do is to 'reforward' the user to the site he came from, after the article is saved. Therefore I want to check, if the content of the saved article contains the string "<section begin=".
It's quite plain to me, that it will not work by using the 'HTTP_REFERER'. I saw this while using the same syntax in combination with the 'ArticleSave-Hook'. But maybe it would be feasible by using cookies.
But I don't understand, why it doesn't work anyway if I change the hook to 'ArticleSaveComplete'. Seems I don't get the right vareables to get the articles content!?!
greets, demagggus
<?php # get out if not part of mediawiki .. if( !defined( 'MEDIAWIKI' ) ) { echo( "This file is part of an extension to the MediaWiki software and cannot be used standalone.\n" ); die( true ); } $wgExtensionCredits['other'][] = array( 'name' => 'EditSubstitutionRestore', 'author' => 'Marcus Schäfer', 'url' => '', 'description' => '' ); $wgHooks['AlternateEdit'][] = 'EditForwarding'; $wgHooks['ArticleSaveComplete'][] = 'ArticleReturn'; function EditForwarding(&$editpage) { global $wgOut, $wgUser, $wgRequest, $wgTitle, $wgParser; // get the title for the current article $articleTitle = $editpage->mTitle->getText(); // get the content for the current article $articleText = $editpage->mArticle->getContent(); // check if the current article contains the LST-syntax if (preg_match('/{{#lst:|#lsth:/i', $articleText)) { // extract the origin article name out of the SelectedTransclusion-Syntax $articleTitle_origin = preg_replace('/{{#lst:|\|lux}}|\ger}}/', '', $articleText); // forward to the origin article; enter in edit-mode (using php-header) header("Location: http://localhost/mediawiki/index.php?title=$articleTitle_origin&action=edit"); } else { return true; } } function ArticleReturn(&$text) { global $wgOut, $wgUser, $wgRequest, $wgTitle, $wgParser; $articleText = $text->getContent(); $referer = $_SERVER['HTTP_REFERER']; if (preg_match('/<section begin=/', $articleText)) { header("Location: $referer"); } else { return true; } } ?>
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
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; } }
Could you please tell me what the $wgOut->disable() statement is good for?
It tells the output engine to display nothing. This is usually what you want when you're using header() to redirect to another location.
-- Jim
On 10/20/07, demagggus magggus@gmx.de wrote:
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; }}
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
wikitech-l@lists.wikimedia.org