Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -441,6 +441,10 @@ |
442 | 442 | $article: article (object) that data will be loaded |
443 | 443 | $fields: fileds (array) to load from the database |
444 | 444 | |
| 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 | + |
445 | 449 | 'ArticleProtect': before an article is protected |
446 | 450 | $article: the article being protected |
447 | 451 | $user: the user doing the protection |
Index: trunk/phase3/includes/Article.php |
— | — | @@ -3596,10 +3596,17 @@ |
3597 | 3597 | |
3598 | 3598 | global $wgParser; |
3599 | 3599 | |
| 3600 | + if( $user === null ) { |
| 3601 | + global $wgUser; |
| 3602 | + $user = $wgUser; |
| 3603 | + } |
| 3604 | + $popts = ParserOptions::newFromUser( $user ); |
| 3605 | + wfRunHooks( 'ArticlePrepareTextForEdit', array( $this, $popts ) ); |
| 3606 | + |
3600 | 3607 | $edit = (object)array(); |
3601 | 3608 | $edit->revid = $revid; |
3602 | 3609 | $edit->newText = $text; |
3603 | | - $edit->pst = $this->preSaveTransform( $text, $user ); |
| 3610 | + $edit->pst = $this->preSaveTransform( $text, $user, $popts ); |
3604 | 3611 | $edit->popts = $this->getParserOptions( true ); |
3605 | 3612 | $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid ); |
3606 | 3613 | $edit->oldText = $this->getRawText(); |
— | — | @@ -3876,10 +3883,12 @@ |
3877 | 3884 | * @param $text String article contents |
3878 | 3885 | * @param $user User object: user doing the edit, $wgUser will be used if |
3879 | 3886 | * null is given |
| 3887 | + * @param $popts ParserOptions object: parser options, default options for |
| 3888 | + * the user loaded if null given |
3880 | 3889 | * @return string article contents with altered wikitext markup (signatures |
3881 | 3890 | * converted, {{subst:}}, templates, etc.) |
3882 | 3891 | */ |
3883 | | - public function preSaveTransform( $text, User $user = null ) { |
| 3892 | + public function preSaveTransform( $text, User $user = null, ParserOptions $popts = null ) { |
3884 | 3893 | global $wgParser; |
3885 | 3894 | |
3886 | 3895 | if ( $user === null ) { |
— | — | @@ -3887,7 +3896,11 @@ |
3888 | 3897 | $user = $wgUser; |
3889 | 3898 | } |
3890 | 3899 | |
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 ); |
3892 | 3905 | } |
3893 | 3906 | |
3894 | 3907 | /* Caching functions */ |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -4053,7 +4053,9 @@ |
4054 | 4054 | "\r\n" => "\n", |
4055 | 4055 | ); |
4056 | 4056 | $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 | + } |
4058 | 4060 | $text = $this->mStripState->unstripBoth( $text ); |
4059 | 4061 | |
4060 | 4062 | $this->setUser( null ); #Reset |
Index: trunk/phase3/includes/parser/ParserOptions.php |
— | — | @@ -36,6 +36,7 @@ |
37 | 37 | var $mTimestamp; # Timestamp used for {{CURRENTDAY}} etc. |
38 | 38 | var $mExternalLinkTarget; # Target attribute for external links |
39 | 39 | var $mCleanSignatures; # |
| 40 | + var $mPreSaveTransform = true; # Transform wiki markup when saving the page. |
40 | 41 | |
41 | 42 | var $mNumberHeadings; # Automatically number headings |
42 | 43 | var $mMath; # User math preference (as integer) |
— | — | @@ -82,6 +83,7 @@ |
83 | 84 | function getIsPrintable() { $this->optionUsed('printable'); |
84 | 85 | return $this->mIsPrintable; } |
85 | 86 | function getUser() { return $this->mUser; } |
| 87 | + function getPreSaveTransform() { return $this->mPreSaveTransform; } |
86 | 88 | |
87 | 89 | function getSkin( $title = null ) { |
88 | 90 | if ( !isset( $this->mSkin ) ) { |
— | — | @@ -140,6 +142,7 @@ |
141 | 143 | function setMath( $x ) { return wfSetVar( $this->mMath, $x ); } |
142 | 144 | function setUserLang( $x ) { return wfSetVar( $this->mUserLang, $x ); } |
143 | 145 | function setThumbSize( $x ) { return wfSetVar( $this->mThumbSize, $x ); } |
| 146 | + function setPreSaveTransform( $x ) { return wfSetVar( $this->mPreSaveTransform, $x ); } |
144 | 147 | |
145 | 148 | function setIsPreview( $x ) { return wfSetVar( $this->mIsPreview, $x ); } |
146 | 149 | function setIsSectionPreview( $x ) { return wfSetVar( $this->mIsSectionPreview, $x ); } |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -46,6 +46,9 @@ |
47 | 47 | * (bug 6672) Images are now autorotated according to their EXIF orientation. |
48 | 48 | This only affects thumbnails; the source remains unrotated. |
49 | 49 | * (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. |
50 | 53 | |
51 | 54 | === Bug fixes in 1.18 === |
52 | 55 | * (bug 23119) WikiError class and subclasses are now marked as deprecated |