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