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