From: Tim Starling Date: Mon, 12 Nov 2007 07:30:40 +0000 (+0000) Subject: Added EditFilterMerged hook: like EditFilter but uses the text after section merging... X-Git-Tag: 1.31.0-rc.0~50907 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=af7be3b1b7b2f9e1aa32007857a21df3c6a0cfc0;p=lhc%2Fweb%2Fwiklou.git Added EditFilterMerged hook: like EditFilter but uses the text after section merging. This allows ConfirmEdit and SpamBlacklist to share a parse with Article::editUpdates(). Article::prepareTextForEdit() facilitates this sharing. Unfortunately this means that {{REVISIONID}} will no longer work for current page views. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a4b06d29d8..3a20a41825 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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, diff --git a/includes/Article.php b/includes/Article.php index cd71adf212..7f23be4fcd 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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 ) ) ) { diff --git a/includes/Defines.php b/includes/Defines.php index c923c25605..d75c441e88 100644 --- a/includes/Defines.php +++ b/includes/Defines.php @@ -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 ); diff --git a/includes/EditPage.php b/includes/EditPage.php index ee0d6c6ae4..15a56a93d3 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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 )) {