MediaWiki  REL1_24
RevDelRevisionItem.php
Go to the documentation of this file.
00001 <?php
00025 class RevDelRevisionItem extends RevDelItem {
00027     public $revision;
00028 
00029     public function __construct( $list, $row ) {
00030         parent::__construct( $list, $row );
00031         $this->revision = new Revision( $row );
00032     }
00033 
00034     public function getIdField() {
00035         return 'rev_id';
00036     }
00037 
00038     public function getTimestampField() {
00039         return 'rev_timestamp';
00040     }
00041 
00042     public function getAuthorIdField() {
00043         return 'rev_user';
00044     }
00045 
00046     public function getAuthorNameField() {
00047         return 'rev_user_text';
00048     }
00049 
00050     public function canView() {
00051         return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->list->getUser() );
00052     }
00053 
00054     public function canViewContent() {
00055         return $this->revision->userCan( Revision::DELETED_TEXT, $this->list->getUser() );
00056     }
00057 
00058     public function getBits() {
00059         return $this->revision->getVisibility();
00060     }
00061 
00062     public function setBits( $bits ) {
00063         $dbw = wfGetDB( DB_MASTER );
00064         // Update revision table
00065         $dbw->update( 'revision',
00066             array( 'rev_deleted' => $bits ),
00067             array(
00068                 'rev_id' => $this->revision->getId(),
00069                 'rev_page' => $this->revision->getPage(),
00070                 'rev_deleted' => $this->getBits()
00071             ),
00072             __METHOD__
00073         );
00074         if ( !$dbw->affectedRows() ) {
00075             // Concurrent fail!
00076             return false;
00077         }
00078         // Update recentchanges table
00079         $dbw->update( 'recentchanges',
00080             array(
00081                 'rc_deleted' => $bits,
00082                 'rc_patrolled' => 1
00083             ),
00084             array(
00085                 'rc_this_oldid' => $this->revision->getId(), // condition
00086                 // non-unique timestamp index
00087                 'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ),
00088             ),
00089             __METHOD__
00090         );
00091 
00092         return true;
00093     }
00094 
00095     public function isDeleted() {
00096         return $this->revision->isDeleted( Revision::DELETED_TEXT );
00097     }
00098 
00099     public function isHideCurrentOp( $newBits ) {
00100         return ( $newBits & Revision::DELETED_TEXT )
00101             && $this->list->getCurrent() == $this->getId();
00102     }
00103 
00109     protected function getRevisionLink() {
00110         $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
00111             $this->revision->getTimestamp(), $this->list->getUser() ) );
00112 
00113         if ( $this->isDeleted() && !$this->canViewContent() ) {
00114             return $date;
00115         }
00116 
00117         return Linker::linkKnown(
00118             $this->list->title,
00119             $date,
00120             array(),
00121             array(
00122                 'oldid' => $this->revision->getId(),
00123                 'unhide' => 1
00124             )
00125         );
00126     }
00127 
00133     protected function getDiffLink() {
00134         if ( $this->isDeleted() && !$this->canViewContent() ) {
00135             return $this->list->msg( 'diff' )->escaped();
00136         } else {
00137             return Linker::linkKnown(
00138                     $this->list->title,
00139                     $this->list->msg( 'diff' )->escaped(),
00140                     array(),
00141                     array(
00142                         'diff' => $this->revision->getId(),
00143                         'oldid' => 'prev',
00144                         'unhide' => 1
00145                     )
00146                 );
00147         }
00148     }
00149 
00150     public function getHTML() {
00151         $difflink = $this->list->msg( 'parentheses' )
00152             ->rawParams( $this->getDiffLink() )->escaped();
00153         $revlink = $this->getRevisionLink();
00154         $userlink = Linker::revUserLink( $this->revision );
00155         $comment = Linker::revComment( $this->revision );
00156         if ( $this->isDeleted() ) {
00157             $revlink = "<span class=\"history-deleted\">$revlink</span>";
00158         }
00159 
00160         return "<li>$difflink $revlink $userlink $comment</li>";
00161     }
00162 
00163     public function getApiData( ApiResult $result ) {
00164         $rev = $this->revision;
00165         $user = $this->list->getUser();
00166         $ret = array(
00167             'id' => $rev->getId(),
00168             'timestamp' => wfTimestamp( TS_ISO_8601, $rev->getTimestamp() ),
00169         );
00170         $ret += $rev->isDeleted( Revision::DELETED_USER ) ? array( 'userhidden' => '' ) : array();
00171         $ret += $rev->isDeleted( Revision::DELETED_COMMENT ) ? array( 'commenthidden' => '' ) : array();
00172         $ret += $rev->isDeleted( Revision::DELETED_TEXT ) ? array( 'texthidden' => '' ) : array();
00173         if ( $rev->userCan( Revision::DELETED_USER, $user ) ) {
00174             $ret += array(
00175                 'userid' => $rev->getUser( Revision::FOR_THIS_USER ),
00176                 'user' => $rev->getUserText( Revision::FOR_THIS_USER ),
00177             );
00178         }
00179         if ( $rev->userCan( Revision::DELETED_COMMENT, $user ) ) {
00180             $ret += array(
00181                 'comment' => $rev->getComment( Revision::FOR_THIS_USER ),
00182             );
00183         }
00184 
00185         return $ret;
00186     }
00187 }