API edit: allow ConfirmEdit to use the merged parse
authorTim Starling <tstarling@wikimedia.org>
Fri, 5 Dec 2014 04:25:18 +0000 (15:25 +1100)
committerTim Starling <tstarling@wikimedia.org>
Fri, 5 Dec 2014 06:10:20 +0000 (17:10 +1100)
commit09a5febb7b024c0b6585141bb05cba13a642f3eb
tree200143ced8988f80ea2d63dda0ff66c7fb8d73a7
parentc393f874706ea4683762b37305401432e0473940
API edit: allow ConfirmEdit to use the merged parse

ConfirmEdit was tripling the amount of time it took to save a typical
page via the API, since it was assuming that the APIEditBeforeSave hook
was giving unmerged wikitext, requiring a full parse of the content
before and after the edit in order to check the addurl trigger.
Apparently nobody bothered to update it after Ia59fb6bb.

APIEditBeforeSave is unusable anyway, because it is given the serialized
content, without any information about the content model. It really
needs the Content object in order to do it properly. So instead, adapt
EditFilterMergedContent for the purpose. Incidentally, that avoids the
inelegant defined('MW_API') check in ConfirmEdit's
EditFilterMergedContent handler, since both API and normal edits are
handled by EditFilterMergedContent in the same way.

Unfortunately the interpretation of the 'value' member in the Status
object passed to EditFilterMergedContent is not extensible, being an
integer instead of an associative array. So we add a custom member in
order to get the result array back down the stack.

Another obstacle to this design was the lack of an EditPage object
passed to EditFilterMergedContent. ConfirmEdit was previously directly
calling EditPage::showEditForm() with a $formCallback which outputs the
necessary HTML. Instead, I hacked up runPostMergeFilters() a bit, to
allow the hook to request that the edit page be shown again even if
hookError is not set. Then a new EditPage::showEditForm:fields hook does
the necessary HTML output, instead of $formCallback.

Marked $formCallback as deprecated, since I think it is now unused.

Change-Id: I4b4270dd868a643512d4717927858b6ef0556d8a
docs/hooks.txt
includes/Defines.php
includes/EditPage.php
includes/api/ApiEditPage.php