Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 85
0.00% covered (danger)
0.00%
0 / 12
CRAP
0.00% covered (danger)
0.00%
0 / 1
RevDelLogItem
0.00% covered (danger)
0.00%
0 / 85
0.00% covered (danger)
0.00%
0 / 12
306
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
 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
 canView
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 canViewContent
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getBits
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 / 23
0.00% covered (danger)
0.00%
0 / 1
6
 getHTML
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 1
6
 getApiData
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 1
20
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\CommentStore\CommentStore;
23use MediaWiki\RevisionList\RevisionListBase;
24use MediaWiki\SpecialPage\SpecialPage;
25use MediaWiki\Title\Title;
26use MediaWiki\Xml\Xml;
27use Wikimedia\Rdbms\IConnectionProvider;
28
29/**
30 * Item class for a logging table row
31 */
32class RevDelLogItem extends RevDelItem {
33
34    /** @var CommentStore */
35    private $commentStore;
36    private IConnectionProvider $dbProvider;
37
38    /**
39     * @param RevisionListBase $list
40     * @param stdClass $row DB result row
41     * @param CommentStore $commentStore
42     * @param IConnectionProvider $dbProvider
43     */
44    public function __construct(
45        RevisionListBase $list,
46        $row,
47        CommentStore $commentStore,
48        IConnectionProvider $dbProvider
49    ) {
50        parent::__construct( $list, $row );
51        $this->commentStore = $commentStore;
52        $this->dbProvider = $dbProvider;
53    }
54
55    public function getIdField() {
56        return 'log_id';
57    }
58
59    public function getTimestampField() {
60        return 'log_timestamp';
61    }
62
63    public function getAuthorIdField() {
64        return 'log_user';
65    }
66
67    public function getAuthorNameField() {
68        return 'log_user_text';
69    }
70
71    public function getAuthorActorField() {
72        return 'log_actor';
73    }
74
75    public function canView() {
76        return LogEventsList::userCan(
77            $this->row, LogPage::DELETED_RESTRICTED, $this->list->getAuthority()
78        );
79    }
80
81    public function canViewContent() {
82        return true; // none
83    }
84
85    public function getBits() {
86        return (int)$this->row->log_deleted;
87    }
88
89    public function setBits( $bits ) {
90        $dbw = $this->dbProvider->getPrimaryDatabase();
91
92        $dbw->newUpdateQueryBuilder()
93            ->update( 'logging' )
94            ->set( [ 'log_deleted' => $bits ] )
95            ->where( [
96                'log_id' => $this->row->log_id,
97                'log_deleted' => $this->getBits() // cas
98            ] )
99            ->caller( __METHOD__ )->execute();
100
101        if ( !$dbw->affectedRows() ) {
102            // Concurrent fail!
103            return false;
104        }
105
106        $dbw->newUpdateQueryBuilder()
107            ->update( 'recentchanges' )
108            ->set( [
109                'rc_deleted' => $bits,
110                'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
111            ] )
112            ->where( [
113                'rc_logid' => $this->row->log_id,
114                'rc_timestamp' => $this->row->log_timestamp // index
115            ] )
116            ->caller( __METHOD__ )->execute();
117
118        return true;
119    }
120
121    public function getHTML() {
122        $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
123            $this->row->log_timestamp, $this->list->getUser() ) );
124        $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
125        $formatter = LogFormatter::newFromRow( $this->row );
126        $formatter->setContext( $this->list->getContext() );
127        $formatter->setAudience( LogFormatter::FOR_THIS_USER );
128
129        // Log link for this page
130        $loglink = $this->getLinkRenderer()->makeLink(
131            SpecialPage::getTitleFor( 'Log' ),
132            $this->list->msg( 'log' )->text(),
133            [],
134            [ 'page' => $title->getPrefixedText() ]
135        );
136        $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
137        // User links and action text
138        $action = $formatter->getActionText();
139
140        $comment = $this->list->getLanguage()->getDirMark() .
141            $formatter->getComment();
142
143        $content = "$loglink $date $action $comment";
144        $attribs = [];
145        if ( $this->row->ts_tags ) {
146            [ $tagSummary, $classes ] = ChangeTags::formatSummaryRow(
147                $this->row->ts_tags,
148                'revisiondelete',
149                $this->list->getContext()
150            );
151            $content .= " $tagSummary";
152            $attribs['class'] = implode( ' ', $classes );
153        }
154        return Xml::tags( 'li', $attribs, $content );
155    }
156
157    public function getApiData( ApiResult $result ) {
158        $logEntry = DatabaseLogEntry::newFromRow( $this->row );
159        $user = $this->list->getAuthority();
160        $ret = [
161            'id' => $logEntry->getId(),
162            'type' => $logEntry->getType(),
163            'action' => $logEntry->getSubtype(),
164            'userhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_USER ),
165            'commenthidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_COMMENT ),
166            'actionhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_ACTION ),
167        ];
168
169        if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
170            $ret['params'] = LogFormatter::newFromEntry( $logEntry )->formatParametersForApi();
171        }
172        if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) {
173            $ret += [
174                'userid' => $this->row->log_user ?? 0,
175                'user' => $this->row->log_user_text,
176            ];
177        }
178        if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
179            $ret += [
180                'comment' => $this->commentStore->getComment( 'log_comment', $this->row )->text,
181            ];
182        }
183
184        return $ret;
185    }
186}