Merge "Pass useskin/mobileformat when previewing/refreshing page contents"

This commit is contained in:
jenkins-bot 2022-06-27 21:57:02 +00:00 committed by Gerrit Code Review
commit cd86854235
6 changed files with 34 additions and 7 deletions

View file

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

View file

@ -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 ) );

View file

@ -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',
],
];
}

View file

@ -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(

View file

@ -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

View file

@ -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()
} );
}