MediaWiki master
RevDelArchivedFileItem.php
Go to the documentation of this file.
1<?php
29
38 protected $lockFile;
39
40 public function __construct( RevisionListBase $list, $row ) {
41 parent::__construct( $list, $row );
42 $this->lockFile = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
43 ->newFile( $row->fa_name );
44 }
45
46 protected static function initFile( $list, $row ) {
47 return ArchivedFile::newFromRow( $row );
48 }
49
50 public function getIdField() {
51 return 'fa_id';
52 }
53
54 public function getTimestampField() {
55 return 'fa_timestamp';
56 }
57
58 public function getAuthorIdField() {
59 return 'fa_user';
60 }
61
62 public function getAuthorNameField() {
63 return 'fa_user_text';
64 }
65
66 public function getAuthorActorField() {
67 return 'fa_actor';
68 }
69
70 public function getId() {
71 return $this->row->fa_id;
72 }
73
74 public function setBits( $bits ) {
75 $dbw = $this->dbProvider->getPrimaryDatabase();
76 $dbw->newUpdateQueryBuilder()
77 ->update( 'filearchive' )
78 ->set( [ 'fa_deleted' => $bits ] )
79 ->where( [
80 'fa_id' => $this->row->fa_id,
81 'fa_deleted' => $this->getBits(),
82 ] )
83 ->caller( __METHOD__ )->execute();
84
85 return (bool)$dbw->affectedRows();
86 }
87
88 protected function getLink() {
89 $date = $this->list->getLanguage()->userTimeAndDate(
90 $this->file->getTimestamp(), $this->list->getUser() );
91
92 # Hidden files...
93 if ( !$this->canViewContent() ) {
94 $link = htmlspecialchars( $date );
95 } else {
96 $undelete = SpecialPage::getTitleFor( 'Undelete' );
97 $key = $this->file->getKey();
98 $link = $this->getLinkRenderer()->makeLink( $undelete, $date, [],
99 [
100 'target' => $this->list->getPageName(),
101 'file' => $key,
102 'token' => $this->list->getUser()->getEditToken( $key )
103 ]
104 );
105 }
106 if ( $this->isDeleted() ) {
107 $link = '<span class="history-deleted">' . $link . '</span>';
108 }
109
110 return $link;
111 }
112
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
154 public function lock() {
155 return $this->lockFile->acquireFileLock();
156 }
157
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:43
Deleted file in the 'filearchive' table.
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:93
Local file in the wiki's own database.
Definition LocalFile.php:93
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.
getIdField()
Get the DB field name associated with the ID list.
getAuthorNameField()
Get the DB field name storing user names.
getApiData(ApiResult $result)
Get the return information about the revision for the API.
unlock()
Unlock the item against changes outside of the DB.
getTimestampField()
Get the DB field name storing timestamps.
setBits( $bits)
Set the visibility of the item.
__construct(RevisionListBase $list, $row)
getLink()
Get the link to the file.
lock()
Lock the item against changes outside of the DB.
getId()
Get the ID, as it would appear in the ids URL parameter.
getAuthorActorField()
Get the DB field name storing actor ids.
getAuthorIdField()
Get the DB field name storing user ids.
Item class for an oldimage table row.
RevDelFileList $list
canViewContent()
Returns true if the current user can view the item text/file.
OldLocalFile $file