MediaWiki master
RevDelFileItem.php
Go to the documentation of this file.
1<?php
28
34 protected $list;
36 protected $file;
38
39 public function __construct( RevisionListBase $list, $row ) {
40 parent::__construct( $list, $row );
41 $this->file = static::initFile( $list, $row );
42 $this->dbProvider = MediaWikiServices::getInstance()->getConnectionProvider();
43 }
44
52 protected static function initFile( $list, $row ) {
53 return MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
54 ->newFileFromRow( $row );
55 }
56
57 public function getIdField() {
58 return 'oi_archive_name';
59 }
60
61 public function getTimestampField() {
62 return 'oi_timestamp';
63 }
64
65 public function getAuthorIdField() {
66 return 'oi_user';
67 }
68
69 public function getAuthorNameField() {
70 return 'oi_user_text';
71 }
72
73 public function getAuthorActorField() {
74 return 'oi_actor';
75 }
76
77 public function getId() {
78 $parts = explode( '!', $this->row->oi_archive_name );
79
80 return $parts[0];
81 }
82
83 public function canView() {
84 return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getAuthority() );
85 }
86
87 public function canViewContent() {
88 return $this->file->userCan( File::DELETED_FILE, $this->list->getAuthority() );
89 }
90
91 public function getBits() {
92 return $this->file->getVisibility();
93 }
94
95 public function setBits( $bits ) {
96 # Queue the file op
97 # @todo FIXME: Move to LocalFile.php
98 if ( $this->isDeleted() ) {
99 if ( $bits & File::DELETED_FILE ) {
100 # Still deleted
101 } else {
102 # Newly undeleted
103 $key = $this->file->getStorageKey();
104 $srcRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
105 $this->list->storeBatch[] = [
106 $this->file->repo->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
107 'public',
108 $this->file->getRel()
109 ];
110 $this->list->cleanupBatch[] = $key;
111 }
112 } elseif ( $bits & File::DELETED_FILE ) {
113 # Newly deleted
114 $key = $this->file->getStorageKey();
115 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
116 $this->list->deleteBatch[] = [ $this->file->getRel(), $dstRel ];
117 }
118
119 # Do the database operations
120 $dbw = $this->dbProvider->getPrimaryDatabase();
121 $dbw->newUpdateQueryBuilder()
122 ->update( 'oldimage' )
123 ->set( [ 'oi_deleted' => $bits ] )
124 ->where( [
125 'oi_name' => $this->row->oi_name,
126 'oi_timestamp' => $this->row->oi_timestamp,
127 'oi_deleted' => $this->getBits()
128 ] )
129 ->caller( __METHOD__ )->execute();
130
131 return (bool)$dbw->affectedRows();
132 }
133
134 public function isDeleted() {
135 return $this->file->isDeleted( File::DELETED_FILE );
136 }
137
143 protected function getLink() {
144 $date = $this->list->getLanguage()->userTimeAndDate(
145 $this->file->getTimestamp(), $this->list->getUser() );
146
147 if ( !$this->isDeleted() ) {
148 # Regular files...
149 return Html::element( 'a', [ 'href' => $this->file->getUrl() ], $date );
150 }
151
152 # Hidden files...
153 if ( !$this->canViewContent() ) {
154 $link = htmlspecialchars( $date );
155 } else {
156 $link = $this->getLinkRenderer()->makeLink(
157 SpecialPage::getTitleFor( 'Revisiondelete' ),
158 $date,
159 [],
160 [
161 'target' => $this->list->getPageName(),
162 'file' => $this->file->getArchiveName(),
163 'token' => $this->list->getUser()->getEditToken(
164 $this->file->getArchiveName() )
165 ]
166 );
167 }
168
169 return '<span class="history-deleted">' . $link . '</span>';
170 }
171
176 protected function getUserTools() {
177 $uploader = $this->file->getUploader( File::FOR_THIS_USER, $this->list->getAuthority() );
178 if ( $uploader ) {
179 $link = Linker::userLink( $uploader->getId(), $uploader->getName() ) .
180 Linker::userToolLinks( $uploader->getId(), $uploader->getName() );
181 return $link;
182 } else {
183 $link = $this->list->msg( 'rev-deleted-user' )->escaped();
184 }
185 if ( $this->file->isDeleted( File::DELETED_USER ) ) {
186 return '<span class="history-deleted">' . $link . '</span>';
187 }
188 return $link;
189 }
190
197 protected function getComment() {
198 if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getAuthority() ) ) {
199 $block = MediaWikiServices::getInstance()->getCommentFormatter()
200 ->formatBlock( $this->file->getDescription() );
201 } else {
202 $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();
203 }
204 if ( $this->file->isDeleted( File::DELETED_COMMENT ) ) {
205 return "<span class=\"history-deleted\">$block</span>";
206 }
207
208 return $block;
209 }
210
211 public function getHTML() {
212 $data =
213 $this->list->msg( 'widthheight' )->numParams(
214 $this->file->getWidth(),
215 $this->file->getHeight() )->escaped() .
216 ' (' . $this->list->msg( 'nbytes' )->numParams(
217 $this->file->getSize() )->escaped() . ')';
218
219 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
220 $data . ' ' . $this->getComment() . '</li>';
221 }
222
223 public function getApiData( ApiResult $result ) {
225 $user = $this->list->getUser();
226 $ret = [
227 'title' => $this->list->getPageName(),
228 'archivename' => $file->getArchiveName(),
229 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
230 'width' => $file->getWidth(),
231 'height' => $file->getHeight(),
232 'size' => $file->getSize(),
233 'userhidden' => (bool)$file->isDeleted( File::DELETED_USER ),
234 'commenthidden' => (bool)$file->isDeleted( File::DELETED_COMMENT ),
235 'contenthidden' => (bool)$this->isDeleted(),
236 ];
237 if ( !$this->isDeleted() ) {
238 $ret += [
239 'url' => $file->getUrl(),
240 ];
241 } elseif ( $this->canViewContent() ) {
242 $ret += [
243 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
244 [
245 'target' => $this->list->getPageName(),
246 'file' => $file->getArchiveName(),
247 'token' => $user->getEditToken( $file->getArchiveName() )
248 ]
249 ),
250 ];
251 }
252 $uploader = $file->getUploader( File::FOR_THIS_USER, $user );
253 if ( $uploader ) {
254 $ret += [
255 'userid' => $uploader->getId(),
256 'user' => $uploader->getName(),
257 ];
258 }
259 $comment = $file->getDescription( File::FOR_THIS_USER, $user );
260 if ( ( $comment ?? '' ) !== '' ) {
261 $ret += [
262 'comment' => $comment,
263 ];
264 }
265
266 return $ret;
267 }
268
269 public function lock() {
270 return $this->file->acquireFileLock();
271 }
272
273 public function unlock() {
274 return $this->file->releaseFileLock();
275 }
276}
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:36
getUrl()
Return the URL of the file.
Definition File.php:395
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:56
Some internal bits split of from Skin.php.
Definition Linker.php:63
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.
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.
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.