MediaWiki master
RevDelArchivedFileItem.php
Go to the documentation of this file.
1<?php
15use Wikimedia\Timestamp\TimestampFormat as TS;
16
25 protected $lockFile;
26
28 public function __construct( RevisionListBase $list, $row ) {
29 parent::__construct( $list, $row );
30 $this->lockFile = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
31 ->newFile( $row->fa_name );
32 }
33
35 protected static function initFile( $list, $row ) {
36 return ArchivedFile::newFromRow( $row );
37 }
38
40 public function getIdField() {
41 return 'fa_id';
42 }
43
45 public function getTimestampField() {
46 return 'fa_timestamp';
47 }
48
50 public function getAuthorIdField() {
51 return 'fa_user';
52 }
53
55 public function getAuthorNameField() {
56 return 'fa_user_text';
57 }
58
60 public function getAuthorActorField() {
61 return 'fa_actor';
62 }
63
65 public function getId() {
66 return $this->row->fa_id;
67 }
68
70 public function setBits( $bits ) {
71 $dbw = $this->dbProvider->getPrimaryDatabase();
72 $dbw->newUpdateQueryBuilder()
73 ->update( 'filearchive' )
74 ->set( [ 'fa_deleted' => $bits ] )
75 ->where( [
76 'fa_id' => $this->row->fa_id,
77 'fa_deleted' => $this->getBits(),
78 ] )
79 ->caller( __METHOD__ )->execute();
80
81 return (bool)$dbw->affectedRows();
82 }
83
85 protected function getLink() {
86 $date = $this->list->getLanguage()->userTimeAndDate(
87 $this->file->getTimestamp(), $this->list->getUser() );
88
89 # Hidden files...
90 if ( !$this->canViewContent() ) {
91 $link = htmlspecialchars( $date );
92 } else {
93 $undelete = SpecialPage::getTitleFor( 'Undelete' );
94 $key = $this->file->getKey();
95 $link = $this->getLinkRenderer()->makeLink( $undelete, $date, [],
96 [
97 'target' => $this->list->getPageName(),
98 'file' => $key,
99 'token' => $this->list->getUser()->getEditToken( $key )
100 ]
101 );
102 }
103 if ( $this->isDeleted() ) {
104 $link = '<span class="history-deleted">' . $link . '</span>';
105 }
106
107 return $link;
108 }
109
111 public function getApiData( ApiResult $result ) {
113 $user = $this->list->getUser();
114 $ret = [
115 'title' => $this->list->getPageName(),
116 'timestamp' => wfTimestamp( TS::ISO_8601, $file->getTimestamp() ),
117 'width' => $file->getWidth(),
118 'height' => $file->getHeight(),
119 'size' => $file->getSize(),
120 'userhidden' => (bool)$file->isDeleted( File::DELETED_USER ),
121 'commenthidden' => (bool)$file->isDeleted( File::DELETED_COMMENT ),
122 'contenthidden' => (bool)$this->isDeleted(),
123 ];
124 if ( $this->canViewContent() ) {
125 $ret += [
126 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
127 [
128 'target' => $this->list->getPageName(),
129 'file' => $file->getKey(),
130 'token' => $user->getEditToken( $file->getKey() )
131 ]
132 ),
133 ];
134 }
135 $uploader = $file->getUploader( ArchivedFile::FOR_THIS_USER, $user );
136 if ( $uploader ) {
137 $ret += [
138 'userid' => $uploader->getId(),
139 'user' => $uploader->getName(),
140 ];
141 }
142 $comment = $file->getDescription( ArchivedFile::FOR_THIS_USER, $user );
143 if ( $comment !== '' ) {
144 $ret += [
145 'comment' => $comment,
146 ];
147 }
148
149 return $ret;
150 }
151
153 public function lock() {
154 return $this->lockFile->acquireFileLock();
155 }
156
158 public function unlock() {
159 return $this->lockFile->releaseFileLock();
160 }
161}
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:33
Deleted file in the 'filearchive' table.
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:79
Local file in the wiki's own database.
Definition LocalFile.php:81
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)
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.
static initFile( $list, $row)
Create file object from $row sourced from $list.mixed
getIdField()
Get the DB field name associated with the ID list.Override this function. string|null
getAuthorNameField()
Get the DB field name storing user names.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
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
setBits( $bits)
Set the visibility of the item.This should do any necessary DB queries.The DB update query should hav...
__construct(RevisionListBase $list, $row)
getLink()
Get the link to the file.Overridden by RevDelArchivedFileItem. string
lock()
Lock the item against changes outside of the DB.Status 1.28
getId()
Get the ID, as it would appear in the ids URL parameter.int|string
getAuthorActorField()
Get the DB field name storing actor ids.Override this function. 1.31 string|false
getAuthorIdField()
Get the DB field name storing user ids.Override this function. string|false
Item class for an oldimage table row.
RevDelFileList $list
canViewContent()
Returns true if the current user can view the item text/file.bool
OldLocalFile $file