mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-23 16:06:53 +00:00
Merge "ApiDiscussionToolsCompare: Deduplicate 'from'/'to' param handling"
This commit is contained in:
commit
af74638d08
|
@ -32,6 +32,32 @@ class ApiDiscussionToolsCompare extends ApiBase {
|
|||
$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
|
||||
* @throws ApiUsageException
|
||||
|
@ -42,25 +68,7 @@ class ApiDiscussionToolsCompare extends ApiBase {
|
|||
$this->requireOnlyOneParameter( $params, 'fromtitle', 'fromrev' );
|
||||
$this->requireOnlyOneParameter( $params, 'totitle', 'torev' );
|
||||
|
||||
if ( isset( $params['torev'] ) ) {
|
||||
$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'
|
||||
);
|
||||
}
|
||||
}
|
||||
$toRev = $this->getRevision( $params, 'to' );
|
||||
|
||||
// When polling for new comments this is an important optimisation,
|
||||
// as usually there is no new revision.
|
||||
|
@ -69,25 +77,7 @@ class ApiDiscussionToolsCompare extends ApiBase {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( isset( $params['fromrev'] ) ) {
|
||||
$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'
|
||||
);
|
||||
}
|
||||
}
|
||||
$fromRev = $this->getRevision( $params, 'from' );
|
||||
|
||||
if ( $fromRev->hasSameContent( $toRev ) ) {
|
||||
$this->addResult( $fromRev, $toRev );
|
||||
|
|
Loading…
Reference in a new issue