MediaWiki master
RevDelFileItem.php
Go to the documentation of this file.
1<?php
9
19use Wikimedia\Timestamp\TimestampFormat as TS;
20
26 protected $list;
28 protected $file;
30
32 public function __construct( RevisionListBase $list, $row ) {
33 parent::__construct( $list, $row );
34 $this->file = static::initFile( $list, $row );
35 $this->dbProvider = MediaWikiServices::getInstance()->getConnectionProvider();
36 }
37
45 protected static function initFile( $list, $row ) {
46 return MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
47 ->newFileFromRow( $row );
48 }
49
51 public function getIdField() {
52 return 'oi_archive_name';
53 }
54
56 public function getTimestampField() {
57 return 'oi_timestamp';
58 }
59
61 public function getAuthorIdField() {
62 return 'oi_user';
63 }
64
66 public function getAuthorNameField() {
67 return 'oi_user_text';
68 }
69
71 public function getAuthorActorField() {
72 return 'oi_actor';
73 }
74
76 public function getId() {
77 $parts = explode( '!', $this->row->oi_archive_name );
78
79 return $parts[0];
80 }
81
83 public function canView() {
84 return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getAuthority() );
85 }
86
88 public function canViewContent() {
89 return $this->file->userCan( File::DELETED_FILE, $this->list->getAuthority() );
90 }
91
93 public function getBits() {
94 return $this->file->getVisibility();
95 }
96
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
140 public function isDeleted() {
141 return $this->file->isDeleted( File::DELETED_FILE );
142 }
143
149 protected function getLink() {
150 $date = $this->list->getLanguage()->userTimeAndDate(
151 $this->file->getTimestamp(), $this->list->getUser() );
152
153 if ( !$this->isDeleted() ) {
154 # Regular files...
155 return Html::element( 'a', [ 'href' => $this->file->getUrl() ], $date );
156 }
157
158 # Hidden files...
159 if ( !$this->canViewContent() ) {
160 $link = htmlspecialchars( $date );
161 } else {
162 $link = $this->getLinkRenderer()->makeLink(
163 SpecialPage::getTitleFor( 'Revisiondelete' ),
164 $date,
165 [],
166 [
167 'target' => $this->list->getPageName(),
168 'file' => $this->file->getArchiveName(),
169 'token' => $this->list->getUser()->getEditToken(
170 $this->file->getArchiveName() )
171 ]
172 );
173 }
174
175 return '<span class="history-deleted">' . $link . '</span>';
176 }
177
182 protected function getUserTools() {
183 $uploader = $this->file->getUploader( File::FOR_THIS_USER, $this->list->getAuthority() );
184 if ( $uploader ) {
185 $link = Linker::userLink( $uploader->getId(), $uploader->getName() ) .
186 Linker::userToolLinks( $uploader->getId(), $uploader->getName() );
187 return $link;
188 } else {
189 $link = $this->list->msg( 'rev-deleted-user' )->escaped();
190 }
191 if ( $this->file->isDeleted( File::DELETED_USER ) ) {
192 return '<span class="history-deleted">' . $link . '</span>';
193 }
194 return $link;
195 }
196
203 protected function getComment() {
204 if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getAuthority() ) ) {
205 $block = MediaWikiServices::getInstance()->getCommentFormatter()
206 ->formatBlock( $this->file->getDescription() );
207 } else {
208 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
209 }
210 if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
211 return "<span class=\"history-deleted\">$block</span>";
212 }
213
214 return $block;
215 }
216
218 public function getHTML() {
219 $data =
220 $this->list->msg( 'widthheight' )->numParams(
221 $this->file->getWidth(),
222 $this->file->getHeight() )->escaped() .
223 ' (' . $this->list->msg( 'nbytes' )->numParams(
224 $this->file->getSize() )->escaped() . ')';
225
226 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
227 $data . ' ' . $this->getComment() . '</li>';
228 }
229
231 public function getApiData( ApiResult $result ) {
233 $user = $this->list->getUser();
234 $ret = [
235 'title' => $this->list->getPageName(),
236 'archivename' => $file->getArchiveName(),
237 'timestamp' => wfTimestamp( TS::ISO_8601, $file->getTimestamp() ),
238 'width' => $file->getWidth(),
239 'height' => $file->getHeight(),
240 'size' => $file->getSize(),
241 'userhidden' => (bool)$file->isDeleted( File::DELETED_USER ),
242 'commenthidden' => (bool)$file->isDeleted( File::DELETED_COMMENT ),
243 'contenthidden' => (bool)$this->isDeleted(),
244 ];
245 if ( !$this->isDeleted() ) {
246 $ret += [
247 'url' => $file->getUrl(),
248 ];
249 } elseif ( $this->canViewContent() ) {
250 $ret += [
251 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
252 [
253 'target' => $this->list->getPageName(),
254 'file' => $file->getArchiveName(),
255 'token' => $user->getEditToken( $file->getArchiveName() )
256 ]
257 ),
258 ];
259 }
260 $uploader = $file->getUploader( File::FOR_THIS_USER, $user );
261 if ( $uploader ) {
262 $ret += [
263 'userid' => $uploader->getId(),
264 'user' => $uploader->getName(),
265 ];
266 }
267 $comment = $file->getDescription( File::FOR_THIS_USER, $user );
268 if ( ( $comment ?? '' ) !== '' ) {
269 $ret += [
270 'comment' => $comment,
271 ];
272 }
273
274 return $ret;
275 }
276
278 public function lock() {
279 return $this->file->acquireFileLock();
280 }
281
283 public function unlock() {
284 return $this->file->releaseFileLock();
285 }
286}
287
289class_alias( RevDelFileItem::class, 'RevDelFileItem' );
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:34
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:79
getUrl()
Return the URL of the file.
Definition File.php:400
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:43
Some internal bits split of from Skin.php.
Definition Linker.php:47
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Item class for an oldimage table row.
getAuthorIdField()
Get the DB field name storing user ids.Override this function. string|false
canViewContent()
Returns true if the current user can view the item text/file.bool
unlock()
Unlock the item against changes outside of the DB.Status 1.28
getTimestampField()
Get the DB field name storing timestamps.Override this function. string|false
getApiData(ApiResult $result)
Get the return information about the revision for the API.1.23 array Data for the API result
__construct(RevisionListBase $list, $row)
getComment()
Wrap and format the file's comment block, if the current user is allowed to view it.
canView()
Returns true if the current user can view the item.bool
static initFile( $list, $row)
Create file object from $row sourced from $list.
getBits()
Get the current deletion bitfield value.int
getHTML()
Get the HTML of the list item.Should be include "<li></li>" tags. This is used to show the list in HT...
getId()
Get the ID, as it would appear in the ids URL parameter.int|string
getAuthorNameField()
Get the DB field name storing user names.Override this function. string|false
getAuthorActorField()
Get the DB field name storing actor ids.Override this function. 1.31 string|false
getUserTools()
Generate a user tool link cluster if the current user is allowed to view it.
lock()
Lock the item against changes outside of the DB.Status 1.28
setBits( $bits)
Set the visibility of the item.This should do any necessary DB queries.The DB update query should hav...
getIdField()
Get the DB field name associated with the ID list.Override this function. string|null
List for oldimage table items.
Abstract base class for deletable items.
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.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Provide primary and replica IDatabase connections.
element(SerializerNode $parent, SerializerNode $node, $contents)