mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 17:51:09 +00:00
Move ApiDiscussionTools to ApiDiscussionToolsPageInfo
Also remove 'paction' param, and instead make 'transcludedFrom' a property of the result object. Change-Id: I0a289f6d71e4708afff0b52066b1ed6faf76b9ae
This commit is contained in:
parent
ee2749d34a
commit
7cad692afa
|
@ -404,9 +404,6 @@
|
|||
"MediaWiki\\Extension\\DiscussionTools\\Tests\\": "tests/phpunit/"
|
||||
},
|
||||
"APIModules": {
|
||||
"discussiontools": {
|
||||
"class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionTools"
|
||||
},
|
||||
"discussiontoolsedit": {
|
||||
"class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsEdit"
|
||||
},
|
||||
|
@ -417,6 +414,9 @@
|
|||
"ConfigFactory"
|
||||
]
|
||||
},
|
||||
"discussiontoolspageinfo": {
|
||||
"class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsPageInfo"
|
||||
},
|
||||
"discussiontoolssubscribe": {
|
||||
"class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsSubscribe",
|
||||
"services": [
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
"apierror-discussiontools-formtoken-used": "Comment already posted. Reload the page to see it.",
|
||||
"apierror-discussiontools-subscription-failed-add": "Could not subscribe to this topic.",
|
||||
"apierror-discussiontools-subscription-failed-remove": "Could not unsubscribe from this topic.",
|
||||
"apihelp-discussiontools-param-oldid": "The revision number to use (defaults to latest revision).",
|
||||
"apihelp-discussiontools-paramvalue-paction-transcludedfrom": "Return titles of pages from which each comment on the given page is transcluded.",
|
||||
"apihelp-discussiontools-summary": "Returns metadata required to initialize the discussion tools.",
|
||||
"apihelp-discussiontoolsedit-param-commentid": "ID of the comment to reply to. Only used when <var>paction</var> is <var>addcomment</var>. Overrides <var>commentname</var>.",
|
||||
"apihelp-discussiontoolsedit-param-commentname": "Name of the comment to reply to. Only used when <var>paction</var> is <var>addcomment</var>.",
|
||||
"apihelp-discussiontoolsedit-param-formtoken": "An optional unique ID generated in the client to prevent double-posting.",
|
||||
|
@ -22,6 +19,8 @@
|
|||
"apihelp-discussiontoolsedit-summary": "Post a message on a discussion page.",
|
||||
"apihelp-discussiontoolsgetsubscriptions-param-commentname": "Names of the topics to check",
|
||||
"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-summary": "Returns metadata required to initialize the discussion tools.",
|
||||
"apihelp-discussiontoolssubscribe-param-commentname": "Name of the topic to subscribe to (or unsubscribe from)",
|
||||
"apihelp-discussiontoolssubscribe-param-page": "A page on which the topic appears",
|
||||
"apihelp-discussiontoolssubscribe-param-subscribe": "True to subscribe, false to unsubscribe",
|
||||
|
|
|
@ -10,9 +10,6 @@
|
|||
"apierror-discussiontools-formtoken-used": "{{doc-apierror}}",
|
||||
"apierror-discussiontools-subscription-failed-add": "{{doc-apierror}}",
|
||||
"apierror-discussiontools-subscription-failed-remove": "{{doc-apierror}}",
|
||||
"apihelp-discussiontools-param-oldid": "{{doc-apihelp-param|discussiontools|oldid}}",
|
||||
"apihelp-discussiontools-paramvalue-paction-transcludedfrom": "{{doc-apihelp-paramvalue|discussiontools|paction|transcludedfrom}}",
|
||||
"apihelp-discussiontools-summary": "{{doc-apihelp-summary|discussiontools}}",
|
||||
"apihelp-discussiontoolsedit-param-commentid": "{{doc-apihelp-param|discussiontoolsedit|commentid}}",
|
||||
"apihelp-discussiontoolsedit-param-commentname": "{{doc-apihelp-param|discussiontoolsedit|commentname}}",
|
||||
"apihelp-discussiontoolsedit-param-formtoken": "{{doc-apihelp-param|discussiontoolsedit|formtoken}}",
|
||||
|
@ -24,6 +21,8 @@
|
|||
"apihelp-discussiontoolsedit-summary": "{{doc-apihelp-summary|discussiontoolsedit}}",
|
||||
"apihelp-discussiontoolsgetsubscriptions-param-commentname": "{{doc-apihelp-param|discussiontoolsgetsubscriptions|commentname}}",
|
||||
"apihelp-discussiontoolsgetsubscriptions-summary": "{{doc-apihelp-summary|discussiontoolsgetsubscriptions}}",
|
||||
"apihelp-discussiontoolspageinfo-param-oldid": "{{doc-apihelp-param|discussiontoolspageinfo|oldid}}",
|
||||
"apihelp-discussiontoolspageinfo-summary": "{{doc-apihelp-summary|discussiontoolspageinfo}}",
|
||||
"apihelp-discussiontoolssubscribe-param-commentname": "{{doc-apihelp-param|discussiontoolssubscribe|commentname}}",
|
||||
"apihelp-discussiontoolssubscribe-param-page": "{{doc-apihelp-param|discussiontoolssubscribe|page}}",
|
||||
"apihelp-discussiontoolssubscribe-param-subscribe": "{{doc-apihelp-param|discussiontoolssubscribe|subscribe}}",
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\DiscussionTools;
|
||||
|
||||
use ApiBase;
|
||||
use ApiMain;
|
||||
use ApiParsoidTrait;
|
||||
use Title;
|
||||
use Wikimedia\ParamValidator\ParamValidator;
|
||||
use Wikimedia\Parsoid\Utils\DOMCompat;
|
||||
use Wikimedia\Parsoid\Utils\DOMUtils;
|
||||
|
||||
class ApiDiscussionTools extends ApiBase {
|
||||
|
||||
use ApiParsoidTrait;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct( ApiMain $main, string $name ) {
|
||||
parent::__construct( $main, $name );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute() {
|
||||
$params = $this->extractRequestParams();
|
||||
$title = Title::newFromText( $params['page'] );
|
||||
$result = null;
|
||||
|
||||
if ( !$title ) {
|
||||
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ] );
|
||||
}
|
||||
|
||||
switch ( $params['paction'] ) {
|
||||
case 'transcludedfrom':
|
||||
$response = $this->requestRestbasePageHtml(
|
||||
$this->getValidRevision( $title, $params['oldid'] ?? null )
|
||||
);
|
||||
|
||||
$doc = DOMUtils::parseHTML( $response['body'] );
|
||||
$container = DOMCompat::getBody( $doc );
|
||||
|
||||
CommentUtils::unwrapParsoidSections( $container );
|
||||
|
||||
$parser = CommentParser::newFromGlobalState( $container, $title );
|
||||
$threadItems = $parser->getThreadItems();
|
||||
|
||||
$transcludedFrom = [];
|
||||
foreach ( $threadItems as $threadItem ) {
|
||||
$from = $threadItem->getTranscludedFrom();
|
||||
|
||||
// Key by IDs, legacy IDs, and names. This assumes that they can never conflict.
|
||||
|
||||
$transcludedFrom[ $threadItem->getId() ] = $from;
|
||||
|
||||
$legacyId = $threadItem->getLegacyId();
|
||||
if ( $legacyId ) {
|
||||
$transcludedFrom[ $legacyId ] = $from;
|
||||
}
|
||||
|
||||
$name = $threadItem->getName();
|
||||
if ( isset( $transcludedFrom[ $name ] ) && $transcludedFrom[ $name ] !== $from ) {
|
||||
// Two or more items with the same name, transcluded from different pages.
|
||||
// Consider them both to be transcluded from unknown source.
|
||||
$transcludedFrom[ $name ] = true;
|
||||
} else {
|
||||
$transcludedFrom[ $name ] = $from;
|
||||
}
|
||||
}
|
||||
|
||||
$result = $transcludedFrom;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->getResult()->addValue( null, $this->getModuleName(), $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getAllowedParams() {
|
||||
return [
|
||||
'paction' => [
|
||||
ParamValidator::PARAM_REQUIRED => true,
|
||||
ParamValidator::PARAM_TYPE => [
|
||||
'transcludedfrom',
|
||||
],
|
||||
ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-paction',
|
||||
ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
|
||||
],
|
||||
'page' => [
|
||||
ParamValidator::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-page',
|
||||
],
|
||||
'oldid' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function needsToken() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isInternal() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isWriteMode() {
|
||||
return false;
|
||||
}
|
||||
}
|
110
includes/ApiDiscussionToolsPageInfo.php
Normal file
110
includes/ApiDiscussionToolsPageInfo.php
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\DiscussionTools;
|
||||
|
||||
use ApiBase;
|
||||
use ApiMain;
|
||||
use ApiParsoidTrait;
|
||||
use Title;
|
||||
use Wikimedia\ParamValidator\ParamValidator;
|
||||
use Wikimedia\Parsoid\Utils\DOMCompat;
|
||||
use Wikimedia\Parsoid\Utils\DOMUtils;
|
||||
|
||||
class ApiDiscussionToolsPageInfo extends ApiBase {
|
||||
|
||||
use ApiParsoidTrait;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct( ApiMain $main, string $name ) {
|
||||
parent::__construct( $main, $name );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute() {
|
||||
$params = $this->extractRequestParams();
|
||||
$title = Title::newFromText( $params['page'] );
|
||||
|
||||
if ( !$title ) {
|
||||
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ] );
|
||||
}
|
||||
|
||||
$response = $this->requestRestbasePageHtml(
|
||||
$this->getValidRevision( $title, $params['oldid'] ?? null )
|
||||
);
|
||||
|
||||
$doc = DOMUtils::parseHTML( $response['body'] );
|
||||
$container = DOMCompat::getBody( $doc );
|
||||
|
||||
CommentUtils::unwrapParsoidSections( $container );
|
||||
|
||||
$parser = CommentParser::newFromGlobalState( $container, $title );
|
||||
$threadItems = $parser->getThreadItems();
|
||||
|
||||
$transcludedFrom = [];
|
||||
foreach ( $threadItems as $threadItem ) {
|
||||
$from = $threadItem->getTranscludedFrom();
|
||||
|
||||
// Key by IDs, legacy IDs, and names. This assumes that they can never conflict.
|
||||
|
||||
$transcludedFrom[ $threadItem->getId() ] = $from;
|
||||
|
||||
$legacyId = $threadItem->getLegacyId();
|
||||
if ( $legacyId ) {
|
||||
$transcludedFrom[ $legacyId ] = $from;
|
||||
}
|
||||
|
||||
$name = $threadItem->getName();
|
||||
if ( isset( $transcludedFrom[ $name ] ) && $transcludedFrom[ $name ] !== $from ) {
|
||||
// Two or more items with the same name, transcluded from different pages.
|
||||
// Consider them both to be transcluded from unknown source.
|
||||
$transcludedFrom[ $name ] = true;
|
||||
} else {
|
||||
$transcludedFrom[ $name ] = $from;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
'transcludedfrom' => $transcludedFrom
|
||||
];
|
||||
|
||||
$this->getResult()->addValue( null, $this->getModuleName(), $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getAllowedParams() {
|
||||
return [
|
||||
'page' => [
|
||||
ParamValidator::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-page',
|
||||
],
|
||||
'oldid' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function needsToken() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isInternal() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isWriteMode() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -101,12 +101,11 @@ function getPageData( pageName, oldId, isNewTopic ) {
|
|||
} );
|
||||
|
||||
transcludedFromPromise = api.get( {
|
||||
action: 'discussiontools',
|
||||
paction: 'transcludedfrom',
|
||||
action: 'discussiontoolspageinfo',
|
||||
page: pageName,
|
||||
oldid: oldId
|
||||
} ).then( function ( response ) {
|
||||
return OO.getProp( response, 'discussiontools' ) || {};
|
||||
return OO.getProp( response, 'discussiontoolspageinfo', 'transcludedfrom' ) || {};
|
||||
} );
|
||||
} else {
|
||||
lintPromise = $.Deferred().resolve( [] ).promise();
|
||||
|
|
Loading…
Reference in a new issue