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