MediaWiki  REL1_24
RevDelRevisionList.php
Go to the documentation of this file.
00001 <?php
00031 class RevDelRevisionList extends RevDelList {
00033     public $currentRevId;
00034 
00035     public function getType() {
00036         return 'revision';
00037     }
00038 
00039     public static function getRelationType() {
00040         return 'rev_id';
00041     }
00042 
00043     public static function getRestriction() {
00044         return 'deleterevision';
00045     }
00046 
00047     public static function getRevdelConstant() {
00048         return Revision::DELETED_TEXT;
00049     }
00050 
00051     public static function suggestTarget( $target, array $ids ) {
00052         $rev = Revision::newFromId( $ids[0] );
00053         return $rev ? $rev->getTitle() : $target;
00054     }
00055 
00060     public function doQuery( $db ) {
00061         $ids = array_map( 'intval', $this->ids );
00062         $live = $db->select(
00063             array( 'revision', 'page', 'user' ),
00064             array_merge( Revision::selectFields(), Revision::selectUserFields() ),
00065             array(
00066                 'rev_page' => $this->title->getArticleID(),
00067                 'rev_id' => $ids,
00068             ),
00069             __METHOD__,
00070             array( 'ORDER BY' => 'rev_id DESC' ),
00071             array(
00072                 'page' => Revision::pageJoinCond(),
00073                 'user' => Revision::userJoinCond() )
00074         );
00075 
00076         if ( $live->numRows() >= count( $ids ) ) {
00077             // All requested revisions are live, keeps things simple!
00078             return $live;
00079         }
00080 
00081         // Check if any requested revisions are available fully deleted.
00082         $archived = $db->select( array( 'archive' ), Revision::selectArchiveFields(),
00083             array(
00084                 'ar_rev_id' => $ids
00085             ),
00086             __METHOD__,
00087             array( 'ORDER BY' => 'ar_rev_id DESC' )
00088         );
00089 
00090         if ( $archived->numRows() == 0 ) {
00091             return $live;
00092         } elseif ( $live->numRows() == 0 ) {
00093             return $archived;
00094         } else {
00095             // Combine the two! Whee
00096             $rows = array();
00097             foreach ( $live as $row ) {
00098                 $rows[$row->rev_id] = $row;
00099             }
00100             foreach ( $archived as $row ) {
00101                 $rows[$row->ar_rev_id] = $row;
00102             }
00103             krsort( $rows );
00104             return new FakeResultWrapper( array_values( $rows ) );
00105         }
00106     }
00107 
00108     public function newItem( $row ) {
00109         if ( isset( $row->rev_id ) ) {
00110             return new RevDelRevisionItem( $this, $row );
00111         } elseif ( isset( $row->ar_rev_id ) ) {
00112             return new RevDelArchivedRevisionItem( $this, $row );
00113         } else {
00114             // This shouldn't happen. :)
00115             throw new MWException( 'Invalid row type in RevDelRevisionList' );
00116         }
00117     }
00118 
00119     public function getCurrent() {
00120         if ( is_null( $this->currentRevId ) ) {
00121             $dbw = wfGetDB( DB_MASTER );
00122             $this->currentRevId = $dbw->selectField(
00123                 'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
00124         }
00125         return $this->currentRevId;
00126     }
00127 
00128     public function getSuppressBit() {
00129         return Revision::DELETED_RESTRICTED;
00130     }
00131 
00132     public function doPreCommitUpdates() {
00133         $this->title->invalidateCache();
00134         return Status::newGood();
00135     }
00136 
00137     public function doPostCommitUpdates() {
00138         $this->title->purgeSquid();
00139         // Extensions that require referencing previous revisions may need this
00140         wfRunHooks( 'ArticleRevisionVisibilitySet', array( &$this->title ) );
00141         return Status::newGood();
00142     }
00143 }