Merge "Add MessagesBi.php"
[lhc/web/wiklou.git] / includes / Storage / RevisionRecord.php
index ff0a70d..8c31a3c 100644 (file)
@@ -218,6 +218,48 @@ abstract class RevisionRecord {
                return $this->mSlots->getSlotRoles();
        }
 
+       /**
+        * Returns the slots defined for this revision.
+        *
+        * @return RevisionSlots
+        */
+       public function getSlots() {
+               return $this->mSlots;
+       }
+
+       /**
+        * Returns the slots that originate in this revision.
+        *
+        * Note that this does not include any slots inherited from some earlier revision,
+        * even if they are different from the slots in the immediate parent revision.
+        * This is the case for rollbacks: slots of a rollback revision are inherited from
+        * the rollback target, and are different from the slots in the parent revision,
+        * which was rolled back.
+        *
+        * To find all slots modified by this revision against its immediate parent
+        * revision, use RevisionSlotsUpdate::newFromRevisionSlots().
+        *
+        * @return RevisionSlots
+        */
+       public function getOriginalSlots() {
+               return new RevisionSlots( $this->mSlots->getOriginalSlots() );
+       }
+
+       /**
+        * Returns slots inherited from some previous revision.
+        *
+        * "Inherited" slots are all slots that do not originate in this revision.
+        * Note that these slots may still differ from the one in the parent revision.
+        * This is the case for rollbacks: slots of a rollback revision are inherited from
+        * the rollback target, and are different from the slots in the parent revision,
+        * which was rolled back.
+        *
+        * @return RevisionSlots
+        */
+       public function getInheritedSlots() {
+               return new RevisionSlots( $this->mSlots->getInheritedSlots() );
+       }
+
        /**
         * Get revision ID. Depending on the concrete subclass, this may return null if
         * the revision ID is not known (e.g. because the revision does not yet exist
@@ -411,7 +453,7 @@ abstract class RevisionRecord {
         *
         * @return bool
         */
-       protected function audienceCan( $field, $audience, User $user = null ) {
+       public function audienceCan( $field, $audience, User $user = null ) {
                if ( $audience == self::FOR_PUBLIC && $this->isDeleted( $field ) ) {
                        return false;
                } elseif ( $audience == self::FOR_THIS_USER ) {
@@ -474,7 +516,7 @@ abstract class RevisionRecord {
                        $permissionlist = implode( ', ', $permissions );
                        if ( $title === null ) {
                                wfDebug( "Checking for $permissionlist due to $field match on $bitfield\n" );
-                               return call_user_func_array( [ $user, 'isAllowedAny' ], $permissions );
+                               return $user->isAllowedAny( ...$permissions );
                        } else {
                                $text = $title->getPrefixedText();
                                wfDebug( "Checking for $permissionlist on $text due to $field match on $bitfield\n" );
@@ -490,4 +532,29 @@ abstract class RevisionRecord {
                }
        }
 
+       /**
+        * Returns whether this RevisionRecord is ready for insertion, that is, whether it contains all
+        * information needed to save it to the database. This should trivially be true for
+        * RevisionRecords loaded from the database.
+        *
+        * Note that this may return true even if getId() or getPage() return null or 0, since these
+        * are generally assigned while the revision is saved to the database, and may not be available
+        * before.
+        *
+        * @return bool
+        */
+       public function isReadyForInsertion() {
+               // NOTE: don't check getSize() and getSha1(), since that may cause the full content to
+               // be loaded in order to calculate the values. Just assume these methods will not return
+               // null if mSlots is not empty.
+
+               // NOTE: getId() and getPageId() may return null before a revision is saved, so don't
+               //check them.
+
+               return $this->getTimestamp() !== null
+                       && $this->getComment( self::RAW ) !== null
+                       && $this->getUser( self::RAW ) !== null
+                       && $this->mSlots->getSlotRoles() !== [];
+       }
+
 }