3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 * @ingroup RevisionDelete
22 use MediaWiki\Storage\RevisionRecord
;
25 * Item class for an oldimage table row
27 class RevDelFileItem
extends RevDelItem
{
28 /** @var RevDelFileList */
30 /** @var OldLocalFile */
33 public function __construct( $list, $row ) {
34 parent
::__construct( $list, $row );
35 $this->file
= static::initFile( $list, $row );
39 * Create file object from $row sourced from $list
41 * @param RevDelFileList $list
45 protected static function initFile( $list, $row ) {
46 return RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
49 public function getIdField() {
50 return 'oi_archive_name';
53 public function getTimestampField() {
54 return 'oi_timestamp';
57 public function getAuthorIdField() {
61 public function getAuthorNameField() {
62 return 'oi_user_text';
65 public function getAuthorActorField() {
69 public function getId() {
70 $parts = explode( '!', $this->row
->oi_archive_name
);
75 public function canView() {
76 return $this->file
->userCan( File
::DELETED_RESTRICTED
, $this->list->getUser() );
79 public function canViewContent() {
80 return $this->file
->userCan( File
::DELETED_FILE
, $this->list->getUser() );
83 public function getBits() {
84 return $this->file
->getVisibility();
87 public function setBits( $bits ) {
89 # @todo FIXME: Move to LocalFile.php
90 if ( $this->isDeleted() ) {
91 if ( $bits & File
::DELETED_FILE
) {
95 $key = $this->file
->getStorageKey();
96 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
97 $this->list->storeBatch
[] = [
98 $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
100 $this->file
->getRel()
102 $this->list->cleanupBatch
[] = $key;
104 } elseif ( $bits & File
::DELETED_FILE
) {
106 $key = $this->file
->getStorageKey();
107 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
108 $this->list->deleteBatch
[] = [ $this->file
->getRel(), $dstRel ];
111 # Do the database operations
112 $dbw = wfGetDB( DB_MASTER
);
113 $dbw->update( 'oldimage',
114 [ 'oi_deleted' => $bits ],
116 'oi_name' => $this->row
->oi_name
,
117 'oi_timestamp' => $this->row
->oi_timestamp
,
118 'oi_deleted' => $this->getBits()
123 return (bool)$dbw->affectedRows();
126 public function isDeleted() {
127 return $this->file
->isDeleted( File
::DELETED_FILE
);
131 * Get the link to the file.
132 * Overridden by RevDelArchivedFileItem.
135 protected function getLink() {
136 $date = $this->list->getLanguage()->userTimeAndDate(
137 $this->file
->getTimestamp(), $this->list->getUser() );
139 if ( !$this->isDeleted() ) {
141 return Html
::element( 'a', [ 'href' => $this->file
->getUrl() ], $date );
145 if ( !$this->canViewContent() ) {
146 $link = htmlspecialchars( $date );
148 $link = $this->getLinkRenderer()->makeLink(
149 SpecialPage
::getTitleFor( 'Revisiondelete' ),
153 'target' => $this->list->title
->getPrefixedText(),
154 'file' => $this->file
->getArchiveName(),
155 'token' => $this->list->getUser()->getEditToken(
156 $this->file
->getArchiveName() )
161 return '<span class="history-deleted">' . $link . '</span>';
165 * Generate a user tool link cluster if the current user is allowed to view it
166 * @return string HTML
168 protected function getUserTools() {
169 if ( $this->file
->userCan( RevisionRecord
::DELETED_USER
, $this->list->getUser() ) ) {
170 $uid = $this->file
->getUser( 'id' );
171 $name = $this->file
->getUser( 'text' );
172 $link = Linker
::userLink( $uid, $name ) . Linker
::userToolLinks( $uid, $name );
174 $link = $this->list->msg( 'rev-deleted-user' )->escaped();
176 if ( $this->file
->isDeleted( RevisionRecord
::DELETED_USER
) ) {
177 return '<span class="history-deleted">' . $link . '</span>';
184 * Wrap and format the file's comment block, if the current
185 * user is allowed to view it.
187 * @return string HTML
189 protected function getComment() {
190 if ( $this->file
->userCan( File
::DELETED_COMMENT
, $this->list->getUser() ) ) {
191 $block = Linker
::commentBlock( $this->file
->getDescription() );
193 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
195 if ( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
196 return "<span class=\"history-deleted\">$block</span>";
202 public function getHTML() {
204 $this->list->msg( 'widthheight' )->numParams(
205 $this->file
->getWidth(), $this->file
->getHeight() )->text() .
206 ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file
->getSize() )->text() . ')';
208 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
209 $data . ' ' . $this->getComment() . '</li>';
212 public function getApiData( ApiResult
$result ) {
214 $user = $this->list->getUser();
216 'title' => $this->list->title
->getPrefixedText(),
217 'archivename' => $file->getArchiveName(),
218 'timestamp' => wfTimestamp( TS_ISO_8601
, $file->getTimestamp() ),
219 'width' => $file->getWidth(),
220 'height' => $file->getHeight(),
221 'size' => $file->getSize(),
222 'userhidden' => (bool)$file->isDeleted( RevisionRecord
::DELETED_USER
),
223 'commenthidden' => (bool)$file->isDeleted( RevisionRecord
::DELETED_COMMENT
),
224 'contenthidden' => (bool)$this->isDeleted(),
226 if ( !$this->isDeleted() ) {
228 'url' => $file->getUrl(),
230 } elseif ( $this->canViewContent() ) {
232 'url' => SpecialPage
::getTitleFor( 'Revisiondelete' )->getLinkURL(
234 'target' => $this->list->title
->getPrefixedText(),
235 'file' => $file->getArchiveName(),
236 'token' => $user->getEditToken( $file->getArchiveName() )
241 if ( $file->userCan( RevisionRecord
::DELETED_USER
, $user ) ) {
243 'userid' => $file->user
,
244 'user' => $file->user_text
,
247 if ( $file->userCan( RevisionRecord
::DELETED_COMMENT
, $user ) ) {
249 'comment' => $file->description
,
256 public function lock() {
257 return $this->file
->acquireFileLock();
260 public function unlock() {
261 return $this->file
->releaseFileLock();