mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-18 02:51:26 +00:00
aa03dc971e
For two given revisions, this API tells us which comments have been added and which have been removed. Can be used to highlight new comments, or check if the page has been updated since we first loaded it. Bug: T281624 Bug: T300504 Change-Id: Ia4d95ffe3b7cf2317cd8e7c0f034e09f64777ef3
102 lines
2.1 KiB
PHP
102 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools;
|
|
|
|
use ApiBase;
|
|
use ApiMain;
|
|
use ApiParsoidTrait;
|
|
use Title;
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
|
|
|
class ApiDiscussionToolsPageInfo extends ApiBase {
|
|
|
|
use ApiDiscussionToolsTrait;
|
|
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'] ) ] );
|
|
}
|
|
|
|
$revision = $this->getValidRevision( $title, $params['oldid'] ?? null );
|
|
$parser = $this->parseRevision( $revision );
|
|
$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;
|
|
}
|
|
}
|