Currently, [[ https://www.mediawiki.org/wiki/API:Compare#Relative_comparison_at_first_and_last_revision | relative comparison at first and last revision ]] in the API has behaviour that is defined but conceptually inconsistent. @Anomie has proposed that we change the behaviour to be more consistent with the conceptual model of a series of revisions, as well as the behaviour of the Web UI.
One mechanism for making this change would be an interim step where a deprecation warning is given in the "warnings" property of the results. After this, the result would be a baddiff error as in https://phabricator.wikimedia.org/T203433.
----
Reasons for doing this include:
* Consistency with all other cases where a specified revision does not exist or is inaccessible, such as
** Specification of a page that does not exist.
** Specification of a revision ID that does not exist.
** Specification of a deleted revision, when the user lacks the necessary rights to view it.
** Specification of a revision with hidden or suppressed content ([[https://www.mediawiki.org/wiki/Help:RevisionDelete|RevDel]]), when the user lacks the necessary rights to view it.
** Attempting to use `torelative=prev` or `torelative=next` relative to a deleted revision, where it's unclear whether that should be the previous/next deleted revision, the previous/next live revision by timestamp, or the previous/next revision by timestamp regardless of whether it's live or deleted.
** Attempting to use `torelative=cur` with a revision from a deleted page.
* Removing an inconsistency in non-error behavior with the web UI, which displays "no differences" rather than a diff from an empty revision for the previous-to-first case.
* Avoiding the fact that an empty revision for the previous-to-first case is not correct when a page has default content, as for example is the case for messages in the MediaWiki namespace.
** For example, the first real edit to enwiki's MediaWiki:Protectedpagetext was [[https://en.wikipedia.org/w/index.php?diff=1906920&oldid=1900533|this diff]]. Absent that "MediaWiki default" revision, we'd have no way of knowing that that was the default content of the page at the time the edit was made.
Clients currently requesting such comparisons would have a few options, including
* Use prior knowledge that the revision in question is the first/last, and avoid making the call to `action=compare`.
* Check whether the from-revision has a previous or next revision, e.g. with `action=query&prop=revisions&rvstartid=X&rvlimit=2`, and avoid making the call to `action=compare`.
* Make the request to `action=compare` and handle the error, analogous to pseudocode code like
``` lang=php
try {
$result = $api->compareToPrevious( $rev );
} catch ( NoPreviousRevisionException $ex ) {
/* Populate $result in some other way */
}
```
Also note that, at least for the case of a wikitext page, you can safely get a diff from an empty revision by using the `fromslots` and `fromtext-main` parameters, as for example https://en.wikipedia.org/w/api.php?action=compare&torev=1906920&fromslots=main&fromtext-main=.