MediaWiki  master
RevDelArchivedFileItem.php
Go to the documentation of this file.
1 <?php
24 
33  protected $lockFile;
34 
35  public function __construct( RevisionListBase $list, $row ) {
36  parent::__construct( $list, $row );
37  $this->lockFile = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
38  ->newFile( $row->fa_name );
39  }
40 
41  protected static function initFile( $list, $row ) {
43  }
44 
45  public function getIdField() {
46  return 'fa_id';
47  }
48 
49  public function getTimestampField() {
50  return 'fa_timestamp';
51  }
52 
53  public function getAuthorIdField() {
54  return 'fa_user';
55  }
56 
57  public function getAuthorNameField() {
58  return 'fa_user_text';
59  }
60 
61  public function getAuthorActorField() {
62  return 'fa_actor';
63  }
64 
65  public function getId() {
66  return $this->row->fa_id;
67  }
68 
69  public function setBits( $bits ) {
70  $dbw = wfGetDB( DB_MASTER );
71  $dbw->update( 'filearchive',
72  [ 'fa_deleted' => $bits ],
73  [
74  'fa_id' => $this->row->fa_id,
75  'fa_deleted' => $this->getBits(),
76  ],
77  __METHOD__
78  );
79 
80  return (bool)$dbw->affectedRows();
81  }
82 
83  protected function getLink() {
84  $date = $this->list->getLanguage()->userTimeAndDate(
85  $this->file->getTimestamp(), $this->list->getUser() );
86 
87  # Hidden files...
88  if ( !$this->canViewContent() ) {
89  $link = htmlspecialchars( $date );
90  } else {
91  $undelete = SpecialPage::getTitleFor( 'Undelete' );
92  $key = $this->file->getKey();
93  $link = $this->getLinkRenderer()->makeLink( $undelete, $date, [],
94  [
95  'target' => $this->list->title->getPrefixedText(),
96  'file' => $key,
97  'token' => $this->list->getUser()->getEditToken( $key )
98  ]
99  );
100  }
101  if ( $this->isDeleted() ) {
102  $link = '<span class="history-deleted">' . $link . '</span>';
103  }
104 
105  return $link;
106  }
107 
108  public function getApiData( ApiResult $result ) {
109  $file = $this->file;
110  $user = $this->list->getUser();
111  $ret = [
112  'title' => $this->list->title->getPrefixedText(),
113  'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
114  'width' => $file->getWidth(),
115  'height' => $file->getHeight(),
116  'size' => $file->getSize(),
117  'userhidden' => (bool)$file->isDeleted( RevisionRecord::DELETED_USER ),
118  'commenthidden' => (bool)$file->isDeleted( RevisionRecord::DELETED_COMMENT ),
119  'contenthidden' => (bool)$this->isDeleted(),
120  ];
121  if ( $this->canViewContent() ) {
122  $ret += [
123  'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
124  [
125  'target' => $this->list->title->getPrefixedText(),
126  'file' => $file->getKey(),
127  'token' => $user->getEditToken( $file->getKey() )
128  ]
129  ),
130  ];
131  }
132  if ( $file->userCan( RevisionRecord::DELETED_USER, $user ) ) {
133  $ret += [
134  'userid' => $file->getUser( 'id' ),
135  'user' => $file->getUser( 'text' ),
136  ];
137  }
138  if ( $file->userCan( RevisionRecord::DELETED_COMMENT, $user ) ) {
139  $ret += [
140  'comment' => $file->getRawDescription(),
141  ];
142  }
143 
144  return $ret;
145  }
146 
147  public function lock() {
148  return $this->lockFile->acquireFileLock();
149  }
150 
151  public function unlock() {
152  return $this->lockFile->releaseFileLock();
153  }
154 }
RevDelArchivedFileItem\getId
getId()
Get the ID, as it would appear in the ids URL parameter.
Definition: RevDelArchivedFileItem.php:65
RevDelFileItem\$file
OldLocalFile $file
Definition: RevDelFileItem.php:32
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
LocalFile\getTimestamp
getTimestamp()
Definition: LocalFile.php:2255
RevDelArchivedFileItem\getAuthorActorField
getAuthorActorField()
Get the DB field name storing actor ids.
Definition: RevDelArchivedFileItem.php:61
LocalFile\getUser
getUser( $type='text')
Returns user who uploaded the file.
Definition: LocalFile.php:870
RevisionListBase
List for revision table items for a single page.
Definition: RevisionListBase.php:29
OldLocalFile\isDeleted
isDeleted( $field)
Definition: OldLocalFile.php:335
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:152
RevDelArchivedFileItem\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.
Definition: RevDelArchivedFileItem.php:49
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1811
LocalFile\getSize
getSize()
Returns the size of the image file, in bytes.
Definition: LocalFile.php:940
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:90
RevDelArchivedFileItem\getLink
getLink()
Get the link to the file.
Definition: RevDelArchivedFileItem.php:83
RevDelArchivedFileItem\unlock
unlock()
Unlock the item against changes outside of the DB.
Definition: RevDelArchivedFileItem.php:151
RevDelArchivedFileItem\lock
lock()
Lock the item against changes outside of the DB.
Definition: RevDelArchivedFileItem.php:147
RevDelArchivedFileItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevDelArchivedFileItem.php:53
RevDelArchivedFileItem\$lockFile
LocalFile $lockFile
Definition: RevDelArchivedFileItem.php:33
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:2464
RevDelFileItem\isDeleted
isDeleted()
Definition: RevDelFileItem.php:128
RevDelArchivedFileItem\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevDelArchivedFileItem.php:45
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:58
RevDelArchivedFileItem
Definition: RevDelArchivedFileItem.php:31
RevDelArchivedFileItem\getApiData
getApiData(ApiResult $result)
Get the return information about the revision for the API.
Definition: RevDelArchivedFileItem.php:108
RevDelFileItem\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.
Definition: RevDelFileItem.php:81
RevisionItemBase\$row
$row
The database result row.
Definition: RevisionItemBase.php:33
RevDelFileItem
Item class for an oldimage table row.
Definition: RevDelFileItem.php:28
RevDelArchivedFileItem\setBits
setBits( $bits)
Set the visibility of the item.
Definition: RevDelArchivedFileItem.php:69
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:41
RevDelArchivedFileItem\__construct
__construct(RevisionListBase $list, $row)
Definition: RevDelArchivedFileItem.php:35
RevDelFileItem\$list
RevDelFileList $list
Definition: RevDelFileItem.php:30
LocalFile\getWidth
getWidth( $page=1)
Return the width of the image.
Definition: LocalFile.php:805
LocalFile\getHeight
getHeight( $page=1)
Return the height of the image.
Definition: LocalFile.php:837
RevDelArchivedFileItem\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.
Definition: RevDelArchivedFileItem.php:57
ArchivedFile\newFromRow
static newFromRow( $row)
Loads a file object from the filearchive table.
Definition: ArchivedFile.php:213