MediaWiki master
RevDelFileItem.php
Go to the documentation of this file.
1<?php
31
37 protected $list;
39 protected $file;
41
42 public function __construct( RevisionListBase $list, $row ) {
43 parent::__construct( $list, $row );
44 $this->file = static::initFile( $list, $row );
45 $this->dbProvider = MediaWikiServices::getInstance()->getConnectionProvider();
46 }
47
55 protected static function initFile( $list, $row ) {
56 return MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
57 ->newFileFromRow( $row );
58 }
59
60 public function getIdField() {
61 return 'oi_archive_name';
62 }
63
64 public function getTimestampField() {
65 return 'oi_timestamp';
66 }
67
68 public function getAuthorIdField() {
69 return 'oi_user';
70 }
71
72 public function getAuthorNameField() {
73 return 'oi_user_text';
74 }
75
76 public function getAuthorActorField() {
77 return 'oi_actor';
78 }
79
80 public function getId() {
81 $parts = explode( '!', $this->row->oi_archive_name );
82
83 return $parts[0];
84 }
85
86 public function canView() {
87 return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getAuthority() );
88 }
89
90 public function canViewContent() {
91 return $this->file->userCan( File::DELETED_FILE, $this->list->getAuthority() );
92 }
93
94 public function getBits() {
95 return $this->file->getVisibility();
96 }
97
98 public function setBits( $bits ) {
99 # Queue the file op
100 # @todo FIXME: Move to LocalFile.php
101 if ( $this->isDeleted() ) {
102 if ( $bits & File::DELETED_FILE ) {
103 # Still deleted
104 } else {
105 # Newly undeleted
106 $key = $this->file->getStorageKey();
107 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
108 $this->list->storeBatch[] = [
109 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
110 'public',
111 $this->file->getRel()
112 ];
113 $this->list->cleanupBatch[] = $key;
114 }
115 } elseif ( $bits & File::DELETED_FILE ) {
116 # Newly deleted
117 $key = $this->file->getStorageKey();
118 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
119 $this->list->deleteBatch[] = [ $this->file->getRel(), $dstRel ];
120 }
121
122 # Do the database operations
123 $dbw = $this->dbProvider->getPrimaryDatabase();
124 $dbw->newUpdateQueryBuilder()
125 ->update( 'oldimage' )
126 ->set( [ 'oi_deleted' => $bits ] )
127 ->where( [
128 'oi_name' => $this->row->oi_name,
129 'oi_timestamp' => $this->row->oi_timestamp,
130 'oi_deleted' => $this->getBits()
131 ] )
132 ->caller( __METHOD__ )->execute();
133
134 return (bool)$dbw->affectedRows();
135 }
136
137 public function isDeleted() {
138 return $this->file->isDeleted( File::DELETED_FILE );
139 }
140
146 protected function getLink() {
147 $date = $this->list->getLanguage()->userTimeAndDate(
148 $this->file->getTimestamp(), $this->list->getUser() );
149
150 if ( !$this->isDeleted() ) {
151 # Regular files...
152 return Html::element( 'a', [ 'href' => $this->file->getUrl() ], $date );
153 }
154
155 # Hidden files...
156 if ( !$this->canViewContent() ) {
157 $link = htmlspecialchars( $date );
158 } else {
159 $link = $this->getLinkRenderer()->makeLink(
160 SpecialPage::getTitleFor( 'Revisiondelete' ),
161 $date,
162 [],
163 [
164 'target' => $this->list->getPageName(),
165 'file' => $this->file->getArchiveName(),
166 'token' => $this->list->getUser()->getEditToken(
167 $this->file->getArchiveName() )
168 ]
169 );
170 }
171
172 return '<span class="history-deleted">' . $link . '</span>';
173 }
174
179 protected function getUserTools() {
180 $uploader = $this->file->getUploader( File::FOR_THIS_USER, $this->list->getAuthority() );
181 if ( $uploader ) {
182 $link = Linker::userLink( $uploader->getId(), $uploader->getName() ) .
183 Linker::userToolLinks( $uploader->getId(), $uploader->getName() );
184 return $link;
185 } else {
186 $link = $this->list->msg( 'rev-deleted-user' )->escaped();
187 }
188 if ( $this->file->isDeleted( File::DELETED_USER ) ) {
189 return '<span class="history-deleted">' . $link . '</span>';
190 }
191 return $link;
192 }
193
200 protected function getComment() {
201 if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getAuthority() ) ) {
202 $block = MediaWikiServices::getInstance()->getCommentFormatter()
203 ->formatBlock( $this->file->getDescription() );
204 } else {
205 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
206 }
207 if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
208 return "<span class=\"history-deleted\">$block</span>";
209 }
210
211 return $block;
212 }
213
214 public function getHTML() {
215 $data =
216 $this->list->msg( 'widthheight' )->numParams(
217 $this->file->getWidth(),
218 $this->file->getHeight() )->escaped() .
219 ' (' . $this->list->msg( 'nbytes' )->numParams(
220 $this->file->getSize() )->escaped() . ')';
221
222 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
223 $data . ' ' . $this->getComment() . '</li>';
224 }
225
226 public function getApiData( ApiResult $result ) {
228 $user = $this->list->getUser();
229 $ret = [
230 'title' => $this->list->getPageName(),
231 'archivename' => $file->getArchiveName(),
232 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
233 'width' => $file->getWidth(),
234 'height' => $file->getHeight(),
235 'size' => $file->getSize(),
236 'userhidden' => (bool)$file->isDeleted( File::DELETED_USER ),
237 'commenthidden' => (bool)$file->isDeleted( File::DELETED_COMMENT ),
238 'contenthidden' => (bool)$this->isDeleted(),
239 ];
240 if ( !$this->isDeleted() ) {
241 $ret += [
242 'url' => $file->getUrl(),
243 ];
244 } elseif ( $this->canViewContent() ) {
245 $ret += [
246 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
247 [
248 'target' => $this->list->getPageName(),
249 'file' => $file->getArchiveName(),
250 'token' => $user->getEditToken( $file->getArchiveName() )
251 ]
252 ),
253 ];
254 }
255 $uploader = $file->getUploader( File::FOR_THIS_USER, $user );
256 if ( $uploader ) {
257 $ret += [
258 'userid' => $uploader->getId(),
259 'user' => $uploader->getName(),
260 ];
261 }
262 $comment = $file->getDescription( File::FOR_THIS_USER, $user );
263 if ( ( $comment ?? '' ) !== '' ) {
264 $ret += [
265 'comment' => $comment,
266 ];
267 }
268
269 return $ret;
270 }
271
272 public function lock() {
273 return $this->file->acquireFileLock();
274 }
275
276 public function unlock() {
277 return $this->file->releaseFileLock();
278 }
279}
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
This class represents the result of the API operations.
Definition ApiResult.php:43
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:93
getUrl()
Return the URL of the file.
Definition File.php:414
getWidth( $page=1)
Return the width of the image.
getHeight( $page=1)
Return the height of the image.
getSize()
Returns the size of the image file, in bytes.
getUploader(int $audience=self::FOR_PUBLIC, ?Authority $performer=null)
getDescription( $audience=self::FOR_PUBLIC, ?Authority $performer=null)
Old file in the oldimage table.
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
Some internal bits split of from Skin.php.
Definition Linker.php:62
Service locator for MediaWiki core services.
getLinkRenderer()
Returns an instance of LinkRenderer.
stdClass $row
The database result row.
List for revision table items for a single page.
Parent class for all special pages.
Item class for an oldimage table row.
getTimestampField()
Get the DB field name storing timestamps.
getComment()
Wrap and format the file's comment block, if the current user is allowed to view it.
getLink()
Get the link to the file.
RevDelFileList $list
canViewContent()
Returns true if the current user can view the item text/file.
getId()
Get the ID, as it would appear in the ids URL parameter.
getIdField()
Get the DB field name associated with the ID list.
getBits()
Get the current deletion bitfield value.
getAuthorIdField()
Get the DB field name storing user ids.
static initFile( $list, $row)
Create file object from $row sourced from $list.
getHTML()
Get the HTML of the list item.
getUserTools()
Generate a user tool link cluster if the current user is allowed to view it.
IConnectionProvider $dbProvider
__construct(RevisionListBase $list, $row)
unlock()
Unlock the item against changes outside of the DB.
getAuthorNameField()
Get the DB field name storing user names.
lock()
Lock the item against changes outside of the DB.
canView()
Returns true if the current user can view the item.
getAuthorActorField()
Get the DB field name storing actor ids.
setBits( $bits)
Set the visibility of the item.
OldLocalFile $file
getApiData(ApiResult $result)
Get the return information about the revision for the API.
List for oldimage table items.
Abstract base class for deletable items.
Provide primary and replica IDatabase connections.