MediaWiki master
RevDelArchivedFileItem.php
Go to the documentation of this file.
1<?php
26
35 protected $lockFile;
36
37 public function __construct( RevisionListBase $list, $row ) {
38 parent::__construct( $list, $row );
39 $this->lockFile = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
40 ->newFile( $row->fa_name );
41 }
42
43 protected static function initFile( $list, $row ) {
44 return ArchivedFile::newFromRow( $row );
45 }
46
47 public function getIdField() {
48 return 'fa_id';
49 }
50
51 public function getTimestampField() {
52 return 'fa_timestamp';
53 }
54
55 public function getAuthorIdField() {
56 return 'fa_user';
57 }
58
59 public function getAuthorNameField() {
60 return 'fa_user_text';
61 }
62
63 public function getAuthorActorField() {
64 return 'fa_actor';
65 }
66
67 public function getId() {
68 return $this->row->fa_id;
69 }
70
71 public function setBits( $bits ) {
72 $dbw = $this->dbProvider->getPrimaryDatabase();
73 $dbw->newUpdateQueryBuilder()
74 ->update( 'filearchive' )
75 ->set( [ 'fa_deleted' => $bits ] )
76 ->where( [
77 'fa_id' => $this->row->fa_id,
78 'fa_deleted' => $this->getBits(),
79 ] )
80 ->caller( __METHOD__ )->execute();
81
82 return (bool)$dbw->affectedRows();
83 }
84
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
110 public function getApiData( ApiResult $result ) {
112 $user = $this->list->getUser();
113 $ret = [
114 'title' => $this->list->getPageName(),
115 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
116 'width' => $file->getWidth(),
117 'height' => $file->getHeight(),
118 'size' => $file->getSize(),
119 'userhidden' => (bool)$file->isDeleted( File::DELETED_USER ),
120 'commenthidden' => (bool)$file->isDeleted( File::DELETED_COMMENT ),
121 'contenthidden' => (bool)$this->isDeleted(),
122 ];
123 if ( $this->canViewContent() ) {
124 $ret += [
125 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
126 [
127 'target' => $this->list->getPageName(),
128 'file' => $file->getKey(),
129 'token' => $user->getEditToken( $file->getKey() )
130 ]
131 ),
132 ];
133 }
134 $uploader = $file->getUploader( ArchivedFile::FOR_THIS_USER, $user );
135 if ( $uploader ) {
136 $ret += [
137 'userid' => $uploader->getId(),
138 'user' => $uploader->getName(),
139 ];
140 }
141 $comment = $file->getDescription( ArchivedFile::FOR_THIS_USER, $user );
142 if ( $comment !== '' ) {
143 $ret += [
144 'comment' => $comment,
145 ];
146 }
147
148 return $ret;
149 }
150
151 public function lock() {
152 return $this->lockFile->acquireFileLock();
153 }
154
155 public function unlock() {
156 return $this->lockFile->releaseFileLock();
157 }
158}
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Local file in the wiki's own database.
Definition LocalFile.php:75
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
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.
isDeleted( $field)
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