apply preSaveTransform to script pages
authordaniel <daniel.kinzler@wikimedia.de>
Tue, 12 Jun 2012 08:32:42 +0000 (10:32 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Tue, 12 Jun 2012 08:32:42 +0000 (10:32 +0200)
includes/Article.php
includes/Content.php
tests/phpunit/includes/JavascriptContentTest.php

index b252920..7c76806 100644 (file)
@@ -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__ );
 
index 5965753..caea845 100644 (file)
@@ -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 );
+       }
+
 }
index 7a12ada..c402458 100644 (file)
@@ -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(