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 Wikimedia\Rdbms\IDatabase
;
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
= RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
38 public function getIdField() {
39 return 'oi_archive_name';
42 public function getTimestampField() {
43 return 'oi_timestamp';
46 public function getAuthorIdField() {
50 public function getAuthorNameField() {
51 return 'oi_user_text';
54 public function getId() {
55 $parts = explode( '!', $this->row
->oi_archive_name
);
60 public function canView() {
61 return $this->file
->userCan( File
::DELETED_RESTRICTED
, $this->list->getUser() );
64 public function canViewContent() {
65 return $this->file
->userCan( File
::DELETED_FILE
, $this->list->getUser() );
68 public function getBits() {
69 return $this->file
->getVisibility();
72 public function setBits( $bits ) {
74 # @todo FIXME: Move to LocalFile.php
75 if ( $this->isDeleted() ) {
76 if ( $bits & File
::DELETED_FILE
) {
80 $key = $this->file
->getStorageKey();
81 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
82 $this->list->storeBatch
[] = [
83 $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
87 $this->list->cleanupBatch
[] = $key;
89 } elseif ( $bits & File
::DELETED_FILE
) {
91 $key = $this->file
->getStorageKey();
92 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
93 $this->list->deleteBatch
[] = [ $this->file
->getRel(), $dstRel ];
96 # Do the database operations
97 $dbw = wfGetDB( DB_MASTER
);
98 $dbw->update( 'oldimage',
99 [ 'oi_deleted' => $bits ],
101 'oi_name' => $this->row
->oi_name
,
102 'oi_timestamp' => $this->row
->oi_timestamp
,
103 'oi_deleted' => $this->getBits()
108 return (bool)$dbw->affectedRows();
111 public function isDeleted() {
112 return $this->file
->isDeleted( File
::DELETED_FILE
);
116 * Get the link to the file.
117 * Overridden by RevDelArchivedFileItem.
120 protected function getLink() {
121 $date = $this->list->getLanguage()->userTimeAndDate(
122 $this->file
->getTimestamp(), $this->list->getUser() );
124 if ( !$this->isDeleted() ) {
126 return Html
::element( 'a', [ 'href' => $this->file
->getUrl() ], $date );
130 if ( !$this->canViewContent() ) {
131 $link = htmlspecialchars( $date );
133 $link = $this->getLinkRenderer()->makeLink(
134 SpecialPage
::getTitleFor( 'Revisiondelete' ),
138 'target' => $this->list->title
->getPrefixedText(),
139 'file' => $this->file
->getArchiveName(),
140 'token' => $this->list->getUser()->getEditToken(
141 $this->file
->getArchiveName() )
146 return '<span class="history-deleted">' . $link . '</span>';
150 * Generate a user tool link cluster if the current user is allowed to view it
151 * @return string HTML
153 protected function getUserTools() {
154 if ( $this->file
->userCan( Revision
::DELETED_USER
, $this->list->getUser() ) ) {
155 $uid = $this->file
->getUser( 'id' );
156 $name = $this->file
->getUser( 'text' );
157 $link = Linker
::userLink( $uid, $name ) . Linker
::userToolLinks( $uid, $name );
159 $link = $this->list->msg( 'rev-deleted-user' )->escaped();
161 if ( $this->file
->isDeleted( Revision
::DELETED_USER
) ) {
162 return '<span class="history-deleted">' . $link . '</span>';
169 * Wrap and format the file's comment block, if the current
170 * user is allowed to view it.
172 * @return string HTML
174 protected function getComment() {
175 if ( $this->file
->userCan( File
::DELETED_COMMENT
, $this->list->getUser() ) ) {
176 $block = Linker
::commentBlock( $this->file
->getDescription() );
178 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
180 if ( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
181 return "<span class=\"history-deleted\">$block</span>";
187 public function getHTML() {
189 $this->list->msg( 'widthheight' )->numParams(
190 $this->file
->getWidth(), $this->file
->getHeight() )->text() .
191 ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file
->getSize() )->text() . ')';
193 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
194 $data . ' ' . $this->getComment() . '</li>';
197 public function getApiData( ApiResult
$result ) {
199 $user = $this->list->getUser();
201 'title' => $this->list->title
->getPrefixedText(),
202 'archivename' => $file->getArchiveName(),
203 'timestamp' => wfTimestamp( TS_ISO_8601
, $file->getTimestamp() ),
204 'width' => $file->getWidth(),
205 'height' => $file->getHeight(),
206 'size' => $file->getSize(),
207 'userhidden' => (bool)$file->isDeleted( Revision
::DELETED_USER
),
208 'commenthidden' => (bool)$file->isDeleted( Revision
::DELETED_COMMENT
),
209 'contenthidden' => (bool)$this->isDeleted(),
211 if ( !$this->isDeleted() ) {
213 'url' => $file->getUrl(),
215 } elseif ( $this->canViewContent() ) {
217 'url' => SpecialPage
::getTitleFor( 'Revisiondelete' )->getLinkURL(
219 'target' => $this->list->title
->getPrefixedText(),
220 'file' => $file->getArchiveName(),
221 'token' => $user->getEditToken( $file->getArchiveName() )
226 if ( $file->userCan( Revision
::DELETED_USER
, $user ) ) {
228 'userid' => $file->user
,
229 'user' => $file->user_text
,
232 if ( $file->userCan( Revision
::DELETED_COMMENT
, $user ) ) {
234 'comment' => $file->description
,
241 public function lock() {
242 return $this->file
->acquireFileLock();
245 public function unlock() {
246 return $this->file
->releaseFileLock();