diff --git a/extension.json b/extension.json index 385a07e74..76475cf60 100644 --- a/extension.json +++ b/extension.json @@ -447,7 +447,8 @@ "discussiontoolspreview": { "class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsPreview", "services": [ - "DiscussionTools.CommentParser" + "DiscussionTools.CommentParser", + "SkinFactory" ] }, "discussiontoolssubscribe": { diff --git a/includes/ApiDiscussionToolsEdit.php b/includes/ApiDiscussionToolsEdit.php index ef62459d6..64199646b 100644 --- a/includes/ApiDiscussionToolsEdit.php +++ b/includes/ApiDiscussionToolsEdit.php @@ -85,7 +85,8 @@ class ApiDiscussionToolsEdit extends ApiBase { 'wikitext' => $params['wikitext'], 'html' => $params['html'], 'sectiontitle' => $params['sectiontitle'], - ] + ], + $params ); $previewResultHtml = $previewResult->getResultData( [ 'parse', 'text' ] ); $previewContainer = DOMCompat::getBody( DOMUtils::parseHTML( $previewResultHtml ) ); diff --git a/includes/ApiDiscussionToolsPreview.php b/includes/ApiDiscussionToolsPreview.php index ea5728868..ff68d6aa2 100644 --- a/includes/ApiDiscussionToolsPreview.php +++ b/includes/ApiDiscussionToolsPreview.php @@ -5,6 +5,7 @@ namespace MediaWiki\Extension\DiscussionTools; use ApiBase; use ApiMain; use MediaWiki\Extension\VisualEditor\ApiParsoidTrait; +use SkinFactory; use Title; use Wikimedia\ParamValidator\ParamValidator; use Wikimedia\Parsoid\Utils\DOMCompat; @@ -18,18 +19,24 @@ class ApiDiscussionToolsPreview extends ApiBase { /** @var CommentParser */ private $commentParser; + /** @var SkinFactory */ + private $skinFactory; + /** * @param ApiMain $main * @param string $name * @param CommentParser $commentParser + * @param SkinFactory $skinFactory */ public function __construct( ApiMain $main, $name, - CommentParser $commentParser + CommentParser $commentParser, + SkinFactory $skinFactory ) { parent::__construct( $main, $name ); $this->commentParser = $commentParser; + $this->skinFactory = $skinFactory; } /** @@ -53,7 +60,8 @@ class ApiDiscussionToolsPreview extends ApiBase { [ 'wikitext' => $params['wikitext'], 'sectiontitle' => $params['sectiontitle'] - ] + ], + $params ); $resultHtml = $result->getResultData( [ 'parse', 'text' ] ); @@ -77,7 +85,8 @@ class ApiDiscussionToolsPreview extends ApiBase { 'wikitext' => $params['wikitext'], 'sectiontitle' => $params['sectiontitle'], 'signature' => $signature - ] + ], + $params ); } @@ -109,6 +118,10 @@ class ApiDiscussionToolsPreview extends ApiBase { ParamValidator::PARAM_TYPE => 'string', ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-sectiontitle', ], + 'useskin' => [ + ParamValidator::PARAM_TYPE => array_keys( $this->skinFactory->getInstalledSkins() ), + ApiBase::PARAM_HELP_MSG => 'apihelp-parse-param-useskin', + ], ]; } diff --git a/includes/ApiDiscussionToolsTrait.php b/includes/ApiDiscussionToolsTrait.php index 89a13ee7f..5402d0d0d 100644 --- a/includes/ApiDiscussionToolsTrait.php +++ b/includes/ApiDiscussionToolsTrait.php @@ -47,9 +47,12 @@ trait ApiDiscussionToolsTrait { * - `html` (string|null) Content of the message, mutually exclusive with `wikitext` * - `sectiontitle` (string) Content of the title, when `type` is 'topic' * - `signature` (string|null) Wikitext signature to add to the message + * @param array $originalParams Original params from the source API call * @return ApiResult action=parse API result */ - protected function previewMessage( string $type, Title $title, array $params ): ApiResult { + protected function previewMessage( + string $type, Title $title, array $params, array $originalParams = [] + ): ApiResult { $wikitext = $params['wikitext'] ?? null; $html = $params['html'] ?? null; $signature = $params['signature'] ?? null; @@ -106,6 +109,12 @@ trait ApiDiscussionToolsTrait { 'disableeditsection' => '1', 'prop' => 'text|modules|jsconfigvars', ]; + if ( isset( $originalParams['useskin'] ) ) { + $apiParams['useskin'] = $originalParams['useskin']; + } + if ( isset( $originalParams['mobileformat'] ) && $originalParams['mobileformat'] ) { + $apiParams['mobileformat'] = '1'; + } $context = new DerivativeContext( $this->getContext() ); $context->setRequest( diff --git a/modules/controller.js b/modules/controller.js index f01f9def5..c41402913 100644 --- a/modules/controller.js +++ b/modules/controller.js @@ -523,6 +523,7 @@ function refreshPageContents( oldId ) { // HACK: 'useskin' triggers a different code path that runs our OutputPageBeforeHTML hook, // adding our reply links in the HTML (T266195) useskin: mw.config.get( 'skin' ), + mobileformat: OO.ui.isMobile(), uselang: mw.config.get( 'wgUserLanguage' ), // HACK: Always display reply links afterwards, ignoring preferences etc., in case this was // a page view with reply links forced with ?dtenable=1 or otherwise diff --git a/modules/dt.ui.ReplyWidget.js b/modules/dt.ui.ReplyWidget.js index 362149857..1e4b8d2c8 100644 --- a/modules/dt.ui.ReplyWidget.js +++ b/modules/dt.ui.ReplyWidget.js @@ -735,7 +735,9 @@ ReplyWidget.prototype.preparePreview = function ( wikitext ) { type: this.isNewTopic ? 'topic' : 'reply', page: this.pageName, wikitext: wikitext, - sectiontitle: title + sectiontitle: title, + useskin: mw.config.get( 'skin' ), + mobileformat: OO.ui.isMobile() } ); }