MediaWiki REL1_34
RevDelArchivedFileItem.php
Go to the documentation of this file.
1<?php
23
32 protected $lockFile;
33
34 public function __construct( $list, $row ) {
35 parent::__construct( $list, $row );
36 $this->lockFile = RepoGroup::singleton()->getLocalRepo()->newFile( $row->fa_name );
37 }
38
39 protected static function initFile( $list, $row ) {
41 }
42
43 public function getIdField() {
44 return 'fa_id';
45 }
46
47 public function getTimestampField() {
48 return 'fa_timestamp';
49 }
50
51 public function getAuthorIdField() {
52 return 'fa_user';
53 }
54
55 public function getAuthorNameField() {
56 return 'fa_user_text';
57 }
58
59 public function getAuthorActorField() {
60 return 'fa_actor';
61 }
62
63 public function getId() {
64 return $this->row->fa_id;
65 }
66
67 public function setBits( $bits ) {
68 $dbw = wfGetDB( DB_MASTER );
69 $dbw->update( 'filearchive',
70 [ 'fa_deleted' => $bits ],
71 [
72 'fa_id' => $this->row->fa_id,
73 'fa_deleted' => $this->getBits(),
74 ],
75 __METHOD__
76 );
77
78 return (bool)$dbw->affectedRows();
79 }
80
81 protected function getLink() {
82 $date = $this->list->getLanguage()->userTimeAndDate(
83 $this->file->getTimestamp(), $this->list->getUser() );
84
85 # Hidden files...
86 if ( !$this->canViewContent() ) {
87 $link = htmlspecialchars( $date );
88 } else {
89 $undelete = SpecialPage::getTitleFor( 'Undelete' );
90 $key = $this->file->getKey();
91 $link = $this->getLinkRenderer()->makeLink( $undelete, $date, [],
92 [
93 'target' => $this->list->title->getPrefixedText(),
94 'file' => $key,
95 'token' => $this->list->getUser()->getEditToken( $key )
96 ]
97 );
98 }
99 if ( $this->isDeleted() ) {
100 $link = '<span class="history-deleted">' . $link . '</span>';
101 }
102
103 return $link;
104 }
105
106 public function getApiData( ApiResult $result ) {
108 $user = $this->list->getUser();
109 $ret = [
110 'title' => $this->list->title->getPrefixedText(),
111 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
112 'width' => $file->getWidth(),
113 'height' => $file->getHeight(),
114 'size' => $file->getSize(),
115 'userhidden' => (bool)$file->isDeleted( RevisionRecord::DELETED_USER ),
116 'commenthidden' => (bool)$file->isDeleted( RevisionRecord::DELETED_COMMENT ),
117 'contenthidden' => (bool)$this->isDeleted(),
118 ];
119 if ( $this->canViewContent() ) {
120 $ret += [
121 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
122 [
123 'target' => $this->list->title->getPrefixedText(),
124 'file' => $file->getKey(),
125 'token' => $user->getEditToken( $file->getKey() )
126 ]
127 ),
128 ];
129 }
130 if ( $file->userCan( RevisionRecord::DELETED_USER, $user ) ) {
131 $ret += [
132 'userid' => $file->getUser( 'id' ),
133 'user' => $file->getUser( 'text' ),
134 ];
135 }
136 if ( $file->userCan( RevisionRecord::DELETED_COMMENT, $user ) ) {
137 $ret += [
138 'comment' => $file->getRawDescription(),
139 ];
140 }
141
142 return $ret;
143 }
144
145 public function lock() {
146 return $this->lockFile->acquireFileLock();
147 }
148
149 public function unlock() {
150 return $this->lockFile->releaseFileLock();
151 }
152}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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
static newFromRow( $row)
Loads a file object from the filearchive table.
Class to represent a local file in the wiki's own database.
Definition LocalFile.php:56
getWidth( $page=1)
Return the width of the image.
getUser( $type='text')
Returns user who uploaded the file.
getSize()
Returns the size of the image file, in bytes.
getHeight( $page=1)
Return the height of the image.
Page revision base class.
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this image file,...
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.
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
$row
The database result row.
getLinkRenderer()
Returns an instance of LinkRenderer.
const DB_MASTER
Definition defines.php:26