MediaWiki
REL1_24
|
00001 <?php 00025 class RevDelFileItem extends RevDelItem { 00027 public $file; 00028 00029 public function __construct( $list, $row ) { 00030 parent::__construct( $list, $row ); 00031 $this->file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row ); 00032 } 00033 00034 public function getIdField() { 00035 return 'oi_archive_name'; 00036 } 00037 00038 public function getTimestampField() { 00039 return 'oi_timestamp'; 00040 } 00041 00042 public function getAuthorIdField() { 00043 return 'oi_user'; 00044 } 00045 00046 public function getAuthorNameField() { 00047 return 'oi_user_text'; 00048 } 00049 00050 public function getId() { 00051 $parts = explode( '!', $this->row->oi_archive_name ); 00052 00053 return $parts[0]; 00054 } 00055 00056 public function canView() { 00057 return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getUser() ); 00058 } 00059 00060 public function canViewContent() { 00061 return $this->file->userCan( File::DELETED_FILE, $this->list->getUser() ); 00062 } 00063 00064 public function getBits() { 00065 return $this->file->getVisibility(); 00066 } 00067 00068 public function setBits( $bits ) { 00069 # Queue the file op 00070 # @todo FIXME: Move to LocalFile.php 00071 if ( $this->isDeleted() ) { 00072 if ( $bits & File::DELETED_FILE ) { 00073 # Still deleted 00074 } else { 00075 # Newly undeleted 00076 $key = $this->file->getStorageKey(); 00077 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key; 00078 $this->list->storeBatch[] = array( 00079 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel, 00080 'public', 00081 $this->file->getRel() 00082 ); 00083 $this->list->cleanupBatch[] = $key; 00084 } 00085 } elseif ( $bits & File::DELETED_FILE ) { 00086 # Newly deleted 00087 $key = $this->file->getStorageKey(); 00088 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key; 00089 $this->list->deleteBatch[] = array( $this->file->getRel(), $dstRel ); 00090 } 00091 00092 # Do the database operations 00093 $dbw = wfGetDB( DB_MASTER ); 00094 $dbw->update( 'oldimage', 00095 array( 'oi_deleted' => $bits ), 00096 array( 00097 'oi_name' => $this->row->oi_name, 00098 'oi_timestamp' => $this->row->oi_timestamp, 00099 'oi_deleted' => $this->getBits() 00100 ), 00101 __METHOD__ 00102 ); 00103 00104 return (bool)$dbw->affectedRows(); 00105 } 00106 00107 public function isDeleted() { 00108 return $this->file->isDeleted( File::DELETED_FILE ); 00109 } 00110 00116 protected function getLink() { 00117 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate( 00118 $this->file->getTimestamp(), $this->list->getUser() ) ); 00119 00120 if ( !$this->isDeleted() ) { 00121 # Regular files... 00122 return Html::rawElement( 'a', array( 'href' => $this->file->getUrl() ), $date ); 00123 } 00124 00125 # Hidden files... 00126 if ( !$this->canViewContent() ) { 00127 $link = $date; 00128 } else { 00129 $link = Linker::link( 00130 SpecialPage::getTitleFor( 'Revisiondelete' ), 00131 $date, 00132 array(), 00133 array( 00134 'target' => $this->list->title->getPrefixedText(), 00135 'file' => $this->file->getArchiveName(), 00136 'token' => $this->list->getUser()->getEditToken( 00137 $this->file->getArchiveName() ) 00138 ) 00139 ); 00140 } 00141 00142 return '<span class="history-deleted">' . $link . '</span>'; 00143 } 00144 00149 protected function getUserTools() { 00150 if ( $this->file->userCan( Revision::DELETED_USER, $this->list->getUser() ) ) { 00151 $uid = $this->file->getUser( 'id' ); 00152 $name = $this->file->getUser( 'text' ); 00153 $link = Linker::userLink( $uid, $name ) . Linker::userToolLinks( $uid, $name ); 00154 } else { 00155 $link = $this->list->msg( 'rev-deleted-user' )->escaped(); 00156 } 00157 if ( $this->file->isDeleted( Revision::DELETED_USER ) ) { 00158 return '<span class="history-deleted">' . $link . '</span>'; 00159 } 00160 00161 return $link; 00162 } 00163 00170 protected function getComment() { 00171 if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getUser() ) ) { 00172 $block = Linker::commentBlock( $this->file->getDescription() ); 00173 } else { 00174 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped(); 00175 } 00176 if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) { 00177 return "<span class=\"history-deleted\">$block</span>"; 00178 } 00179 00180 return $block; 00181 } 00182 00183 public function getHTML() { 00184 $data = 00185 $this->list->msg( 'widthheight' )->numParams( 00186 $this->file->getWidth(), $this->file->getHeight() )->text() . 00187 ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file->getSize() )->text() . ')'; 00188 00189 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' . 00190 $data . ' ' . $this->getComment() . '</li>'; 00191 } 00192 00193 public function getApiData( ApiResult $result ) { 00194 $file = $this->file; 00195 $user = $this->list->getUser(); 00196 $ret = array( 00197 'title' => $this->list->title->getPrefixedText(), 00198 'archivename' => $file->getArchiveName(), 00199 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ), 00200 'width' => $file->getWidth(), 00201 'height' => $file->getHeight(), 00202 'size' => $file->getSize(), 00203 ); 00204 $ret += $file->isDeleted( Revision::DELETED_USER ) ? array( 'userhidden' => '' ) : array(); 00205 $ret += $file->isDeleted( Revision::DELETED_COMMENT ) ? array( 'commenthidden' => '' ) : array(); 00206 $ret += $this->isDeleted() ? array( 'contenthidden' => '' ) : array(); 00207 if ( !$this->isDeleted() ) { 00208 $ret += array( 00209 'url' => $file->getUrl(), 00210 ); 00211 } elseif ( $this->canViewContent() ) { 00212 $ret += array( 00213 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL( 00214 array( 00215 'target' => $this->list->title->getPrefixedText(), 00216 'file' => $file->getArchiveName(), 00217 'token' => $user->getEditToken( $file->getArchiveName() ) 00218 ), 00219 false, PROTO_RELATIVE 00220 ), 00221 ); 00222 } 00223 if ( $file->userCan( Revision::DELETED_USER, $user ) ) { 00224 $ret += array( 00225 'userid' => $file->user, 00226 'user' => $file->user_text, 00227 ); 00228 } 00229 if ( $file->userCan( Revision::DELETED_COMMENT, $user ) ) { 00230 $ret += array( 00231 'comment' => $file->description, 00232 ); 00233 } 00234 00235 return $ret; 00236 } 00237 }