From 8d198333d30f8878eed73793e616b042b71f4682 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 9 Nov 2012 16:54:57 -0800 Subject: [PATCH] Add EditPage hooks AlternateEditPreview, EditPage::showStandardInputs:options Adds two new hooks: * AlternateEditPreview allows an extension to override the standard page preview display. * EditPage::showStandardInputs:options allows an extension to add additional HTML to the end of the editOptions area of the edit form. Change-Id: Ic5d35c8e9ff71282b5ebccc87c64894a385e5836 --- RELEASE-NOTES-1.21 | 4 ++++ docs/hooks.txt | 15 +++++++++++++++ includes/EditPage.php | 10 +++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index 6fdbfb9242..a0035d5d54 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -41,6 +41,10 @@ production. for use with Microdata. * The HTML5 tag has been whitelisted. * Added ParserCloned hook for when the Parser object is cloned. +* Added AlternateEditPreview hook to allow extensions to replace the page + preview from the edit page. +* Added EditPage::showStandardInputs:options hook to allow extensions to add + new fields to the "editOptions" area of the edit form. === Bug fixes in 1.21 === * (bug 40353) SpecialDoubleRedirect should support interwiki redirects. diff --git a/docs/hooks.txt b/docs/hooks.txt index 46b1b26e4d..a9a7c10aa2 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -310,6 +310,15 @@ before showing the edit form ( EditPage::edit() ). This is triggered on &action=edit. $EditPage: the EditPage object +'AlternateEditPreview': before generating the preview of the page when editing +( EditPage::getPreviewText() ). +$EditPage: the EditPage object +&$content: the Content object for the text field from the edit page +&$previewHTML: Text to be placed into the page for the preview +&$parserOutput: the ParserOutput object for the preview +return false and set $previewHTML and $parserOutput to output custom page +preview HTML. + 'AlternateUserMailer': Called before mail is sent so that mail could be logged (or something else) instead of using PEAR or PHP's mail(). Return false to skip the regular method of sending mail. Return a @@ -886,6 +895,12 @@ yourself. Alternatively, modifying $error and returning true will cause the contents of $error to be echoed at the top of the edit form as wikitext. Return true without altering $error to allow the edit to proceed. +'EditPage::showStandardInputs:options': allows injection of form fields into +the editOptions area +$editor: EditPage instance (object) +$out: an OutputPage instance to write to +return value is ignored (should always be true) + 'EditPageBeforeConflictDiff': allows modifying the EditPage object and output when there's an edit conflict. Return false to halt normal diff output; in this case you're responsible for computing and outputting the entire "conflict" diff --git a/includes/EditPage.php b/includes/EditPage.php index 89daf521c7..5ab5adc923 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2780,7 +2780,9 @@ HTML wfMessage( 'newwindow' )->parse(); $wgOut->addHTML( " {$cancel}\n" ); $wgOut->addHTML( " {$edithelp}\n" ); - $wgOut->addHTML( "\n\n" ); + $wgOut->addHTML( "\n" ); + wfRunHooks( 'EditPage::showStandardInputs:options', array( $this, $wgOut, &$tabindex ) ); + $wgOut->addHTML( "\n" ); } /** @@ -2930,6 +2932,12 @@ HTML try { $content = $this->toEditContent( $this->textbox1 ); + $previewHTML = ''; + if ( !wfRunHooks( 'AlternateEditPreview', array( $this, &$content, &$previewHTML, &$this->mParserOutput ) ) ) { + wfProfileOut( __METHOD__ ); + return $previewHTML; + } + if ( $this->mTriedSave && !$this->mTokenOk ) { if ( $this->mTokenOkExceptSuffix ) { $note = wfMessage( 'token_suffix_mismatch' )->plain() ; -- 2.20.1