Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[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 * @property ArchivedFile $file
28 * @property RevDelArchivedFileList $list
29 */
30 class RevDelArchivedFileItem extends RevDelFileItem {
31 /** @var LocalFile */
32 protected $lockFile;
33
34 public function __construct( $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 ) {
40 return ArchivedFile::newFromRow( $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 }