mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-28 02:00:57 +00:00
Merge "Clean up ApiDiscussionToolsPageInfo hack"
This commit is contained in:
commit
6d52132754
|
@ -4,6 +4,7 @@ namespace MediaWiki\Extension\DiscussionTools;
|
|||
|
||||
use ApiBase;
|
||||
use ApiMain;
|
||||
use ApiUsageException;
|
||||
use MediaWiki\Extension\DiscussionTools\Hooks\HookUtils;
|
||||
use MediaWiki\Extension\DiscussionTools\ThreadItem\CommentItem;
|
||||
use MediaWiki\Extension\DiscussionTools\ThreadItem\ContentHeadingItem;
|
||||
|
@ -41,43 +42,7 @@ class ApiDiscussionToolsPageInfo extends ApiBase {
|
|||
public function execute() {
|
||||
$params = $this->extractRequestParams();
|
||||
$this->requireAtLeastOneParameter( $params, 'page', 'oldid' );
|
||||
|
||||
if ( isset( $params['page'] ) ) {
|
||||
$title = Title::newFromText( $params['page'] );
|
||||
if ( !$title ) {
|
||||
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ] );
|
||||
}
|
||||
if ( !HookUtils::isAvailableForTitle( $title ) ) {
|
||||
$this->getResult()->addValue(
|
||||
null,
|
||||
$this->getModuleName(),
|
||||
[ 'transcludedfrom' => [] ]
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $params['oldid'] ) ) {
|
||||
$revision = $this->revisionLookup->getRevisionById( $params['oldid'] );
|
||||
if ( !$revision ) {
|
||||
$this->dieWithError( [ 'apierror-nosuchrevid', $params['oldid'] ] );
|
||||
}
|
||||
|
||||
} else {
|
||||
$title = Title::newFromText( $params['page'] );
|
||||
if ( !$title ) {
|
||||
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ] );
|
||||
}
|
||||
$revision = $this->revisionLookup->getRevisionByTitle( $title );
|
||||
if ( !$revision ) {
|
||||
$this->dieWithError(
|
||||
[ 'apierror-missingrev-title', wfEscapeWikiText( $title->getPrefixedText() ) ],
|
||||
'nosuchrevid'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$threadItemSet = HookUtils::parseRevisionParsoidHtml( $revision );
|
||||
$threadItemSet = $this->getThreadItemSet( $params );
|
||||
|
||||
$result = [];
|
||||
$prop = array_fill_keys( $params['prop'], true );
|
||||
|
@ -93,6 +58,58 @@ class ApiDiscussionToolsPageInfo extends ApiBase {
|
|||
$this->getResult()->addValue( null, $this->getModuleName(), $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the thread item set for the specified revision
|
||||
*
|
||||
* @param array $params
|
||||
* @return ContentThreadItemSet
|
||||
*/
|
||||
private function getThreadItemSet( $params ) {
|
||||
if ( isset( $params['page'] ) ) {
|
||||
$title = Title::newFromText( $params['page'] );
|
||||
if ( !$title ) {
|
||||
throw ApiUsageException::newWithMessage(
|
||||
$this,
|
||||
[ 'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $params['oldid'] ) ) {
|
||||
$revision = $this->revisionLookup->getRevisionById( $params['oldid'] );
|
||||
if ( !$revision ) {
|
||||
throw ApiUsageException::newWithMessage(
|
||||
$this,
|
||||
[ 'apierror-nosuchrevid', $params['oldid'] ]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$title = Title::newFromText( $params['page'] );
|
||||
if ( !$title ) {
|
||||
throw ApiUsageException::newWithMessage(
|
||||
$this,
|
||||
[ 'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ]
|
||||
);
|
||||
}
|
||||
$revision = $this->revisionLookup->getRevisionByTitle( $title );
|
||||
if ( !$revision ) {
|
||||
throw ApiUsageException::newWithMessage(
|
||||
$this,
|
||||
[ 'apierror-missingrev-title', wfEscapeWikiText( $title->getPrefixedText() ) ],
|
||||
'nosuchrevid'
|
||||
);
|
||||
}
|
||||
}
|
||||
$title = Title::castFromPageIdentity( $revision->getPage() );
|
||||
|
||||
if ( !$title || !HookUtils::isAvailableForTitle( $title ) ) {
|
||||
// T325477: don't parse non-discussion pages
|
||||
return new ContentThreadItemSet;
|
||||
}
|
||||
|
||||
return HookUtils::parseRevisionParsoidHtml( $revision );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get transcluded=from data for a ContentThreadItemSet
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue