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