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_PRIMARY );
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->getPageName(),
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->getPageName(),
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->getPageName(),
126  'file' => $file->getKey(),
127  'token' => $user->getEditToken( $file->getKey() )
128  ]
129  ),
130  ];
131  }
132  $uploader = $file->getUploader( ArchivedFile::FOR_THIS_USER, $user );
133  if ( $uploader ) {
134  $ret += [
135  'userid' => $uploader->getId(),
136  'user' => $uploader->getName(),
137  ];
138  }
139  $comment = $file->getDescription( ArchivedFile::FOR_THIS_USER, $user );
140  if ( $comment ) {
141  $ret += [
142  'comment' => $comment,
143  ];
144  }
145 
146  return $ret;
147  }
148 
149  public function lock() {
150  return $this->lockFile->acquireFileLock();
151  }
152 
153  public function unlock() {
154  return $this->lockFile->releaseFileLock();
155  }
156 }
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
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
LocalFile\getTimestamp
getTimestamp()
Definition: LocalFile.php:2605
RevDelArchivedFileItem\getAuthorActorField
getAuthorActorField()
Get the DB field name storing actor ids.
Definition: RevDelArchivedFileItem.php:61
RevisionListBase
List for revision table items for a single page.
Definition: RevisionListBase.php:30
OldLocalFile\isDeleted
isDeleted( $field)
Definition: OldLocalFile.php:391
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:193
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:1668
File\getUser
getUser( $type='text')
Returns ID or name of user who uploaded the file STUB.
Definition: File.php:614
LocalFile\getSize
getSize()
Returns the size of the image file, in bytes.
Definition: LocalFile.php:1340
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:107
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:153
RevDelArchivedFileItem\lock
lock()
Lock the item against changes outside of the DB.
Definition: RevDelArchivedFileItem.php:149
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:178
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2202
RevDelFileItem\isDeleted
isDeleted()
Definition: RevDelFileItem.php:128
RevDelArchivedFileItem\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevDelArchivedFileItem.php:45
LocalFile
Class to represent a local file in the wiki's own database.
Definition: LocalFile.php:63
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
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
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
LocalFile\getDescription
getDescription( $audience=self::FOR_PUBLIC, Authority $performer=null)
Definition: LocalFile.php:2590
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
LocalFile\getUploader
getUploader(int $audience=self::FOR_PUBLIC, Authority $performer=null)
Definition: LocalFile.php:2573
RevDelFileItem\$list
RevDelFileList $list
Definition: RevDelFileItem.php:30
LocalFile\getWidth
getWidth( $page=1)
Return the width of the image @stable to override.
Definition: LocalFile.php:968
RevisionItemBase\$row
stdClass $row
The database result row.
Definition: RevisionItemBase.php:34
LocalFile\getHeight
getHeight( $page=1)
Return the height of the image @stable to override.
Definition: LocalFile.php:1001
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:225
ArchivedFile\FOR_THIS_USER
const FOR_THIS_USER
Definition: ArchivedFile.php:39