MediaWiki REL1_40
RevDelFileItem.php
Go to the documentation of this file.
1<?php
26
32 protected $list;
34 protected $file;
35
36 public function __construct( RevisionListBase $list, $row ) {
37 parent::__construct( $list, $row );
38 $this->file = static::initFile( $list, $row );
39 }
40
48 protected static function initFile( $list, $row ) {
49 return MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
50 ->newFileFromRow( $row );
51 }
52
53 public function getIdField() {
54 return 'oi_archive_name';
55 }
56
57 public function getTimestampField() {
58 return 'oi_timestamp';
59 }
60
61 public function getAuthorIdField() {
62 return 'oi_user';
63 }
64
65 public function getAuthorNameField() {
66 return 'oi_user_text';
67 }
68
69 public function getAuthorActorField() {
70 return 'oi_actor';
71 }
72
73 public function getId() {
74 $parts = explode( '!', $this->row->oi_archive_name );
75
76 return $parts[0];
77 }
78
79 public function canView() {
80 return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getAuthority() );
81 }
82
83 public function canViewContent() {
84 return $this->file->userCan( File::DELETED_FILE, $this->list->getAuthority() );
85 }
86
87 public function getBits() {
88 return $this->file->getVisibility();
89 }
90
91 public function setBits( $bits ) {
92 # Queue the file op
93 # @todo FIXME: Move to LocalFile.php
94 if ( $this->isDeleted() ) {
95 if ( $bits & File::DELETED_FILE ) {
96 # Still deleted
97 } else {
98 # Newly undeleted
99 $key = $this->file->getStorageKey();
100 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
101 $this->list->storeBatch[] = [
102 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
103 'public',
104 $this->file->getRel()
105 ];
106 $this->list->cleanupBatch[] = $key;
107 }
108 } elseif ( $bits & File::DELETED_FILE ) {
109 # Newly deleted
110 $key = $this->file->getStorageKey();
111 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
112 $this->list->deleteBatch[] = [ $this->file->getRel(), $dstRel ];
113 }
114
115 # Do the database operations
116 $dbw = wfGetDB( DB_PRIMARY );
117 $dbw->update( 'oldimage',
118 [ 'oi_deleted' => $bits ],
119 [
120 'oi_name' => $this->row->oi_name,
121 'oi_timestamp' => $this->row->oi_timestamp,
122 'oi_deleted' => $this->getBits()
123 ],
124 __METHOD__
125 );
126
127 return (bool)$dbw->affectedRows();
128 }
129
130 public function isDeleted() {
131 return $this->file->isDeleted( File::DELETED_FILE );
132 }
133
139 protected function getLink() {
140 $date = $this->list->getLanguage()->userTimeAndDate(
141 $this->file->getTimestamp(), $this->list->getUser() );
142
143 if ( !$this->isDeleted() ) {
144 # Regular files...
145 return Html::element( 'a', [ 'href' => $this->file->getUrl() ], $date );
146 }
147
148 # Hidden files...
149 if ( !$this->canViewContent() ) {
150 $link = htmlspecialchars( $date );
151 } else {
152 $link = $this->getLinkRenderer()->makeLink(
153 SpecialPage::getTitleFor( 'Revisiondelete' ),
154 $date,
155 [],
156 [
157 'target' => $this->list->getPageName(),
158 'file' => $this->file->getArchiveName(),
159 'token' => $this->list->getUser()->getEditToken(
160 $this->file->getArchiveName() )
161 ]
162 );
163 }
164
165 return '<span class="history-deleted">' . $link . '</span>';
166 }
167
172 protected function getUserTools() {
173 $uploader = $this->file->getUploader( File::FOR_THIS_USER, $this->list->getAuthority() );
174 if ( $uploader ) {
175 $link = Linker::userLink( $uploader->getId(), $uploader->getName() ) .
176 Linker::userToolLinks( $uploader->getId(), $uploader->getName() );
177 return $link;
178 } else {
179 $link = $this->list->msg( 'rev-deleted-user' )->escaped();
180 }
181 if ( $this->file->isDeleted( File::DELETED_USER ) ) {
182 return '<span class="history-deleted">' . $link . '</span>';
183 }
184 return $link;
185 }
186
193 protected function getComment() {
194 if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getAuthority() ) ) {
195 $block = MediaWikiServices::getInstance()->getCommentFormatter()
196 ->formatBlock( $this->file->getDescription() );
197 } else {
198 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
199 }
200 if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
201 return "<span class=\"history-deleted\">$block</span>";
202 }
203
204 return $block;
205 }
206
207 public function getHTML() {
208 $data =
209 $this->list->msg( 'widthheight' )->numParams(
210 $this->file->getWidth(),
211 $this->file->getHeight() )->escaped() .
212 ' (' . $this->list->msg( 'nbytes' )->numParams(
213 $this->file->getSize() )->escaped() . ')';
214
215 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
216 $data . ' ' . $this->getComment() . '</li>';
217 }
218
219 public function getApiData( ApiResult $result ) {
221 $user = $this->list->getUser();
222 $ret = [
223 'title' => $this->list->getPageName(),
224 'archivename' => $file->getArchiveName(),
225 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
226 'width' => $file->getWidth(),
227 'height' => $file->getHeight(),
228 'size' => $file->getSize(),
229 'userhidden' => (bool)$file->isDeleted( RevisionRecord::DELETED_USER ),
230 'commenthidden' => (bool)$file->isDeleted( RevisionRecord::DELETED_COMMENT ),
231 'contenthidden' => (bool)$this->isDeleted(),
232 ];
233 if ( !$this->isDeleted() ) {
234 $ret += [
235 'url' => $file->getUrl(),
236 ];
237 } elseif ( $this->canViewContent() ) {
238 $ret += [
239 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
240 [
241 'target' => $this->list->getPageName(),
242 'file' => $file->getArchiveName(),
243 'token' => $user->getEditToken( $file->getArchiveName() )
244 ]
245 ),
246 ];
247 }
248 $uploader = $file->getUploader( File::FOR_THIS_USER, $user );
249 if ( $uploader ) {
250 $ret += [
251 'userid' => $uploader->getId(),
252 'user' => $uploader->getName(),
253 ];
254 }
255 $comment = $file->getDescription( File::FOR_THIS_USER, $user );
256 if ( ( $comment ?? '' ) !== '' ) {
257 $ret += [
258 'comment' => $comment,
259 ];
260 }
261
262 return $ret;
263 }
264
265 public function lock() {
266 return $this->file->acquireFileLock();
267 }
268
269 public function unlock() {
270 return $this->file->releaseFileLock();
271 }
272}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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:35
getUrl()
Return the URL of the file.
Definition File.php:387
getWidth( $page=1)
Return the width of the image.
getUploader(int $audience=self::FOR_PUBLIC, Authority $performer=null)
getSize()
Returns the size of the image file, in bytes.
getDescription( $audience=self::FOR_PUBLIC, Authority $performer=null)
getHeight( $page=1)
Return the height of the image.
This class is a collection of static functions that serve two purposes:
Definition Html.php:55
Some internal bits split of from Skin.php.
Definition Linker.php:67
Service locator for MediaWiki core services.
Page revision base class.
Old file in the oldimage table.
isDeleted( $field)
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.
__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.
stdClass $row
The database result row.
getLinkRenderer()
Returns an instance of LinkRenderer.
List for revision table items for a single page.
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,...
const DB_PRIMARY
Definition defines.php:28