MediaWiki  master
RevDelArchivedFileItem.php
Go to the documentation of this file.
1 <?php
23 
32  protected $lockFile;
33 
34  public function __construct( RevisionListBase $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 }
static newFromRow( $row)
Loads a file object from the filearchive table.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
getSize()
Returns the size of the image file, in bytes.
Definition: LocalFile.php:932
Item class for an oldimage table row.
static initFile( $list, $row)
__construct(RevisionListBase $list, $row)
const DB_MASTER
Definition: defines.php:26
List for revision table items for a single page.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this image file...
$row
The database result row.
static singleton()
Definition: RepoGroup.php:60
This class represents the result of the API operations.
Definition: ApiResult.php:35
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:83
getLinkRenderer()
Returns an instance of LinkRenderer.
OldLocalFile $file
getHeight( $page=1)
Return the height of the image.
Definition: LocalFile.php:828
RevDelFileList $list
getWidth( $page=1)
Return the width of the image.
Definition: LocalFile.php:796
getUser( $type='text')
Returns user who uploaded the file.
Definition: LocalFile.php:861
isDeleted( $field)