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