Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / revisiondelete / RevDelArchivedFileItem.php
blob94e742d16407327029925c5012b99271cae533b0
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup RevisionDelete
22 use MediaWiki\Api\ApiResult;
23 use MediaWiki\MediaWikiServices;
24 use MediaWiki\RevisionList\RevisionListBase;
25 use MediaWiki\SpecialPage\SpecialPage;
27 /**
28 * Item class for a filearchive table row
30 * @property ArchivedFile $file
31 * @property RevDelArchivedFileList $list
33 class RevDelArchivedFileItem extends RevDelFileItem {
34 /** @var LocalFile */
35 protected $lockFile;
37 public function __construct( RevisionListBase $list, $row ) {
38 parent::__construct( $list, $row );
39 $this->lockFile = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
40 ->newFile( $row->fa_name );
43 protected static function initFile( $list, $row ) {
44 return ArchivedFile::newFromRow( $row );
47 public function getIdField() {
48 return 'fa_id';
51 public function getTimestampField() {
52 return 'fa_timestamp';
55 public function getAuthorIdField() {
56 return 'fa_user';
59 public function getAuthorNameField() {
60 return 'fa_user_text';
63 public function getAuthorActorField() {
64 return 'fa_actor';
67 public function getId() {
68 return $this->row->fa_id;
71 public function setBits( $bits ) {
72 $dbw = $this->dbProvider->getPrimaryDatabase();
73 $dbw->newUpdateQueryBuilder()
74 ->update( 'filearchive' )
75 ->set( [ 'fa_deleted' => $bits ] )
76 ->where( [
77 'fa_id' => $this->row->fa_id,
78 'fa_deleted' => $this->getBits(),
79 ] )
80 ->caller( __METHOD__ )->execute();
82 return (bool)$dbw->affectedRows();
85 protected function getLink() {
86 $date = $this->list->getLanguage()->userTimeAndDate(
87 $this->file->getTimestamp(), $this->list->getUser() );
89 # Hidden files...
90 if ( !$this->canViewContent() ) {
91 $link = htmlspecialchars( $date );
92 } else {
93 $undelete = SpecialPage::getTitleFor( 'Undelete' );
94 $key = $this->file->getKey();
95 $link = $this->getLinkRenderer()->makeLink( $undelete, $date, [],
97 'target' => $this->list->getPageName(),
98 'file' => $key,
99 'token' => $this->list->getUser()->getEditToken( $key )
103 if ( $this->isDeleted() ) {
104 $link = '<span class="history-deleted">' . $link . '</span>';
107 return $link;
110 public function getApiData( ApiResult $result ) {
111 $file = $this->file;
112 $user = $this->list->getUser();
113 $ret = [
114 'title' => $this->list->getPageName(),
115 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
116 'width' => $file->getWidth(),
117 'height' => $file->getHeight(),
118 'size' => $file->getSize(),
119 'userhidden' => (bool)$file->isDeleted( File::DELETED_USER ),
120 'commenthidden' => (bool)$file->isDeleted( File::DELETED_COMMENT ),
121 'contenthidden' => (bool)$this->isDeleted(),
123 if ( $this->canViewContent() ) {
124 $ret += [
125 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
127 'target' => $this->list->getPageName(),
128 'file' => $file->getKey(),
129 'token' => $user->getEditToken( $file->getKey() )
134 $uploader = $file->getUploader( ArchivedFile::FOR_THIS_USER, $user );
135 if ( $uploader ) {
136 $ret += [
137 'userid' => $uploader->getId(),
138 'user' => $uploader->getName(),
141 $comment = $file->getDescription( ArchivedFile::FOR_THIS_USER, $user );
142 if ( $comment !== '' ) {
143 $ret += [
144 'comment' => $comment,
148 return $ret;
151 public function lock() {
152 return $this->lockFile->acquireFileLock();
155 public function unlock() {
156 return $this->lockFile->releaseFileLock();