Last modified: 2011-11-20 18:49:04 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T20856, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 18856 - RevisionsBeforeDiff hook
RevisionsBeforeDiff hook
Status: RESOLVED WORKSFORME
Product: MediaWiki
Classification: Unclassified
Page editing (Other open bugs)
1.15.x
All All
: Low enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
: patch, patch-need-review
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-05-20 15:32 UTC by Juho Vepsäläinen
Modified: 2011-11-20 18:49 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
initial patch (1.21 KB, patch)
2009-05-20 15:32 UTC, Juho Vepsäläinen
Details

Description Juho Vepsäläinen 2009-05-20 15:32:17 UTC
Created attachment 6141 [details]
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.
Comment 1 Brion Vibber 2009-05-26 20:56:57 UTC
This seems to be specific to the edit view diff, but the hook name seems rather generic. Can you clarify the goal?
Comment 2 Juho Vepsäläinen 2009-05-27 06:47:59 UTC
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. :)
Comment 3 Bryan Tong Minh 2009-11-12 22:18:35 UTC
The prefix Revisions suggests that the subject is revisions, however the subject is Diff. I would opt for a better naming (DiffBeforeDiff, DiffBeforeGeneration?)
Comment 4 Sam Reed (reedy) 2011-11-20 18:49:04 UTC
wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links