aboutsummaryrefslogtreecommitdiffstats
path: root/includes/content/Transform
diff options
context:
space:
mode:
authorRoman Stolar <roman.stolar@speedandfunction.com>2021-08-09 16:39:19 +0300
committerDaniel Kinzler <dkinzler@wikimedia.org>2021-08-17 15:17:34 +0000
commit42442e01ff7e503fd89084d5d82a0586aeaa382f (patch)
tree3bfedfada31bbe25cef625a9329a9fedd318be6f /includes/content/Transform
parent63da9a14300c212c678b147f5703ffa356a452c7 (diff)
downloadmediawikicore-42442e01ff7e503fd89084d5d82a0586aeaa382f.tar.gz
mediawikicore-42442e01ff7e503fd89084d5d82a0586aeaa382f.zip
Move Content::preloadTransform to ContentHandler
Update ContentTransformer to access ContentHandler::preLoadTransform through the service. Prepare object to hold a data that required for ContentHandler::preLoadTranform params. This is a fully backwards compatible change. We are doing hard deprecation via MWDebug::detectDeprecatedOverride. However, with the ContentHandler calling Content and Content calling ContentHandler, it doesn't matter whether callers use Content or ContentHandler. This will allow us to naturally convert all callers. Bug: T287157 Change-Id: I89537e1e7d24c6e15252b2b51890a0bd81ea3e6b
Diffstat (limited to 'includes/content/Transform')
-rw-r--r--includes/content/Transform/ContentTransformer.php23
-rw-r--r--includes/content/Transform/PreloadTransformParams.php27
-rw-r--r--includes/content/Transform/PreloadTransformParamsValue.php50
3 files changed, 100 insertions, 0 deletions
diff --git a/includes/content/Transform/ContentTransformer.php b/includes/content/Transform/ContentTransformer.php
index 2229f4b86ba0..01288b887021 100644
--- a/includes/content/Transform/ContentTransformer.php
+++ b/includes/content/Transform/ContentTransformer.php
@@ -45,4 +45,27 @@ class ContentTransformer {
return $contentHandler->preSaveTransform( $content, $pstParams );
}
+
+ /**
+ * Returns a Content object with preload transformations applied (or $content
+ * if no transformations apply).
+ *
+ * @param Content $content
+ * @param PageReference $page
+ * @param ParserOptions $parserOptions
+ * @param array $params
+ *
+ * @return Content
+ */
+ public function preloadTransform(
+ Content $content,
+ PageReference $page,
+ ParserOptions $parserOptions,
+ array $params = []
+ ): Content {
+ $contentHandler = $this->contentHandlerFactory->getContentHandler( $content->getModel() );
+ $pltParams = new PreloadTransformParamsValue( $page, $parserOptions, $params );
+
+ return $contentHandler->preloadTransform( $content, $pltParams );
+ }
}
diff --git a/includes/content/Transform/PreloadTransformParams.php b/includes/content/Transform/PreloadTransformParams.php
new file mode 100644
index 000000000000..92277904c663
--- /dev/null
+++ b/includes/content/Transform/PreloadTransformParams.php
@@ -0,0 +1,27 @@
+<?php
+namespace MediaWiki\Content\Transform;
+
+use MediaWiki\Page\PageReference;
+use ParserOptions;
+
+/**
+ * @since 1.37
+ * An interface to hold pre-load transform params.
+ */
+interface PreloadTransformParams {
+
+ /**
+ * @return PageReference
+ */
+ public function getPage(): PageReference;
+
+ /**
+ * @return array
+ */
+ public function getParams(): array;
+
+ /**
+ * @return ParserOptions
+ */
+ public function getParserOptions(): ParserOptions;
+}
diff --git a/includes/content/Transform/PreloadTransformParamsValue.php b/includes/content/Transform/PreloadTransformParamsValue.php
new file mode 100644
index 000000000000..f1f1fbeb2be2
--- /dev/null
+++ b/includes/content/Transform/PreloadTransformParamsValue.php
@@ -0,0 +1,50 @@
+<?php
+namespace MediaWiki\Content\Transform;
+
+use MediaWiki\Page\PageReference;
+use ParserOptions;
+
+/**
+ * @internal
+ * An object to hold preload transform params.
+ */
+class PreloadTransformParamsValue implements PreloadTransformParams {
+ /** @var PageReference */
+ private $page;
+
+ /** @var array */
+ private $params;
+
+ /** @var ParserOptions */
+ private $parserOptions;
+
+ public function __construct( PageReference $page, ParserOptions $parserOptions, array $params = [] ) {
+ $this->page = $page;
+ $this->parserOptions = $parserOptions;
+ $this->params = $params;
+ }
+
+ /**
+ *
+ * @return PageReference
+ */
+ public function getPage(): PageReference {
+ return $this->page;
+ }
+
+ /**
+ *
+ * @return array
+ */
+ public function getParams(): array {
+ return $this->params;
+ }
+
+ /**
+ *
+ * @return ParserOptions
+ */
+ public function getParserOptions(): ParserOptions {
+ return $this->parserOptions;
+ }
+}