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.
This commit is contained in:
parent
c1aa3f3a8d
commit
2a30aa1d25
5 changed files with 29 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 ); }
|
||||
|
|
|
|||
Loading…
Reference in a new issue