(bug 5841) Allow the 'EditFilter' hook to return a non-fatal error message
authorRob Church <robchurch@users.mediawiki.org>
Sat, 6 May 2006 21:41:53 +0000 (21:41 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Sat, 6 May 2006 21:41:53 +0000 (21:41 +0000)
RELEASE-NOTES
docs/hooks.txt
includes/EditPage.php

index 8b0ca36..5eb22af 100644 (file)
@@ -220,7 +220,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 5839) Prevent access to Special:Confirmemail for logged-out users
 * (bug 5853) Update for Portuguese messages (pt)
 * (bug 5851) Use Cyrillic for Kirghiz language name
-
+* (bug 5841) Allow the 'EditFilter' hook to return a non-fatal error message
 
 == Compatibility ==
 
index a8bfd5b..3c46368 100644 (file)
@@ -297,6 +297,17 @@ $user: the user _doing_ the block (not the one being blocked)
 $block: the Block object that was saved
 $user: the user who did the block (not the one being blocked)
 
+'EditFilter': Perform checks on an edit
+$editor: Edit form (see includes/EditPage.php)
+$text: Contents of the edit box
+&section: Section being edited
+$error: Error message to return
+
+Return false to halt editing; you'll need to handle error messages, etc. 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.
+
 'EmailConfirmed': When checking that the user's email address is "confirmed"
 $user: User being checked
 $confirmed: Whether or not the email address is confirmed
index 90bc135..b14b1c8 100644 (file)
@@ -30,6 +30,7 @@ class EditPage {
        var $missingSummary = false;
        var $allowBlankSummary = false;
        var $autoSumm = '';
+       var $hookError = '';
 
        # Form values
        var $save = false, $preview = false, $diff = false;
@@ -492,11 +493,16 @@ class EditPage {
                        wfProfileOut( "$fname-checks" );
                        return false;
                }
-               if ( !wfRunHooks( 'EditFilter', array( &$this, $this->textbox1, $this->section ) ) ) {
-                       # Error messages or other handling should be performed by the filter function
+               if ( !wfRunHooks( 'EditFilter', array( &$this, $this->textbox1, $this->section, &$this->hookError ) ) ) {
+                       # Error messages etc. could be handled within the hook...
                        wfProfileOut( $fname );
                        wfProfileOut( "$fname-checks" );
                        return false;
+               } elseif( $this->hookError != '' ) {
+                       # ...or the hook could be expecting us to produce an error
+                       wfProfileOut( "$fname-checks " );
+                       wfProfileOut( $fname );
+                       return false;
                }
                if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
                        # Check block state against master, thus 'false'.
@@ -771,6 +777,10 @@ class EditPage {
                        if( $this->missingSummary ) {
                                $wgOut->addWikiText( wfMsg( 'missingsummary' ) );
                        }
+                       
+                       if( !$this->hookError = '' ) {
+                               $wgOut->addWikiText( $this->hookError );
+                       }
 
                        if ( !$this->checkUnicodeCompliantBrowser() ) {
                                $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );