mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-23 16:06:53 +00:00
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:
parent
904f1c2f25
commit
639fabf647
|
@ -447,7 +447,8 @@
|
|||
"discussiontoolspreview": {
|
||||
"class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsPreview",
|
||||
"services": [
|
||||
"DiscussionTools.CommentParser"
|
||||
"DiscussionTools.CommentParser",
|
||||
"SkinFactory"
|
||||
]
|
||||
},
|
||||
"discussiontoolssubscribe": {
|
||||
|
|
|
@ -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 ) );
|
||||
|
|
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -524,6 +524,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
|
||||
|
|
|
@ -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()
|
||||
} );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue