mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 17:51:09 +00:00
ApiDiscussionToolsCompare: Deduplicate 'from'/'to' param handling
Change-Id: I0351228f50e9ea5a599d11b37f684b8e66553a83
This commit is contained in:
parent
1130ab2491
commit
f3e96a72fa
|
@ -32,6 +32,32 @@ class ApiDiscussionToolsCompare extends ApiBase {
|
||||||
$this->revisionLookup = $revisionLookup;
|
$this->revisionLookup = $revisionLookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ApiUsageException
|
||||||
|
*/
|
||||||
|
private function getRevision( array $params, string $prefix ): RevisionRecord {
|
||||||
|
if ( isset( $params["{$prefix}rev"] ) ) {
|
||||||
|
$rev = $this->revisionLookup->getRevisionById( $params["{$prefix}rev"] );
|
||||||
|
if ( !$rev ) {
|
||||||
|
$this->dieWithError( [ 'apierror-nosuchrevid', $params["{$prefix}rev"] ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$title = Title::newFromText( $params["{$prefix}title"] );
|
||||||
|
if ( !$title ) {
|
||||||
|
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params["{$prefix}title"] ) ] );
|
||||||
|
}
|
||||||
|
$rev = $this->revisionLookup->getRevisionByTitle( $title );
|
||||||
|
if ( !$rev ) {
|
||||||
|
$this->dieWithError(
|
||||||
|
[ 'apierror-missingrev-title', wfEscapeWikiText( $title->getPrefixedText() ) ],
|
||||||
|
'nosuchrevid'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $rev;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
* @throws ApiUsageException
|
* @throws ApiUsageException
|
||||||
|
@ -42,25 +68,7 @@ class ApiDiscussionToolsCompare extends ApiBase {
|
||||||
$this->requireOnlyOneParameter( $params, 'fromtitle', 'fromrev' );
|
$this->requireOnlyOneParameter( $params, 'fromtitle', 'fromrev' );
|
||||||
$this->requireOnlyOneParameter( $params, 'totitle', 'torev' );
|
$this->requireOnlyOneParameter( $params, 'totitle', 'torev' );
|
||||||
|
|
||||||
if ( isset( $params['torev'] ) ) {
|
$toRev = $this->getRevision( $params, 'to' );
|
||||||
$toRev = $this->revisionLookup->getRevisionById( $params['torev'] );
|
|
||||||
if ( !$toRev ) {
|
|
||||||
$this->dieWithError( [ 'apierror-nosuchrevid', $params['torev'] ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$toTitle = Title::newFromText( $params['totitle'] );
|
|
||||||
if ( !$toTitle ) {
|
|
||||||
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['totitle'] ) ] );
|
|
||||||
}
|
|
||||||
$toRev = $this->revisionLookup->getRevisionByTitle( $toTitle );
|
|
||||||
if ( !$toRev ) {
|
|
||||||
$this->dieWithError(
|
|
||||||
[ 'apierror-missingrev-title', wfEscapeWikiText( $toTitle->getPrefixedText() ) ],
|
|
||||||
'nosuchrevid'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// When polling for new comments this is an important optimisation,
|
// When polling for new comments this is an important optimisation,
|
||||||
// as usually there is no new revision.
|
// as usually there is no new revision.
|
||||||
|
@ -69,25 +77,7 @@ class ApiDiscussionToolsCompare extends ApiBase {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $params['fromrev'] ) ) {
|
$fromRev = $this->getRevision( $params, 'from' );
|
||||||
$fromRev = $this->revisionLookup->getRevisionById( $params['fromrev'] );
|
|
||||||
if ( !$fromRev ) {
|
|
||||||
$this->dieWithError( [ 'apierror-nosuchrevid', $params['fromrev'] ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$fromTitle = Title::newFromText( $params['fromtitle'] );
|
|
||||||
if ( !$fromTitle ) {
|
|
||||||
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['fromtitle'] ) ] );
|
|
||||||
}
|
|
||||||
$fromRev = $this->revisionLookup->getRevisionByTitle( $fromTitle );
|
|
||||||
if ( !$fromRev ) {
|
|
||||||
$this->dieWithError(
|
|
||||||
[ 'apierror-missingrev-title', wfEscapeWikiText( $fromTitle->getPrefixedText() ) ],
|
|
||||||
'nosuchrevid'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $fromRev->hasSameContent( $toRev ) ) {
|
if ( $fromRev->hasSameContent( $toRev ) ) {
|
||||||
$this->addResult( $fromRev, $toRev );
|
$this->addResult( $fromRev, $toRev );
|
||||||
|
|
Loading…
Reference in a new issue