Page MenuHomePhabricator

ArticleSave Hook does not return messages Message if article is new
Closed, InvalidPublic

Description

Author: bacher

Description:
If you use the ArticleSave hook like follows:

extensions/test.php

<code>
<?php
$wgHooks['ArticleSave'][] = 'test'; // validates the truth of an inline query
function test($text,$user,$text,$summary,$flags, $null, $null2, &$realFlag){

return 'fubar';

}
</code>

with the LocalSettings.php enhanced with

include('extensions/test.php');

this hook normally prevents that a page will be saved. it will redirect you to the edit page of the article, and
show up the message 'fubar'. Just try with Sandbox, it should not let you save any page.

But this does not occur if you are triing to save a page that formerly did not exists. On pressing the save button the ArticleSave Hook is triggered in doEdit, but the message that was returned will not show up. Not even the edit form will show up, it will just view a blank not existing Wiki Page that you may edit again then.

I only tested it with MW 1.11


Version: 1.11.x
Severity: normal

Details

Reference
bz13414

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:04 PM
bzimport set Reference to bz13414.
bzimport added a subscriber: Unknown Object (MLST).

The return value of a hook must be one of the following:

true -- continue processing

false -- abort processing

Returning a non-empty, non-'0' string will evaluate to true in boolean context, meaning that processing should continue as normal. It will not display a message anywhere.

bacher wrote:

But then it does behave extremely different in the both cases, right? In one case it prints out a message, the string returned bu the function called through the hook, in the other case it does not return the message and redirect us to the page.

bacher wrote:

i made a proof of concept for the but. it's placed at
http://jemb.eu/mediawiki/index.php?title=Sandbox
edit the Sandbox and click save, you will see the message.

after that try:
http://jemb.eu/mediawiki/index.php?title=IAmANotExistingPage
edit it and click save: No message returned and not redirected to the edit form.

Ugh, there's some fundamental breakage in how this appears to be handled in the low-level hook code... it seems to be trying to integrate some UI reporting in, which is *WRONG WRONG WRONG*. I strongly recommend against attempting to use that, as it looks like some BADLY obsolete code.

Anyway, you're hooking into low-level page save code which is not guaranteed to be in any useful user interface area in the first place.

You probably want to be hooking into 'EditPage::attemptSave' or 'EditFilter' hooks if you want to be able to interact with a user and abort editing operations at a user-interface level.

bacher wrote:

Cool, i have tested the EditFilter and it worked just like we need it. Many thanks for the fast reply brion!