r27416 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r27415‎ | r27416 | r27417 >
Date:07:30, 12 November 2007
Author:tstarling
Status:old
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Defines.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Defines.php
@@ -260,6 +260,7 @@
261261 define( 'UTF8_HEAD', false );
262262 define( 'UTF8_TAIL', true );
263263
 264+# Hook support constants
 265+define( 'MW_SUPPORTS_EDITFILTERMERGED', 1 );
264266
265267
266 -
Index: trunk/phase3/includes/Article.php
@@ -135,6 +135,7 @@
136136 $this->mRevIdFetched = 0;
137137 $this->mRedirectUrl = false;
138138 $this->mLatest = false;
 139+ $this->mPreparedEdit = false;
139140 }
140141
141142 /**
@@ -1330,7 +1331,8 @@
13311332 if ($flags & EDIT_AUTOSUMMARY && $summary == '')
13321333 $summary = $this->getAutosummary( $oldtext, $text, $flags );
13331334
1334 - $text = $this->preSaveTransform( $text );
 1335+ $editInfo = $this->prepareTextForEdit( $text );
 1336+ $text = $editInfo->pst;
13351337 $newsize = strlen( $text );
13361338
13371339 $dbw = wfGetDB( DB_MASTER );
@@ -2420,6 +2422,27 @@
24212423 }
24222424
24232425 /**
 2426+ * Prepare text which is about to be saved.
 2427+ * Returns a stdclass with source, pst and output members
 2428+ */
 2429+ function prepareTextForEdit( $text ) {
 2430+ if ( $this->mPreparedEdit && $this->mPreparedEdit->newText == $text ) {
 2431+ // Already prepared
 2432+ return $this->mPreparedEdit;
 2433+ }
 2434+ global $wgParser;
 2435+ $edit = (object)array();
 2436+ $edit->newText = $text;
 2437+ $edit->pst = $this->preSaveTransform( $text );
 2438+ $options = new ParserOptions;
 2439+ $options->setTidy( true );
 2440+ $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $options, true, true );
 2441+ $edit->oldText = $this->getContent();
 2442+ $this->mPreparedEdit = $edit;
 2443+ return $edit;
 2444+ }
 2445+
 2446+ /**
24242447 * Do standard deferred updates after page edit.
24252448 * Update links tables, site stats, search index and message cache.
24262449 * Every 100th edit, prune the recent changes table.
@@ -2438,16 +2461,19 @@
24392462 wfProfileIn( __METHOD__ );
24402463
24412464 # Parse the text
2442 - $options = new ParserOptions;
2443 - $options->setTidy(true);
2444 - $poutput = $wgParser->parse( $text, $this->mTitle, $options, true, true, $newid );
 2465+ # Be careful not to double-PST: $text is usually already PST-ed once
 2466+ if ( !$this->mPreparedEdit ) {
 2467+ $editInfo = $this->prepareTextForEdit( $text );
 2468+ } else {
 2469+ $editInfo = $this->mPreparedEdit;
 2470+ }
24452471
24462472 # Save it to the parser cache
24472473 $parserCache =& ParserCache::singleton();
2448 - $parserCache->save( $poutput, $this, $wgUser );
 2474+ $parserCache->save( $editInfo->output, $this, $wgUser );
24492475
24502476 # Update the links tables
2451 - $u = new LinksUpdate( $this->mTitle, $poutput );
 2477+ $u = new LinksUpdate( $this->mTitle, $editInfo->output );
24522478 $u->doUpdate();
24532479
24542480 if( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
Index: trunk/phase3/includes/EditPage.php
@@ -768,7 +768,15 @@
769769 return self::AS_BLANK_ARTICLE;
770770 }
771771
772 - $isComment=($this->section=='new');
 772+ // Run post-section-merge edit filter
 773+ if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError ) ) ) {
 774+ # Error messages etc. could be handled within the hook...
 775+ wfProfileOut( $fname );
 776+ return false;
 777+ }
 778+
 779+ $isComment = ( $this->section == 'new' );
 780+
773781 $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
774782 $this->minoredit, $this->watchthis, false, $isComment);
775783
@@ -843,6 +851,13 @@
844852
845853 $oldtext = $this->mArticle->getContent();
846854
 855+ // Run post-section-merge edit filter
 856+ if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError ) ) ) {
 857+ # Error messages etc. could be handled within the hook...
 858+ wfProfileOut( $fname );
 859+ return false;
 860+ }
 861+
847862 # Handle the user preference to force summaries here, but not for null edits
848863 if( $this->section != 'new' && !$this->allowBlankSummary && $wgUser->getOption( 'forceeditsummary')
849864 && 0 != strcmp($oldtext, $text) && !Article::getRedirectAutosummary( $text )) {
Index: trunk/phase3/RELEASE-NOTES
@@ -20,6 +20,10 @@
2121
2222 === Configuration changes in 1.12 ===
2323
 24+=== Removed features in 1.12 ===
 25+* {{REVISIONID}} will no longer give the correct revision ID for current revision
 26+ views. It will still work for history views.
 27+
2428 === New features in 1.12 ===
2529 * (bug 10735) Add a warning for non-descriptive filenames at Special:Upload
2630 * Add {{filepath:}} parser function to get full path to an uploaded file,

Follow-up revisions

RevisionCommit summaryAuthorDate
r27511Fix regression in r27416 -- {{REVISIONID}} was broken on save since a parsed ...brion02:54, 15 November 2007
r104066MW_SUPPORTS_EDITFILTERMERGED has been in since r27416...reedy19:18, 23 November 2011

Status & tagging log