X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2FStorage%2FRevisionRecord.php;h=8c31a3caf7259bdb82f0a23e9ded03c0f36a77cf;hp=7d1b4778d48f4d3492dae4857f90ca1fcb906db8;hb=4df0c71911500466a6330b8fe29c623ef5b51e41;hpb=aa85156042b7055c238f9d65fdfa3741cda40322 diff --git a/includes/Storage/RevisionRecord.php b/includes/Storage/RevisionRecord.php index 7d1b4778d4..8c31a3caf7 100644 --- a/includes/Storage/RevisionRecord.php +++ b/includes/Storage/RevisionRecord.php @@ -453,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 ) { @@ -532,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() !== []; + } + }