Merge "ApiComparePages: Don't try to find next/prev of a deleted revision"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 6 Dec 2018 18:19:39 +0000 (18:19 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 6 Dec 2018 18:19:39 +0000 (18:19 +0000)
1  2 
includes/api/ApiComparePages.php
includes/api/i18n/en.json
includes/api/i18n/qqq.json

@@@ -22,6 -22,7 +22,7 @@@
  use MediaWiki\MediaWikiServices;
  use MediaWiki\Revision\MutableRevisionRecord;
  use MediaWiki\Revision\RevisionRecord;
+ use MediaWiki\Revision\RevisionArchiveRecord;
  use MediaWiki\Revision\RevisionStore;
  use MediaWiki\Revision\SlotRecord;
  
@@@ -30,15 -31,11 +31,15 @@@ class ApiComparePages extends ApiBase 
        /** @var RevisionStore */
        private $revisionStore;
  
 +      /** @var \MediaWiki\Revision\SlotRoleRegistry */
 +      private $slotRoleRegistry;
 +
        private $guessedTitle = false, $props;
  
        public function __construct( ApiMain $mainModule, $moduleName, $modulePrefix = '' ) {
                parent::__construct( $mainModule, $moduleName, $modulePrefix );
                $this->revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
 +              $this->slotRoleRegistry = MediaWikiServices::getInstance()->getSlotRoleRegistry();
        }
  
        public function execute() {
                        if ( !$fromRelRev ) {
                                $this->dieWithError( 'apierror-compare-relative-to-nothing' );
                        }
+                       if ( $params['torelative'] !== 'cur' && $fromRelRev instanceof RevisionArchiveRecord ) {
+                               // RevisionStore's getPreviousRevision/getNextRevision blow up
+                               // when passed an RevisionArchiveRecord for a deleted page
+                               $this->dieWithError( [ 'apierror-compare-relative-to-deleted', $params['torelative'] ] );
+                       }
                        switch ( $params['torelative'] ) {
                                case 'prev':
                                        // Swap 'from' and 'to'
                }
  
                $guessedTitle = $this->guessTitle();
 -              if ( $guessedTitle && $role === SlotRecord::MAIN ) {
 -                      // @todo: Use SlotRoleRegistry and do this for all slots
 -                      return $guessedTitle->getContentModel();
 +              if ( $guessedTitle ) {
 +                      return $this->slotRoleRegistry->getRoleHandler( $role )->getDefaultModel( $guessedTitle );
                }
  
                if ( isset( $params["fromcontentmodel-$role"] ) ) {
        }
  
        public function getAllowedParams() {
 -              $slotRoles = MediaWikiServices::getInstance()->getSlotRoleStore()->getMap();
 -              if ( !in_array( SlotRecord::MAIN, $slotRoles, true ) ) {
 -                      $slotRoles[] = SlotRecord::MAIN;
 -              }
 +              $slotRoles = $this->slotRoleRegistry->getKnownRoles();
                sort( $slotRoles, SORT_STRING );
  
                // Parameters for the 'from' and 'to' content
        "apihelp-json-param-callback": "If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.",
        "apihelp-json-param-utf8": "If specified, encodes most (but not all) non-ASCII characters as UTF-8 instead of replacing them with hexadecimal escape sequences. Default when <var>formatversion</var> is not <kbd>1</kbd>.",
        "apihelp-json-param-ascii": "If specified, encodes all non-ASCII using hexadecimal escape sequences. Default when <var>formatversion</var> is <kbd>1</kbd>.",
 -      "apihelp-json-param-formatversion": "Output formatting:\n;1:Backwards-compatible format (XML-style booleans, <samp>*</samp> keys for content nodes, etc.).\n;2:Experimental modern format. Details may change!\n;latest:Use the latest format (currently <kbd>2</kbd>), may change without warning.",
 +      "apihelp-json-param-formatversion": "Output formatting:\n;1:Backwards-compatible format (XML-style booleans, <samp>*</samp> keys for content nodes, etc.).\n;2:Modern format.\n;latest:Use the latest format (currently <kbd>2</kbd>), may change without warning.",
        "apihelp-jsonfm-summary": "Output data in JSON format (pretty-print in HTML).",
        "apihelp-none-summary": "Output nothing.",
        "apihelp-php-summary": "Output data in serialized PHP format.",
 -      "apihelp-php-param-formatversion": "Output formatting:\n;1:Backwards-compatible format (XML-style booleans, <samp>*</samp> keys for content nodes, etc.).\n;2:Experimental modern format. Details may change!\n;latest:Use the latest format (currently <kbd>2</kbd>), may change without warning.",
 +      "apihelp-php-param-formatversion": "Output formatting:\n;1:Backwards-compatible format (XML-style booleans, <samp>*</samp> keys for content nodes, etc.).\n;2:Modern format.\n;latest:Use the latest format (currently <kbd>2</kbd>), may change without warning.",
        "apihelp-phpfm-summary": "Output data in serialized PHP format (pretty-print in HTML).",
        "apihelp-rawfm-summary": "Output data, including debugging elements, in JSON format (pretty-print in HTML).",
        "apihelp-xml-summary": "Output data in XML format.",
        "apierror-compare-nofromrevision": "No 'from' revision. Specify <var>fromrev</var>, <var>fromtitle</var>, or <var>fromid</var>.",
        "apierror-compare-notext": "Parameter <var>$1</var> cannot be used without <var>$2</var>.",
        "apierror-compare-notorevision": "No 'to' revision. Specify <var>torev</var>, <var>totitle</var>, or <var>toid</var>.",
+       "apierror-compare-relative-to-deleted": "Cannot use <kbd>torelative=$1</kbd> relative to a deleted revision.",
        "apierror-compare-relative-to-nothing": "No 'from' revision for <var>torelative</var> to be relative to.",
        "apierror-contentserializationexception": "Content serialization failed: $1",
        "apierror-contenttoobig": "The content you supplied exceeds the article size limit of $1 {{PLURAL:$1|kilobyte|kilobytes}}.",
        "apierror-invalidexpiry": "Invalid expiry time \"$1\".",
        "apierror-invalid-file-key": "Not a valid file key.",
        "apierror-invalidlang": "Invalid language code for parameter <var>$1</var>.",
 +      "apierror-invalidmethod": "Invalid HTTP method. Consider using GET or POST.",
        "apierror-invalidoldimage": "The <var>oldimage</var> parameter has an invalid format.",
        "apierror-invalidparammix-cannotusewith": "The <kbd>$1</kbd> parameter cannot be used with <kbd>$2</kbd>.",
        "apierror-invalidparammix-mustusewith": "The <kbd>$1</kbd> parameter may only be used with <kbd>$2</kbd>.",
        "apierror-compare-nofromrevision": "{{doc-apierror}}",
        "apierror-compare-notext": "{{doc-apierror}}\n\nParameters:\n* $1 - Parameter that is not allowed without <var>totext-&#x7B;role}</var>/<var>fromtext-&#x7B;role}</var>.\n* $2 - The specific <var>totext-&#x7B;role}</var>/<var>fromtext-&#x7B;role}</var> parameter that must be present.",
        "apierror-compare-notorevision": "{{doc-apierror}}",
+       "apierror-compare-relative-to-deleted": "{{doc-apierror}}",
        "apierror-compare-relative-to-nothing": "{{doc-apierror}}",
        "apierror-contentserializationexception": "{{doc-apierror}}\n\nParameters:\n* $1 - Exception text, may end with punctuation. Currently this is probably English, hopefully we'll fix that in the future.",
        "apierror-contenttoobig": "{{doc-apierror}}\n\nParameters:\n* $1 - Maximum article size in kilobytes.",
        "apierror-invalidexpiry": "{{doc-apierror}}\n\nParameters:\n* $1 - Value provided.",
        "apierror-invalid-file-key": "{{doc-apierror}}",
        "apierror-invalidlang": "{{doc-apierror}}\n\nParameters:\n* $1 - Parameter name.",
 +      "apierror-invalidmethod": "{{doc-apierror}}\n\nShown when a user tries to access the API using an HTTP method that is not supported",
        "apierror-invalidoldimage": "{{doc-apierror}}",
        "apierror-invalidparammix-cannotusewith": "{{doc-apierror}}\n\nParameters:\n* $1 - Parameter name or \"parameter=value\" text.\n* $2 - Parameter name or \"parameter=value\" text.",
        "apierror-invalidparammix-mustusewith": "{{doc-apierror}}\n\nParameters:\n* $1 - Parameter name or \"parameter=value\" text.\n* $2 - Parameter name or \"parameter=value\" text.",