Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 72 |
|
0.00% |
0 / 13 |
CRAP | |
0.00% |
0 / 1 |
RevDelArchivedFileItem | |
0.00% |
0 / 72 |
|
0.00% |
0 / 13 |
342 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
initFile | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIdField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTimestampField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAuthorIdField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAuthorNameField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAuthorActorField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setBits | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
getLink | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
12 | |||
getApiData | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
20 | |||
lock | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
unlock | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
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\Api\ApiResult; |
23 | use MediaWiki\MediaWikiServices; |
24 | use MediaWiki\RevisionList\RevisionListBase; |
25 | use MediaWiki\SpecialPage\SpecialPage; |
26 | |
27 | /** |
28 | * Item class for a filearchive table row |
29 | * |
30 | * @property ArchivedFile $file |
31 | * @property RevDelArchivedFileList $list |
32 | */ |
33 | class RevDelArchivedFileItem extends RevDelFileItem { |
34 | /** @var LocalFile */ |
35 | protected $lockFile; |
36 | |
37 | public function __construct( RevisionListBase $list, $row ) { |
38 | parent::__construct( $list, $row ); |
39 | $this->lockFile = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() |
40 | ->newFile( $row->fa_name ); |
41 | } |
42 | |
43 | protected static function initFile( $list, $row ) { |
44 | return ArchivedFile::newFromRow( $row ); |
45 | } |
46 | |
47 | public function getIdField() { |
48 | return 'fa_id'; |
49 | } |
50 | |
51 | public function getTimestampField() { |
52 | return 'fa_timestamp'; |
53 | } |
54 | |
55 | public function getAuthorIdField() { |
56 | return 'fa_user'; |
57 | } |
58 | |
59 | public function getAuthorNameField() { |
60 | return 'fa_user_text'; |
61 | } |
62 | |
63 | public function getAuthorActorField() { |
64 | return 'fa_actor'; |
65 | } |
66 | |
67 | public function getId() { |
68 | return $this->row->fa_id; |
69 | } |
70 | |
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(); |
81 | |
82 | return (bool)$dbw->affectedRows(); |
83 | } |
84 | |
85 | protected function getLink() { |
86 | $date = $this->list->getLanguage()->userTimeAndDate( |
87 | $this->file->getTimestamp(), $this->list->getUser() ); |
88 | |
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, [], |
96 | [ |
97 | 'target' => $this->list->getPageName(), |
98 | 'file' => $key, |
99 | 'token' => $this->list->getUser()->getEditToken( $key ) |
100 | ] |
101 | ); |
102 | } |
103 | if ( $this->isDeleted() ) { |
104 | $link = '<span class="history-deleted">' . $link . '</span>'; |
105 | } |
106 | |
107 | return $link; |
108 | } |
109 | |
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(), |
122 | ]; |
123 | if ( $this->canViewContent() ) { |
124 | $ret += [ |
125 | 'url' => SpecialPage::getTitleFor( 'Revisiondelete' )->getLinkURL( |
126 | [ |
127 | 'target' => $this->list->getPageName(), |
128 | 'file' => $file->getKey(), |
129 | 'token' => $user->getEditToken( $file->getKey() ) |
130 | ] |
131 | ), |
132 | ]; |
133 | } |
134 | $uploader = $file->getUploader( ArchivedFile::FOR_THIS_USER, $user ); |
135 | if ( $uploader ) { |
136 | $ret += [ |
137 | 'userid' => $uploader->getId(), |
138 | 'user' => $uploader->getName(), |
139 | ]; |
140 | } |
141 | $comment = $file->getDescription( ArchivedFile::FOR_THIS_USER, $user ); |
142 | if ( $comment !== '' ) { |
143 | $ret += [ |
144 | 'comment' => $comment, |
145 | ]; |
146 | } |
147 | |
148 | return $ret; |
149 | } |
150 | |
151 | public function lock() { |
152 | return $this->lockFile->acquireFileLock(); |
153 | } |
154 | |
155 | public function unlock() { |
156 | return $this->lockFile->releaseFileLock(); |
157 | } |
158 | } |