Fix use of GenderCache in ApiPageSet::processTitlesArray
[lhc/web/wiklou.git] / includes / revisiondelete / RevDelArchivedFileItem.php
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.
7 *
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.
12 *
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
17 *
18 * @file
19 * @ingroup RevisionDelete
20 */
21
22 use MediaWiki\Storage\RevisionRecord;
23
24 /**
25 * Item class for a filearchive table row
26 */
27 class RevDelArchivedFileItem extends RevDelFileItem {
28 /** @var RevDelArchivedFileList $list */
29 /** @var ArchivedFile $file */
30 /** @var LocalFile */
31 protected $lockFile;
32
33 public function __construct( $list, $row ) {
34 parent::__construct( $list, $row );
35 $this->lockFile = RepoGroup::singleton()->getLocalRepo()->newFile( $row->fa_name );
36 }
37
38 protected static function initFile( $list, $row ) {
39 return ArchivedFile::newFromRow( $row );
40 }
41
42 public function getIdField() {
43 return 'fa_id';
44 }
45
46 public function getTimestampField() {
47 return 'fa_timestamp';
48 }
49
50 public function getAuthorIdField() {
51 return 'fa_user';
52 }
53
54 public function getAuthorNameField() {
55 return 'fa_user_text';
56 }
57
58 public function getAuthorActorField() {
59 return 'fa_actor';
60 }
61
62 public function getId() {
63 return $this->row->fa_id;
64 }
65
66 public function setBits( $bits ) {
67 $dbw = wfGetDB( DB_MASTER );
68 $dbw->update( 'filearchive',
69 [ 'fa_deleted' => $bits ],
70 [
71 'fa_id' => $this->row->fa_id,
72 'fa_deleted' => $this->getBits(),
73 ],
74 __METHOD__
75 );
76
77 return (bool)$dbw->affectedRows();
78 }
79
80 protected function getLink() {
81 $date = $this->list->getLanguage()->userTimeAndDate(
82 $this->file->getTimestamp(), $this->list->getUser() );
83
84 # Hidden files...
85 if ( !$this->canViewContent() ) {
86 $link = htmlspecialchars( $date );
87 } else {
88 $undelete = SpecialPage::getTitleFor( 'Undelete' );
89 $key = $this->file->getKey();
90 $link = $this->getLinkRenderer()->makeLink( $undelete, $date, [],
91 [
92 'target' => $this->list->title->getPrefixedText(),
93 'file' => $key,
94 'token' => $this->list->getUser()->getEditToken( $key )
95 ]
96 );
97 }
98 if ( $this->isDeleted() ) {
99 $link = '<span class="history-deleted">' . $link . '</span>';
100 }
101
102 return $link;
103 }
104
105 public function getApiData( ApiResult $result ) {
106 $file = $this->file;
107 $user = $this->list->getUser();
108 $ret = [
109 'title' => $this->list->title->getPrefixedText(),
110 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
111 'width' => $file->getWidth(),
112 'height' => $file->getHeight(),
113 'size' => $file->getSize(),
114 'userhidden' => (bool)$file->isDeleted( RevisionRecord::DELETED_USER ),
115 'commenthidden' => (bool)$file->isDeleted( RevisionRecord::DELETED_COMMENT ),
116 'contenthidden' => (bool)$this->isDeleted(),
117 ];
118 if ( $this->canViewContent() ) {
119 $ret += [
120 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL(
121 [
122 'target' => $this->list->title->getPrefixedText(),
123 'file' => $file->getKey(),
124 'token' => $user->getEditToken( $file->getKey() )
125 ]
126 ),
127 ];
128 }
129 if ( $file->userCan( RevisionRecord::DELETED_USER, $user ) ) {
130 $ret += [
131 'userid' => $file->getUser( 'id' ),
132 'user' => $file->getUser( 'text' ),
133 ];
134 }
135 if ( $file->userCan( RevisionRecord::DELETED_COMMENT, $user ) ) {
136 $ret += [
137 'comment' => $file->getRawDescription(),
138 ];
139 }
140
141 return $ret;
142 }
143
144 public function lock() {
145 return $this->lockFile->acquireFileLock();
146 }
147
148 public function unlock() {
149 return $this->lockFile->releaseFileLock();
150 }
151 }