mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 17:51:09 +00:00
Merge "ApiDiscussionToolsPageInfo: Allow excluding signatures"
This commit is contained in:
commit
7b147cffbf
|
@ -24,6 +24,7 @@
|
|||
"apihelp-discussiontoolsgetsubscriptions-summary": "Get the subscription statuses of given topics.",
|
||||
"apihelp-discussiontoolspageinfo-param-oldid": "The revision number to use (defaults to latest revision).",
|
||||
"apihelp-discussiontoolspageinfo-param-prop": "Which properties to get:",
|
||||
"apihelp-discussiontoolspageinfo-param-excludesignatures": "Exclude user signatures from the comments (when using <var>prop=threaditemshtml</var>).",
|
||||
"apihelp-discussiontoolspageinfo-paramvalue-prop-threaditemshtml": "Representation of the comment threads parsed from the page",
|
||||
"apihelp-discussiontoolspageinfo-paramvalue-prop-transcludedfrom": "Which other pages comments have been transcluded from",
|
||||
"apihelp-discussiontoolspageinfo-summary": "Returns metadata required to initialize the discussion tools.",
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
"apihelp-discussiontoolsgetsubscriptions-summary": "{{doc-apihelp-summary|discussiontoolsgetsubscriptions}}",
|
||||
"apihelp-discussiontoolspageinfo-param-oldid": "{{doc-apihelp-param|discussiontoolspageinfo|oldid}}",
|
||||
"apihelp-discussiontoolspageinfo-param-prop": "{{doc-apihelp-param|discussiontoolspageinfo|prop}}",
|
||||
"apihelp-discussiontoolspageinfo-param-excludesignatures": "{{doc-apihelp-param|discussiontoolspageinfo|excludesignatures}}",
|
||||
"apihelp-discussiontoolspageinfo-paramvalue-prop-threaditemshtml": "{{doc-apihelp-paramvalue|discussiontoolspageinfo|prop|threaditemshtml}}",
|
||||
"apihelp-discussiontoolspageinfo-paramvalue-prop-transcludedfrom": "{{doc-apihelp-paramvalue|discussiontoolspageinfo|prop|transcludedfrom}}",
|
||||
"apihelp-discussiontoolspageinfo-summary": "{{doc-apihelp-summary|discussiontoolspageinfo}}",
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
"discussiontools-defaultsummary-reply": "Reply",
|
||||
"discussiontoolsdebug-title": "Discussion tools data structure",
|
||||
"discussiontoolsdebug-pagetitle": "Page title",
|
||||
"discussiontoolsdebug-intro": "This page demonstrates how the [https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:DiscussionTools DiscussionTools extension] recognizes the threads and comments present on the page '''[[:$1]]'''. You may find it useful in debugging issues with the extension or understanding how it works. The same information is available in the [[Special:ApiSandbox#action=discussiontoolspageinfo&prop=threaditemshtml&page=$1|discussiontoolspageinfo API]].",
|
||||
"discussiontoolsdebug-intro": "This page demonstrates how the [https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:DiscussionTools DiscussionTools extension] recognizes the threads and comments present on the page '''[[:$1]]'''. You may find it useful in debugging issues with the extension or understanding how it works. The same information is available in the [[$2|discussiontoolspageinfo API]].",
|
||||
"discussiontools-desc": "Tools to enhance discussion pages.",
|
||||
"discussiontools-emptystate-button": "Start a discussion",
|
||||
"discussiontools-emptystate-desc": "[[{{MediaWiki:discussiontools-emptystate-link-talkpages}}|Talk pages]] are where people discuss how to make content on {{SITENAME}} the best that it can be. {{GENDER:|You}} can use this page to start a discussion with others about how to improve [[:{{SUBJECTPAGENAME}}]].",
|
||||
|
|
|
@ -7,6 +7,7 @@ use ApiMain;
|
|||
use ApiUsageException;
|
||||
use MediaWiki\Extension\DiscussionTools\Hooks\HookUtils;
|
||||
use MediaWiki\Extension\DiscussionTools\ThreadItem\CommentItem;
|
||||
use MediaWiki\Extension\DiscussionTools\ThreadItem\ContentCommentItem;
|
||||
use MediaWiki\Extension\DiscussionTools\ThreadItem\ContentHeadingItem;
|
||||
use MediaWiki\Extension\DiscussionTools\ThreadItem\ContentThreadItem;
|
||||
use MediaWiki\Extension\VisualEditor\VisualEditorParsoidClientFactory;
|
||||
|
@ -53,7 +54,8 @@ class ApiDiscussionToolsPageInfo extends ApiBase {
|
|||
}
|
||||
|
||||
if ( isset( $prop['threaditemshtml'] ) ) {
|
||||
$result['threaditemshtml'] = static::getThreadItemsHtml( $threadItemSet );
|
||||
$excludeSignatures = $params['excludesignatures'];
|
||||
$result['threaditemshtml'] = static::getThreadItemsHtml( $threadItemSet, $excludeSignatures );
|
||||
}
|
||||
|
||||
$this->getResult()->addValue( null, $this->getModuleName(), $result );
|
||||
|
@ -145,9 +147,10 @@ class ApiDiscussionToolsPageInfo extends ApiBase {
|
|||
* Get thread items HTML for a ContentThreadItemSet
|
||||
*
|
||||
* @param ContentThreadItemSet $threadItemSet
|
||||
* @param bool $excludeSignatures
|
||||
* @return array
|
||||
*/
|
||||
private static function getThreadItemsHtml( ContentThreadItemSet $threadItemSet ): array {
|
||||
private static function getThreadItemsHtml( ContentThreadItemSet $threadItemSet, bool $excludeSignatures ): array {
|
||||
// This function assumes that the start of the ranges associated with
|
||||
// HeadingItems are going to be at the start of their associated
|
||||
// heading node (`<h2>^heading</h2>`), i.e. in the position generated
|
||||
|
@ -172,9 +175,16 @@ class ApiDiscussionToolsPageInfo extends ApiBase {
|
|||
array_unshift( $threads, $fakeHeading );
|
||||
}
|
||||
}
|
||||
$output = array_map( static function ( ContentThreadItem $item ) {
|
||||
return $item->jsonSerialize( true, static function ( array &$array, ContentThreadItem $item ) {
|
||||
$array['html'] = $item->getHtml();
|
||||
$output = array_map( static function ( ContentThreadItem $item ) use ( $excludeSignatures ) {
|
||||
return $item->jsonSerialize( true, static function ( array &$array, ContentThreadItem $item ) use (
|
||||
$excludeSignatures
|
||||
) {
|
||||
if ( $item instanceof ContentCommentItem && $excludeSignatures ) {
|
||||
$array['html'] = $item->getBodyHTML( true );
|
||||
} else {
|
||||
$array['html'] = $item->getHTML();
|
||||
}
|
||||
|
||||
if ( $item instanceof CommentItem ) {
|
||||
// We want timestamps to be consistently formatted in API
|
||||
// output instead of varying based on comment time
|
||||
|
@ -279,6 +289,7 @@ class ApiDiscussionToolsPageInfo extends ApiBase {
|
|||
],
|
||||
ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
|
||||
],
|
||||
'excludesignatures' => false,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use MediaWiki\Linker\Linker;
|
|||
use MediaWiki\Page\ParserOutputAccess;
|
||||
use MWTimestamp;
|
||||
use ParserOptions;
|
||||
use SpecialPage;
|
||||
use Title;
|
||||
use Wikimedia\Assert\Assert;
|
||||
use Wikimedia\Parsoid\Utils\DOMCompat;
|
||||
|
@ -95,7 +96,16 @@ class SpecialDiscussionToolsDebug extends FormSpecialPage {
|
|||
|
||||
$out = $this->getOutput();
|
||||
|
||||
$out->addHTML( $this->msg( 'discussiontoolsdebug-intro', $title->getPrefixedText() )->parseAsBlock() );
|
||||
$out->addHTML( $this->msg(
|
||||
'discussiontoolsdebug-intro',
|
||||
$title->getPrefixedText(),
|
||||
SpecialPage::getTitleFor(
|
||||
'ApiSandbox',
|
||||
false,
|
||||
'action=discussiontoolspageinfo&prop=threaditemshtml&excludesignatures=1&page='
|
||||
. urlencode( $title->getPrefixedText() )
|
||||
)->getFullText()
|
||||
)->parseAsBlock() );
|
||||
|
||||
$pageLang = $title->getPageViewLanguage();
|
||||
$pageLangAttribs = [
|
||||
|
@ -138,7 +148,7 @@ class SpecialDiscussionToolsDebug extends FormSpecialPage {
|
|||
'</span>' .
|
||||
'</span>' .
|
||||
Html::rawElement( 'div', $pageLangAttribs,
|
||||
'<div class="mw-dt-comment-body mw-parser-output">' . $comment->getBodyHtml( true ) . '</div>'
|
||||
'<div class="mw-dt-comment-body mw-parser-output">' . $comment->getBodyHTML( true ) . '</div>'
|
||||
);
|
||||
}
|
||||
$level = $comment->getLevel();
|
||||
|
|
|
@ -60,7 +60,7 @@ class ApiDiscussionToolsPageInfoTest extends ApiTestCase {
|
|||
|
||||
$pageInfo = TestingAccessWrapper::newFromClass( ApiDiscussionToolsPageInfo::class );
|
||||
|
||||
$threadItemsHtml = $pageInfo->getThreadItemsHtml( $threadItemSet );
|
||||
$threadItemsHtml = $pageInfo->getThreadItemsHtml( $threadItemSet, false );
|
||||
|
||||
// Optionally write updated content to the JSON files
|
||||
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
|
||||
|
|
Loading…
Reference in a new issue