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