r80428 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80427‎ | r80428 | r80429 >
Date:21:12, 16 January 2011
Author:roberthl
Status:ok
Tags:
Comment:
Add new hook ArticlePrepareTextForEdit, called when preparing text to be saved.
Add new parser option "PreSaveTransform" that allows the pre-save transformation to be selectively disabled.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOptions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -441,6 +441,10 @@
442442 $article: article (object) that data will be loaded
443443 $fields: fileds (array) to load from the database
444444
 445+'ArticlePrepareTextForEdit': called when preparing text to be saved
 446+$article: the article being saved
 447+$popts: parser options to be used for pre-save transformation
 448+
445449 'ArticleProtect': before an article is protected
446450 $article: the article being protected
447451 $user: the user doing the protection
Index: trunk/phase3/includes/Article.php
@@ -3596,10 +3596,17 @@
35973597
35983598 global $wgParser;
35993599
 3600+ if( $user === null ) {
 3601+ global $wgUser;
 3602+ $user = $wgUser;
 3603+ }
 3604+ $popts = ParserOptions::newFromUser( $user );
 3605+ wfRunHooks( 'ArticlePrepareTextForEdit', array( $this, $popts ) );
 3606+
36003607 $edit = (object)array();
36013608 $edit->revid = $revid;
36023609 $edit->newText = $text;
3603 - $edit->pst = $this->preSaveTransform( $text, $user );
 3610+ $edit->pst = $this->preSaveTransform( $text, $user, $popts );
36043611 $edit->popts = $this->getParserOptions( true );
36053612 $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid );
36063613 $edit->oldText = $this->getRawText();
@@ -3876,10 +3883,12 @@
38773884 * @param $text String article contents
38783885 * @param $user User object: user doing the edit, $wgUser will be used if
38793886 * null is given
 3887+ * @param $popts ParserOptions object: parser options, default options for
 3888+ * the user loaded if null given
38803889 * @return string article contents with altered wikitext markup (signatures
38813890 * converted, {{subst:}}, templates, etc.)
38823891 */
3883 - public function preSaveTransform( $text, User $user = null ) {
 3892+ public function preSaveTransform( $text, User $user = null, ParserOptions $popts = null ) {
38843893 global $wgParser;
38853894
38863895 if ( $user === null ) {
@@ -3887,7 +3896,11 @@
38883897 $user = $wgUser;
38893898 }
38903899
3891 - return $wgParser->preSaveTransform( $text, $this->mTitle, $user, ParserOptions::newFromUser( $user ) );
 3900+ if ( $popts === null ) {
 3901+ $popts = ParserOptions::newFromUser( $user );
 3902+ }
 3903+
 3904+ return $wgParser->preSaveTransform( $text, $this->mTitle, $user, $popts );
38923905 }
38933906
38943907 /* Caching functions */
Index: trunk/phase3/includes/parser/Parser.php
@@ -4053,7 +4053,9 @@
40544054 "\r\n" => "\n",
40554055 );
40564056 $text = str_replace( array_keys( $pairs ), array_values( $pairs ), $text );
4057 - $text = $this->pstPass2( $text, $user );
 4057+ if( $options->getPreSaveTransform() ) {
 4058+ $text = $this->pstPass2( $text, $user );
 4059+ }
40584060 $text = $this->mStripState->unstripBoth( $text );
40594061
40604062 $this->setUser( null ); #Reset
Index: trunk/phase3/includes/parser/ParserOptions.php
@@ -36,6 +36,7 @@
3737 var $mTimestamp; # Timestamp used for {{CURRENTDAY}} etc.
3838 var $mExternalLinkTarget; # Target attribute for external links
3939 var $mCleanSignatures; #
 40+ var $mPreSaveTransform = true; # Transform wiki markup when saving the page.
4041
4142 var $mNumberHeadings; # Automatically number headings
4243 var $mMath; # User math preference (as integer)
@@ -82,6 +83,7 @@
8384 function getIsPrintable() { $this->optionUsed('printable');
8485 return $this->mIsPrintable; }
8586 function getUser() { return $this->mUser; }
 87+ function getPreSaveTransform() { return $this->mPreSaveTransform; }
8688
8789 function getSkin( $title = null ) {
8890 if ( !isset( $this->mSkin ) ) {
@@ -140,6 +142,7 @@
141143 function setMath( $x ) { return wfSetVar( $this->mMath, $x ); }
142144 function setUserLang( $x ) { return wfSetVar( $this->mUserLang, $x ); }
143145 function setThumbSize( $x ) { return wfSetVar( $this->mThumbSize, $x ); }
 146+ function setPreSaveTransform( $x ) { return wfSetVar( $this->mPreSaveTransform, $x ); }
144147
145148 function setIsPreview( $x ) { return wfSetVar( $this->mIsPreview, $x ); }
146149 function setIsSectionPreview( $x ) { return wfSetVar( $this->mIsSectionPreview, $x ); }
Index: trunk/phase3/RELEASE-NOTES
@@ -46,6 +46,9 @@
4747 * (bug 6672) Images are now autorotated according to their EXIF orientation.
4848 This only affects thumbnails; the source remains unrotated.
4949 * (bug 25708) Update case mappings and normalization to Unicode 6.0.0
 50+* New hook ArticlePrepareTextForEdit added, called when preparing text to be saved.
 51+* New parser option PreSaveTransform added, allows the pre-save transformation
 52+ to be selectively disabled.
5053
5154 === Bug fixes in 1.18 ===
5255 * (bug 23119) WikiError class and subclasses are now marked as deprecated

Status & tagging log