+ // Trigger lazy purge of expired restrictions from the db
+ $purgeExpired = true;
+ }
+ }
+ if( $purgeExpired ) {
+ Title::purgeExpiredRestrictions();
+ }
+
+ wfProfileOut( __METHOD__ );
+
+ if ( $get_pages ) {
+ $this->mCascadeSources = $sources;
+ $this->mCascadingRestrictions = $pagerestrictions;
+ } else {
+ $this->mHasCascadingRestrictions = $sources;
+ }
+
+ return array( $sources, $pagerestrictions );
+ }
+
+ function areRestrictionsCascading() {
+ if (!$this->mRestrictionsLoaded) {
+ $this->loadRestrictions();
+ }
+
+ return $this->mCascadeRestriction;
+ }
+
+ /**
+ * Loads a string into mRestrictions array
+ * @param resource $res restrictions as an SQL result.
+ */
+ private function loadRestrictionsFromRow( $res, $oldFashionedRestrictions = NULL ) {
+ $dbr = wfGetDb( DB_SLAVE );
+
+ $this->mRestrictions['edit'] = array();
+ $this->mRestrictions['move'] = array();
+
+ # Backwards-compatibility: also load the restrictions from the page record (old format).
+
+ if ( $oldFashionedRestrictions == NULL ) {
+ $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ), __METHOD__ );
+ }
+
+ if ($oldFashionedRestrictions != '') {
+
+ foreach( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) {
+ $temp = explode( '=', trim( $restrict ) );
+ if(count($temp) == 1) {
+ // old old format should be treated as edit/move restriction
+ $this->mRestrictions["edit"] = explode( ',', trim( $temp[0] ) );
+ $this->mRestrictions["move"] = explode( ',', trim( $temp[0] ) );
+ } else {
+ $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );
+ }
+ }
+
+ $this->mOldRestrictions = true;
+ $this->mCascadeRestriction = false;
+ $this->mRestrictionsExpiry = Block::decodeExpiry('');
+
+ }
+
+ if( $dbr->numRows( $res ) ) {
+ # Current system - load second to make them override.
+ $now = wfTimestampNow();
+ $purgeExpired = false;
+
+ while ($row = $dbr->fetchObject( $res ) ) {
+ # Cycle through all the restrictions.
+
+ // This code should be refactored, now that it's being used more generally,
+ // But I don't really see any harm in leaving it in Block for now -werdna
+ $expiry = Block::decodeExpiry( $row->pr_expiry );
+
+ // Only apply the restrictions if they haven't expired!
+ if ( !$expiry || $expiry > $now ) {
+ $this->mRestrictionsExpiry = $expiry;
+ $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) );
+
+ $this->mCascadeRestriction |= $row->pr_cascade;
+ } else {
+ // Trigger a lazy purge of expired restrictions
+ $purgeExpired = true;
+ }
+ }
+
+ if( $purgeExpired ) {
+ Title::purgeExpiredRestrictions();