Page MenuHomePhabricator

RevisionsBeforeDiff hook
Closed, DeclinedPublic

Description

Author: bebraw

Description:
initial patch

As far as I know there is no way to modify revision texts passed to the difference engine. This hook, attached to the entry, provides a simple solution to the problem. It implements RevisionsBeforeDiff hook that can be used as follows:

...
$wgHooks['RevisionsBeforeDiff'][] = 'combineNewRevisionWithRequest';
function combineNewRevisionWithRequest( &$oldRevText, &$newRevText ) {
if( pageIsEditable() ) {

		global $wgTitle;
		$editPage = getEditPage($wgTitle);
		$newRevText = renderProperties($editPage) . $newRevText;
		
		removeCommentLines($oldRevText);
		removeCommentLines($newRevText);

}

return true;
}
...

Even though the code is out of context I hope it manages to convey the idea and the need for this particular feature.


Version: 1.15.x
Severity: enhancement

Attached:

Details

Reference
bz18856

Event Timeline

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

This seems to be specific to the edit view diff, but the hook name seems rather generic. Can you clarify the goal?

bebraw wrote:

Alright. I implemented a simple form extension for MediaWiki (I know there are at least two other of those available but neither matched my demands :) ). This means that when editing certain pages besides the traditional editing box the user sees some additional fields. Pages having forms are defined using category hierarchy and by matching templates to the category names. The templates define the overall structure and outlook of the document. Furthermore it contains markup (ie. {{{textbox:textbox name}}} ) to determine where to show fields. The extension constructs the editing pages based on this information (category/template matching + template markup -> form).

I stash the user provided information on wiki pages in the syntax using comments and serializing (explains the removeCommentLines part on previous example). Furthermore each property (ie. field but as a more generic concept) can render itself in wiki syntax (renderProperties on previous example). I use renderProperties also in following way:

$wgHooks['EditPage::attemptSave'][] = 'combineBeforeWikiParse';
$wgHooks['EditPageBeforePreviewText'][] = 'combineBeforeWikiParse';
function combineBeforeWikiParse( $editPage ) {
if( pageIsEditable() ) {

		$editPage->textbox1 = renderProperties($editPage) . $editPage->textbox1;

}

return true;
}

So you can think it as a template engine sitting on top of MediaWiki's template engine. In fact you could easily replace MediaWiki's current syntax with totally different one this way but that's another story and goes beyond the point. Basically if you are doing this sort of things and want to have preview working properly, you have to do little tricks such as this. It's possible I have missed some obvious solution given that I'm new to MediaWiki extension coding though. :)

I agree that the name of the hook may not be the best possible. Feel free to suggest more fitting one. :)

Bryan.TongMinh wrote:

The prefix Revisions suggests that the subject is revisions, however the subject is Diff. I would opt for a better naming (DiffBeforeDiff, DiffBeforeGeneration?)

wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );