aboutsummaryrefslogtreecommitdiffstats
path: root/includes/content/JavaScriptContentHandler.php
diff options
context:
space:
mode:
authorPetr Pchelko <ppchelko@wikimedia.org>2021-07-20 18:03:59 -0700
committerRoman Stolar <roman.stolar@speedandfunction.com>2021-07-29 18:06:02 +0300
commitb782a7e66ddff2c168b3f52a9cfe0cd86608b953 (patch)
tree52b5f2a671ffc7f9f3d6f147c66d34843af312a5 /includes/content/JavaScriptContentHandler.php
parentb03f5b5e4ad69cb45cb1f138e504b66edba5bce3 (diff)
downloadmediawikicore-b782a7e66ddff2c168b3f52a9cfe0cd86608b953.tar.gz
mediawikicore-b782a7e66ddff2c168b3f52a9cfe0cd86608b953.zip
Move Content::preSaveTransform to ContentHandler
Create ContentTransformer to access ContentHandler::preSaveTransform through the service. Prepare object to hold a data that required for ContentHandler::preSaveTranform params. This will require making a semi-backwards-incompatible change no matter what, we don't really have a great way of hard-deprecating overriding methods. However, with the ContentHandler calling Content and Content calling ContentHandler, and with the ProxyContent trick to stop infinite recursion, it doesn't matter whether callers use Content or ContentHandler. This will allow us to naturally convert all callers. But won't really allow hard-deprecation. Bug: T287156 Change-Id: If6a2025868ceca3a3b6f11baec39695e47292e40
Diffstat (limited to 'includes/content/JavaScriptContentHandler.php')
-rw-r--r--includes/content/JavaScriptContentHandler.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/includes/content/JavaScriptContentHandler.php b/includes/content/JavaScriptContentHandler.php
index 9abad3e22aef..69aeb99dacef 100644
--- a/includes/content/JavaScriptContentHandler.php
+++ b/includes/content/JavaScriptContentHandler.php
@@ -18,6 +18,9 @@
* @file
*/
+use MediaWiki\Content\Transform\PreSaveTransformParams;
+use MediaWiki\MediaWikiServices;
+
/**
* Content handler for JavaScript pages.
*
@@ -59,4 +62,31 @@ class JavaScriptContentHandler extends CodeContentHandler {
$class = $this->getContentClass();
return new $class( '/* #REDIRECT */' . Xml::encodeJsCall( 'mw.loader.load', [ $url ] ) );
}
+
+ public function preSaveTransform(
+ Content $content,
+ PreSaveTransformParams $pstParams
+ ): Content {
+ '@phan-var JavascriptContent $content';
+
+ $parserOptions = $pstParams->getParserOptions();
+ // @todo Make pre-save transformation optional for script pages (T34858)
+ $services = MediaWikiServices::getInstance();
+ if ( !$services->getUserOptionsLookup()->getBoolOption( $pstParams->getUser(), 'pst-cssjs' ) ) {
+ // Allow bot users to disable the pre-save transform for CSS/JS (T236828).
+ $parserOptions = clone $parserOptions;
+ $parserOptions->setPreSaveTransform( false );
+ }
+
+ $text = $content->getText();
+ $pst = $services->getParser()->preSaveTransform(
+ $text,
+ $pstParams->getPage(),
+ $pstParams->getUser(),
+ $parserOptions
+ );
+
+ $contentClass = $this->getContentClass();
+ return new $contentClass( $pst );
+ }
}