From: daniel Date: Tue, 12 Jun 2012 08:32:42 +0000 (+0200) Subject: apply preSaveTransform to script pages X-Git-Tag: 1.31.0-rc.0~22097^2^2~110 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;h=7a89241457f02f85a4739a122d8827734dacc7d7;p=lhc%2Fweb%2Fwiklou.git apply preSaveTransform to script pages --- diff --git a/includes/Article.php b/includes/Article.php index b252920d2e..7c76806ed4 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -390,7 +390,7 @@ class Article extends Page { $content = $this->fetchContentObject(); $this->mContent = ContentHandler::getContentText( $content ); #@todo: get rid of mContent everywhere! - wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) ); #BC cruft! #XXX: can we deprecate that hook? + wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) ); #BC cruft, deprecated! wfProfileOut( __METHOD__ ); diff --git a/includes/Content.php b/includes/Content.php index 5965753d0c..caea845519 100644 --- a/includes/Content.php +++ b/includes/Content.php @@ -948,15 +948,15 @@ class WikitextContent extends TextContent { } /** - * Returns a Content object with pre-save transformations applied (or this object if no transformations apply). + * Returns a Content object with pre-save transformations applied using Parser::preSaveTransform(). * * @param Title $title * @param User $user * @param ParserOptions $popts * @return Content */ - public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { #FIXME: also needed for JS/CSS! - global $wgParser, $wgConteLang; + public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { + global $wgParser; $text = $this->getNativeData(); $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts ); @@ -972,7 +972,7 @@ class WikitextContent extends TextContent { * @return Content */ public function preloadTransform( Title $title, ParserOptions $popts ) { - global $wgParser, $wgConteLang; + global $wgParser; $text = $this->getNativeData(); $plt = $wgParser->getPreloadText( $text, $title, $popts ); @@ -1130,6 +1130,24 @@ class JavaScriptContent extends TextContent { parent::__construct($text, CONTENT_MODEL_JAVASCRIPT); } + /** + * Returns a Content object with pre-save transformations applied using Parser::preSaveTransform(). + * + * @param Title $title + * @param User $user + * @param ParserOptions $popts + * @return Content + */ + public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { + global $wgParser; + // @todo: make pre-save transformation optional for script pages + + $text = $this->getNativeData(); + $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts ); + + return new JavaScriptContent( $pst ); + } + } /** @@ -1139,4 +1157,23 @@ class CssContent extends TextContent { public function __construct( $text ) { parent::__construct($text, CONTENT_MODEL_CSS); } + + /** + * Returns a Content object with pre-save transformations applied using Parser::preSaveTransform(). + * + * @param Title $title + * @param User $user + * @param ParserOptions $popts + * @return Content + */ + public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { + global $wgParser; + // @todo: make pre-save transformation optional for script pages + + $text = $this->getNativeData(); + $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts ); + + return new CssContent( $pst ); + } + } diff --git a/tests/phpunit/includes/JavascriptContentTest.php b/tests/phpunit/includes/JavascriptContentTest.php index 7a12ada5cd..c402458b8c 100644 --- a/tests/phpunit/includes/JavascriptContentTest.php +++ b/tests/phpunit/includes/JavascriptContentTest.php @@ -76,6 +76,8 @@ class JavascriptContentTest extends WikitextContentTest { $this->assertTrue( $content->equals( $c ) ); } + // XXX: currently, preSaveTransform is applied to scripts. this may change or become optional. + /* public function dataPreSaveTransform() { return array( array( 'hello this is ~~~', @@ -86,6 +88,7 @@ class JavascriptContentTest extends WikitextContentTest { ), ); } + */ public function dataPreloadTransform() { return array(