Add new hook ArticlePrepareTextForEdit, called when preparing text to be saved.
authorRobert Leverington <roberthl@users.mediawiki.org>
Sun, 16 Jan 2011 21:12:26 +0000 (21:12 +0000)
committerRobert Leverington <roberthl@users.mediawiki.org>
Sun, 16 Jan 2011 21:12:26 +0000 (21:12 +0000)
Add new parser option "PreSaveTransform" that allows the pre-save transformation to be selectively disabled.

RELEASE-NOTES
docs/hooks.txt
includes/Article.php
includes/parser/Parser.php
includes/parser/ParserOptions.php

index bd8c551..9db072a 100644 (file)
@@ -46,6 +46,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 6672) Images are now autorotated according to their EXIF orientation. 
   This only affects thumbnails; the source remains unrotated.
 * (bug 25708) Update case mappings and normalization to Unicode 6.0.0
+* New hook ArticlePrepareTextForEdit added, called when preparing text to be saved.
+* New parser option PreSaveTransform added, allows the pre-save transformation
+  to be selectively disabled.
 
 === Bug fixes in 1.18 ===
 * (bug 23119) WikiError class and subclasses are now marked as deprecated
index dfc7a95..dfa34fe 100644 (file)
@@ -441,6 +441,10 @@ $row: row (object) returned from the database server
 $article: article (object) that data will be loaded
 $fields: fileds (array) to load from the database
 
+'ArticlePrepareTextForEdit': called when preparing text to be saved
+$article: the article being saved
+$popts: parser options to be used for pre-save transformation
+
 'ArticleProtect': before an article is protected
 $article: the article being protected
 $user: the user doing the protection
index b0a1764..44bd713 100644 (file)
@@ -3596,10 +3596,17 @@ class Article {
 
                global $wgParser;
 
+               if( $user === null ) {
+                       global $wgUser;
+                       $user = $wgUser;
+               }
+               $popts = ParserOptions::newFromUser( $user );
+               wfRunHooks( 'ArticlePrepareTextForEdit', array( $this, $popts ) );
+
                $edit = (object)array();
                $edit->revid = $revid;
                $edit->newText = $text;
-               $edit->pst = $this->preSaveTransform( $text, $user );
+               $edit->pst = $this->preSaveTransform( $text, $user, $popts );
                $edit->popts = $this->getParserOptions( true );
                $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid );
                $edit->oldText = $this->getRawText();
@@ -3876,10 +3883,12 @@ class Article {
         * @param $text String article contents
         * @param $user User object: user doing the edit, $wgUser will be used if
         *              null is given
+        * @param $popts ParserOptions object: parser options, default options for
+        *               the user loaded if null given
         * @return string article contents with altered wikitext markup (signatures
         *      converted, {{subst:}}, templates, etc.)
         */
-       public function preSaveTransform( $text, User $user = null ) {
+       public function preSaveTransform( $text, User $user = null, ParserOptions $popts = null ) {
                global $wgParser;
 
                if ( $user === null ) {
@@ -3887,7 +3896,11 @@ class Article {
                        $user = $wgUser;
                }
 
-               return $wgParser->preSaveTransform( $text, $this->mTitle, $user, ParserOptions::newFromUser( $user ) );
+               if ( $popts === null ) {
+                       $popts = ParserOptions::newFromUser( $user );
+               }
+
+               return $wgParser->preSaveTransform( $text, $this->mTitle, $user, $popts );
        }
 
        /* Caching functions */
index 777db67..7eadf39 100644 (file)
@@ -4053,7 +4053,9 @@ class Parser {
                        "\r\n" => "\n",
                );
                $text = str_replace( array_keys( $pairs ), array_values( $pairs ), $text );
-               $text = $this->pstPass2( $text, $user );
+               if( $options->getPreSaveTransform() ) {
+                       $text = $this->pstPass2( $text, $user );
+               }
                $text = $this->mStripState->unstripBoth( $text );
 
                $this->setUser( null ); #Reset
index 99d680c..a9a5467 100644 (file)
@@ -36,6 +36,7 @@ class ParserOptions {
        var $mTimestamp;                 # Timestamp used for {{CURRENTDAY}} etc.
        var $mExternalLinkTarget;        # Target attribute for external links
        var $mCleanSignatures;           #
+       var $mPreSaveTransform = true;   # Transform wiki markup when saving the page.
 
        var $mNumberHeadings;            # Automatically number headings
        var $mMath;                      # User math preference (as integer)
@@ -82,6 +83,7 @@ class ParserOptions {
        function getIsPrintable()                   { $this->optionUsed('printable');
                                                                                                  return $this->mIsPrintable; }
        function getUser()                          { return $this->mUser; }
+       function getPreSaveTransform()              { return $this->mPreSaveTransform; }
 
        function getSkin( $title = null ) {
                if ( !isset( $this->mSkin ) ) {
@@ -140,6 +142,7 @@ class ParserOptions {
        function setMath( $x )                      { return wfSetVar( $this->mMath, $x ); }
        function setUserLang( $x )                  { return wfSetVar( $this->mUserLang, $x ); }
        function setThumbSize( $x )                 { return wfSetVar( $this->mThumbSize, $x ); }
+       function setPreSaveTransform( $x )          { return wfSetVar( $this->mPreSaveTransform, $x ); }
 
        function setIsPreview( $x )                 { return wfSetVar( $this->mIsPreview, $x ); }
        function setIsSectionPreview( $x )          { return wfSetVar( $this->mIsSectionPreview, $x ); }