MediaWiki master
RevDelFileItem.php
Go to the documentation of this file.
1<?php
9
20use Wikimedia\Timestamp\TimestampFormat as TS;
21
27 protected $list;
29 protected $file;
31
33 public function __construct( RevisionListBase $list, $row ) {
34 parent::__construct( $list, $row );
35 $this->file = static::initFile( $list, $row );
36 $this->dbProvider = MediaWikiServices::getInstance()->getConnectionProvider();
37 }
38
46 protected static function initFile( $list, $row ) {
47 return MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
48 ->newFileFromRow( $row );
49 }
50
52 public function getIdField() {
53 return 'oi_archive_name';
54 }
55
57 public function getTimestampField() {
58 return 'oi_timestamp';
59 }
60
62 public function getAuthorIdField() {
63 return 'oi_user';
64 }
65
67 public function getAuthorNameField() {
68 return 'oi_user_text';
69 }
70
72 public function getAuthorActorField() {
73 return 'oi_actor';
74 }
75
77 public function getId() {
78 $parts = explode( '!', $this->row->oi_archive_name );
79
80 return $parts[0];
81 }
82
84 public function canView() {
85 return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getAuthority() );
86 }
87
89 public function canViewContent() {
90 return $this->file->userCan( File::DELETED_FILE, $this->list->getAuthority() );
91 }
92
94 public function getBits() {
95 return $this->file->getVisibility();
96 }
97
99 public function setBits( $bits ) {
100 # Queue the file op
101 # @todo FIXME: Move to LocalFile.php
102 if ( $this->isDeleted() ) {
103 if ( $bits & File::DELETED_FILE ) {
104 # Still deleted
105 } else {
106 # Newly undeleted
107 $key = $this->file->getStorageKey();
108 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
109 $this->list->storeBatch[] = [
110 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
111 'public',
112 $this->file->getRel()
113 ];
114 $this->list->cleanupBatch[] = $key;
115 }
116 } elseif ( $bits & File::DELETED_FILE ) {
117 # Newly deleted
118 $key = $this->file->getStorageKey();
119 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
120 $this->list->deleteBatch[] = [ $this->file->getRel(), $dstRel ];
121 }
122
123 // Do the database operations
124 $dbw = $this->dbProvider->getPrimaryDatabase();
125 $migrationStage = MediaWikiServices::getInstance()->getMainConfig()->get(
127 );
128 if ( $migrationStage & SCHEMA_COMPAT_WRITE_OLD ) {
129 $dbw->newUpdateQueryBuilder()
130 ->update( 'oldimage' )
131 ->set( [ 'oi_deleted' => $bits ] )
132 ->where( [
133 'oi_name' => $this->row->oi_name,
134 'oi_timestamp' => $this->row->oi_timestamp,
135 'oi_deleted' => $this->getBits()
136 ] )
137 ->caller( __METHOD__ )->execute();
138 }
139 if ( $migrationStage & SCHEMA_COMPAT_WRITE_NEW ) {
140 $dbw->newUpdateQueryBuilder()
141 ->update( 'filerevision' )
142 ->set( [ 'fr_deleted' => $bits ] )
143 ->where( [
144 'fr_file' => $this->file->getFileIdFromName(),
145 'fr_timestamp' => $this->row->oi_timestamp,
146 'fr_deleted' => $this->getBits()
147 ] )
148 ->caller( __METHOD__ )->execute();
149 }
150
151 return (bool)$dbw->affectedRows();
152 }
153
157 public function isDeleted() {
158 return $this->file->isDeleted( File::DELETED_FILE );
159 }
160
166 protected function getLink() {
167 $date = $this->list->getLanguage()->userTimeAndDate(
168 $this->file->getTimestamp(), $this->list->getUser() );
169
170 if ( !$this->isDeleted() ) {
171 # Regular files...
172 return Html::element( 'a', [ 'href' => $this->file->getUrl() ], $date );
173 }
174
175 # Hidden files...
176 if ( !$this->canViewContent() ) {
177 $link = htmlspecialchars( $date );
178 } else {
179 $link = $this->getLinkRenderer()->makeLink(
180 SpecialPage::getTitleFor( 'Revisiondelete' ),
181 $date,
182 [],
183 [
184 'target' => $this->list->getPageName(),
185 'file' => $this->file->getArchiveName(),
186 'token' => $this->list->getUser()->getEditToken(
187 $this->file->getArchiveName() )
188 ]
189 );
190 }
191
192 return '<span class="history-deleted">' . $link . '</span>';
193 }
194
199 protected function getUserTools() {
200 $uploader = $this->file->getUploader( File::FOR_THIS_USER, $this->list->getAuthority() );
201 if ( $uploader ) {
202 $link = Linker::userLink( $uploader->getId(), $uploader->getName() ) .
203 Linker::userToolLinks( $uploader->getId(), $uploader->getName() );
204 return $link;
205 } else {
206 $link = $this->list->msg( 'rev-deleted-user' )->escaped();
207 }
208 if ( $this->file->isDeleted( File::DELETED_USER ) ) {
209 return '<span class="history-deleted">' . $link . '</span>';
210 }
211 return $link;
212 }
213
220 protected function getComment() {
221 if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getAuthority() ) ) {
222 $block = MediaWikiServices::getInstance()->getCommentFormatter()
223 ->formatBlock( $this->file->getDescription() );
224 } else {
225 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
226 }
227 if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
228 return "<span class=\"history-deleted\">$block</span>";
229 }
230
231 return $block;
232 }
233
235 public function getHTML() {
236 $data =
237 $this->list->msg( 'widthheight' )->numParams(
238 $this->file->getWidth(),
239 $this->file->getHeight() )->escaped() .
240 ' (' . $this->list->msg( 'nbytes' )->numParams(
241 $this->file->getSize() )->escaped() . ')';
242
243 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
244 $data . ' ' . $this->getComment() . '</li>';
245 }
246
248 public function getApiData( ApiResult $result ) {
250 $user = $this->list->getUser();
251 $ret = [
252 'title' => $this->list->getPageName(),
253 'archivename' => $file->getArchiveName(),
254 'timestamp' => wfTimestamp( TS::ISO_8601, $file->getTimestamp() ),
255 'width' => $file->getWidth(),
256 'height' => $file->getHeight(),
257 'size' => $file->getSize(),
258 'userhidden' => (bool)$file->isDeleted( File::DELETED_USER ),
259 'commenthidden' => (bool)$file->isDeleted( File::DELETED_COMMENT ),
260 'contenthidden' => (bool)$this->isDeleted(),
261 ];
262 if ( !$this->isDeleted() ) {
263 $ret += [
264 'url' => $file->getUrl(),
265 ];
266 } elseif ( $this->canViewContent() ) {
267 $ret += [
268 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
269 [
270 'target' => $this->list->getPageName(),
271 'file' => $file->getArchiveName(),
272 'token' => $user->getEditToken( $file->getArchiveName() )
273 ]
274 ),
275 ];
276 }
277 $uploader = $file->getUploader( File::FOR_THIS_USER, $user );
278 if ( $uploader ) {
279 $ret += [
280 'userid' => $uploader->getId(),
281 'user' => $uploader->getName(),
282 ];
283 }
284 $comment = $file->getDescription( File::FOR_THIS_USER, $user );
285 if ( ( $comment ?? '' ) !== '' ) {
286 $ret += [
287 'comment' => $comment,
288 ];
289 }
290
291 return $ret;
292 }
293
295 public function lock() {
296 return $this->file->acquireFileLock();
297 }
298
300 public function unlock() {
301 return $this->file->releaseFileLock();
302 }
303}
304
306class_alias( RevDelFileItem::class, 'RevDelFileItem' );
const SCHEMA_COMPAT_WRITE_OLD
Definition Defines.php:293
const SCHEMA_COMPAT_WRITE_NEW
Definition Defines.php:297
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:80
getUrl()
Return the URL to the original file.
Definition File.php:401
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:44
Some internal bits split of from Skin.php.
Definition Linker.php:48
A class containing constants representing the names of configuration variables.
const FileSchemaMigrationStage
Name constant for the FileSchemaMigrationStage setting, for use with Config::get()
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)