MediaWiki  1.34.0
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 ) {
107  $file = $this->file;
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 }
RevDelArchivedFileItem\getId
getId()
Get the ID, as it would appear in the ids URL parameter.
Definition: RevDelArchivedFileItem.php:63
RevDelFileItem\$file
OldLocalFile $file
Definition: RevDelFileItem.php:31
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
RepoGroup\singleton
static singleton()
Definition: RepoGroup.php:60
LocalFile\getTimestamp
getTimestamp()
Definition: LocalFile.php:2119
RevDelArchivedFileItem\getAuthorActorField
getAuthorActorField()
Get the DB field name storing actor ids.
Definition: RevDelArchivedFileItem.php:59
LocalFile\getUser
getUser( $type='text')
Returns user who uploaded the file.
Definition: LocalFile.php:861
OldLocalFile\isDeleted
isDeleted( $field)
Definition: OldLocalFile.php:335
RevDelArchivedFileItem\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.
Definition: RevDelArchivedFileItem.php:47
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1869
LocalFile\getSize
getSize()
Returns the size of the image file, in bytes.
Definition: LocalFile.php:932
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:83
RevDelArchivedFileItem\getLink
getLink()
Get the link to the file.
Definition: RevDelArchivedFileItem.php:81
RevDelArchivedFileItem\unlock
unlock()
Unlock the item against changes outside of the DB.
Definition: RevDelArchivedFileItem.php:149
RevDelArchivedFileItem\lock
lock()
Lock the item against changes outside of the DB.
Definition: RevDelArchivedFileItem.php:145
RevDelArchivedFileItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevDelArchivedFileItem.php:51
RevDelArchivedFileItem\$lockFile
LocalFile $lockFile
Definition: RevDelArchivedFileItem.php:32
ApiResult
This class represents the result of the API operations.
Definition: ApiResult.php:35
RevisionItemBase\getLinkRenderer
getLinkRenderer()
Returns an instance of LinkRenderer.
Definition: RevisionItemBase.php:174
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2575
RevDelFileItem\isDeleted
isDeleted()
Definition: RevDelFileItem.php:126
RevDelArchivedFileItem\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevDelArchivedFileItem.php:43
DB_MASTER
const DB_MASTER
Definition: defines.php:26
LocalFile
Class to represent a local file in the wiki's own database.
Definition: LocalFile.php:56
RevDelArchivedFileItem
Definition: RevDelArchivedFileItem.php:30
RevDelArchivedFileItem\getApiData
getApiData(ApiResult $result)
Get the return information about the revision for the API.
Definition: RevDelArchivedFileItem.php:106
RevDelFileItem\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.
Definition: RevDelFileItem.php:79
RevisionItemBase\$row
$row
The database result row.
Definition: RevisionItemBase.php:33
RevDelFileItem
Item class for an oldimage table row.
Definition: RevDelFileItem.php:27
RevDelArchivedFileItem\setBits
setBits( $bits)
Set the visibility of the item.
Definition: RevDelArchivedFileItem.php:67
OldLocalFile\userCan
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this image file,...
Definition: OldLocalFile.php:359
RevDelArchivedFileItem\initFile
static initFile( $list, $row)
Create file object from $row sourced from $list.
Definition: RevDelArchivedFileItem.php:39
RevDelFileItem\$list
RevDelFileList $list
Definition: RevDelFileItem.php:29
LocalFile\getWidth
getWidth( $page=1)
Return the width of the image.
Definition: LocalFile.php:796
LocalFile\getHeight
getHeight( $page=1)
Return the height of the image.
Definition: LocalFile.php:828
RevDelArchivedFileItem\__construct
__construct( $list, $row)
Definition: RevDelArchivedFileItem.php:34
RevDelArchivedFileItem\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.
Definition: RevDelArchivedFileItem.php:55
ArchivedFile\newFromRow
static newFromRow( $row)
Loads a file object from the filearchive table.
Definition: ArchivedFile.php:212