Pass useskin/mobileformat when previewing/refreshing page contents

These are required to render content correctly on mobile.

Change-Id: I421e1f172e208c4bf9d50eee68f1b0220a78dfbe
This commit is contained in:
Ed Sanders 2022-06-27 14:40:41 +01:00
parent 904f1c2f25
commit 639fabf647
6 changed files with 34 additions and 7 deletions

View file

@ -447,7 +447,8 @@
"discussiontoolspreview": { "discussiontoolspreview": {
"class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsPreview", "class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsPreview",
"services": [ "services": [
"DiscussionTools.CommentParser" "DiscussionTools.CommentParser",
"SkinFactory"
] ]
}, },
"discussiontoolssubscribe": { "discussiontoolssubscribe": {

View file

@ -85,7 +85,8 @@ class ApiDiscussionToolsEdit extends ApiBase {
'wikitext' => $params['wikitext'], 'wikitext' => $params['wikitext'],
'html' => $params['html'], 'html' => $params['html'],
'sectiontitle' => $params['sectiontitle'], 'sectiontitle' => $params['sectiontitle'],
] ],
$params
); );
$previewResultHtml = $previewResult->getResultData( [ 'parse', 'text' ] ); $previewResultHtml = $previewResult->getResultData( [ 'parse', 'text' ] );
$previewContainer = DOMCompat::getBody( DOMUtils::parseHTML( $previewResultHtml ) ); $previewContainer = DOMCompat::getBody( DOMUtils::parseHTML( $previewResultHtml ) );

View file

@ -5,6 +5,7 @@ namespace MediaWiki\Extension\DiscussionTools;
use ApiBase; use ApiBase;
use ApiMain; use ApiMain;
use MediaWiki\Extension\VisualEditor\ApiParsoidTrait; use MediaWiki\Extension\VisualEditor\ApiParsoidTrait;
use SkinFactory;
use Title; use Title;
use Wikimedia\ParamValidator\ParamValidator; use Wikimedia\ParamValidator\ParamValidator;
use Wikimedia\Parsoid\Utils\DOMCompat; use Wikimedia\Parsoid\Utils\DOMCompat;
@ -18,18 +19,24 @@ class ApiDiscussionToolsPreview extends ApiBase {
/** @var CommentParser */ /** @var CommentParser */
private $commentParser; private $commentParser;
/** @var SkinFactory */
private $skinFactory;
/** /**
* @param ApiMain $main * @param ApiMain $main
* @param string $name * @param string $name
* @param CommentParser $commentParser * @param CommentParser $commentParser
* @param SkinFactory $skinFactory
*/ */
public function __construct( public function __construct(
ApiMain $main, ApiMain $main,
$name, $name,
CommentParser $commentParser CommentParser $commentParser,
SkinFactory $skinFactory
) { ) {
parent::__construct( $main, $name ); parent::__construct( $main, $name );
$this->commentParser = $commentParser; $this->commentParser = $commentParser;
$this->skinFactory = $skinFactory;
} }
/** /**
@ -53,7 +60,8 @@ class ApiDiscussionToolsPreview extends ApiBase {
[ [
'wikitext' => $params['wikitext'], 'wikitext' => $params['wikitext'],
'sectiontitle' => $params['sectiontitle'] 'sectiontitle' => $params['sectiontitle']
] ],
$params
); );
$resultHtml = $result->getResultData( [ 'parse', 'text' ] ); $resultHtml = $result->getResultData( [ 'parse', 'text' ] );
@ -77,7 +85,8 @@ class ApiDiscussionToolsPreview extends ApiBase {
'wikitext' => $params['wikitext'], 'wikitext' => $params['wikitext'],
'sectiontitle' => $params['sectiontitle'], 'sectiontitle' => $params['sectiontitle'],
'signature' => $signature 'signature' => $signature
] ],
$params
); );
} }
@ -109,6 +118,10 @@ class ApiDiscussionToolsPreview extends ApiBase {
ParamValidator::PARAM_TYPE => 'string', ParamValidator::PARAM_TYPE => 'string',
ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-sectiontitle', 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',
],
]; ];
} }

View file

@ -47,9 +47,12 @@ trait ApiDiscussionToolsTrait {
* - `html` (string|null) Content of the message, mutually exclusive with `wikitext` * - `html` (string|null) Content of the message, mutually exclusive with `wikitext`
* - `sectiontitle` (string) Content of the title, when `type` is 'topic' * - `sectiontitle` (string) Content of the title, when `type` is 'topic'
* - `signature` (string|null) Wikitext signature to add to the message * - `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 * @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; $wikitext = $params['wikitext'] ?? null;
$html = $params['html'] ?? null; $html = $params['html'] ?? null;
$signature = $params['signature'] ?? null; $signature = $params['signature'] ?? null;
@ -106,6 +109,12 @@ trait ApiDiscussionToolsTrait {
'disableeditsection' => '1', 'disableeditsection' => '1',
'prop' => 'text|modules|jsconfigvars', '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 = new DerivativeContext( $this->getContext() );
$context->setRequest( $context->setRequest(

View file

@ -524,6 +524,7 @@ function refreshPageContents( oldId ) {
// HACK: 'useskin' triggers a different code path that runs our OutputPageBeforeHTML hook, // HACK: 'useskin' triggers a different code path that runs our OutputPageBeforeHTML hook,
// adding our reply links in the HTML (T266195) // adding our reply links in the HTML (T266195)
useskin: mw.config.get( 'skin' ), useskin: mw.config.get( 'skin' ),
mobileformat: OO.ui.isMobile(),
uselang: mw.config.get( 'wgUserLanguage' ), uselang: mw.config.get( 'wgUserLanguage' ),
// HACK: Always display reply links afterwards, ignoring preferences etc., in case this was // 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 // a page view with reply links forced with ?dtenable=1 or otherwise

View file

@ -735,7 +735,9 @@ ReplyWidget.prototype.preparePreview = function ( wikitext ) {
type: this.isNewTopic ? 'topic' : 'reply', type: this.isNewTopic ? 'topic' : 'reply',
page: this.pageName, page: this.pageName,
wikitext: wikitext, wikitext: wikitext,
sectiontitle: title sectiontitle: title,
useskin: mw.config.get( 'skin' ),
mobileformat: OO.ui.isMobile()
} ); } );
} }