Merge "ApiComparePages: Don't try to find next/prev of a deleted revision"
[lhc/web/wiklou.git] / includes / api / ApiComparePages.php
index 97b21b9..f688346 100644 (file)
@@ -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() {
@@ -278,9 +282,8 @@ class ApiComparePages extends ApiBase {
                }
 
                $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"] ) ) {
@@ -588,10 +591,7 @@ class ApiComparePages extends ApiBase {
        }
 
        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