Added EditFilterMerged hook: like EditFilter but uses the text after section merging...
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 12 Nov 2007 07:30:40 +0000 (07:30 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 12 Nov 2007 07:30:40 +0000 (07:30 +0000)
RELEASE-NOTES
includes/Article.php
includes/Defines.php
includes/EditPage.php

index a4b06d2..3a20a41 100644 (file)
@@ -20,6 +20,10 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 
 === Configuration changes in 1.12 ===
 
+=== Removed features in 1.12 ===
+* {{REVISIONID}} will no longer give the correct revision ID for current revision 
+  views. It will still work for history views. 
+
 === New features in 1.12 ===
 * (bug 10735) Add a warning for non-descriptive filenames at Special:Upload
 * Add {{filepath:}} parser function to get full path to an uploaded file,
index cd71adf..7f23be4 100644 (file)
@@ -135,6 +135,7 @@ class Article {
                $this->mRevIdFetched = 0;
                $this->mRedirectUrl = false;
                $this->mLatest = false;
+               $this->mPreparedEdit = false;
        }
 
        /**
@@ -1330,7 +1331,8 @@ class Article {
                if ($flags & EDIT_AUTOSUMMARY && $summary == '')
                        $summary = $this->getAutosummary( $oldtext, $text, $flags );
 
-               $text = $this->preSaveTransform( $text );
+               $editInfo = $this->prepareTextForEdit( $text );
+               $text = $editInfo->pst;
                $newsize = strlen( $text );
 
                $dbw = wfGetDB( DB_MASTER );
@@ -2419,6 +2421,27 @@ class Article {
                $wgUser->clearNotification( $this->mTitle );
        }
 
+       /**
+        * Prepare text which is about to be saved.
+        * Returns a stdclass with source, pst and output members
+        */
+       function prepareTextForEdit( $text ) {
+               if ( $this->mPreparedEdit && $this->mPreparedEdit->newText == $text ) {
+                       // Already prepared
+                       return $this->mPreparedEdit;
+               }
+               global $wgParser;
+               $edit = (object)array();
+               $edit->newText = $text;
+               $edit->pst = $this->preSaveTransform( $text );
+               $options = new ParserOptions;
+               $options->setTidy( true );
+               $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $options, true, true );
+               $edit->oldText = $this->getContent();
+               $this->mPreparedEdit = $edit;
+               return $edit;
+       }
+
        /**
         * Do standard deferred updates after page edit.
         * Update links tables, site stats, search index and message cache.
@@ -2438,16 +2461,19 @@ class Article {
                wfProfileIn( __METHOD__ );
 
                # Parse the text
-               $options = new ParserOptions;
-               $options->setTidy(true);
-               $poutput = $wgParser->parse( $text, $this->mTitle, $options, true, true, $newid );
+               # Be careful not to double-PST: $text is usually already PST-ed once
+               if ( !$this->mPreparedEdit ) {
+                       $editInfo = $this->prepareTextForEdit( $text );
+               } else {
+                       $editInfo = $this->mPreparedEdit;
+               }
 
                # Save it to the parser cache
                $parserCache =& ParserCache::singleton();
-               $parserCache->save( $poutput, $this, $wgUser );
+               $parserCache->save( $editInfo->output, $this, $wgUser );
 
                # Update the links tables
-               $u = new LinksUpdate( $this->mTitle, $poutput );
+               $u = new LinksUpdate( $this->mTitle, $editInfo->output );
                $u->doUpdate();
 
                if( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
index c923c25..d75c441 100644 (file)
@@ -260,6 +260,7 @@ define( 'UTF8_FFFF', "\xef\xbf\xbf" /*codepointToUtf8( 0xffff )*/ );
 define( 'UTF8_HEAD', false );
 define( 'UTF8_TAIL', true );
 
-
+# Hook support constants
+define( 'MW_SUPPORTS_EDITFILTERMERGED', 1 );
 
 
index ee0d6c6..15a56a9 100644 (file)
@@ -768,7 +768,15 @@ class EditPage {
                                        return self::AS_BLANK_ARTICLE;
                        }
 
-                       $isComment=($this->section=='new');
+                       // Run post-section-merge edit filter
+                       if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError ) ) ) {
+                               # Error messages etc. could be handled within the hook...
+                               wfProfileOut( $fname );
+                               return false;
+                       }
+
+                       $isComment = ( $this->section == 'new' );
+                       
                        $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
                                $this->minoredit, $this->watchthis, false, $isComment);
 
@@ -843,6 +851,13 @@ class EditPage {
 
                $oldtext = $this->mArticle->getContent();
 
+               // Run post-section-merge edit filter
+               if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError ) ) ) {
+                       # Error messages etc. could be handled within the hook...
+                       wfProfileOut( $fname );
+                       return false;
+               }
+
                # Handle the user preference to force summaries here, but not for null edits
                if( $this->section != 'new' && !$this->allowBlankSummary && $wgUser->getOption( 'forceeditsummary')
                        &&  0 != strcmp($oldtext, $text) && !Article::getRedirectAutosummary( $text )) {