Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / revisiondelete / RevDelLogItem.php
blobfdbdf92ba73972141b9026dce7895a35ff016ec6
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.
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.
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
18 * @file
19 * @ingroup RevisionDelete
22 use MediaWiki\Api\ApiResult;
23 use MediaWiki\CommentStore\CommentStore;
24 use MediaWiki\Html\Html;
25 use MediaWiki\RevisionList\RevisionListBase;
26 use MediaWiki\SpecialPage\SpecialPage;
27 use MediaWiki\Title\Title;
28 use MediaWiki\Xml\Xml;
29 use Wikimedia\Rdbms\IConnectionProvider;
31 /**
32 * Item class for a logging table row
34 class RevDelLogItem extends RevDelItem {
36 /** @var CommentStore */
37 private $commentStore;
38 private IConnectionProvider $dbProvider;
39 private LogFormatterFactory $logFormatterFactory;
41 /**
42 * @param RevisionListBase $list
43 * @param stdClass $row DB result row
44 * @param CommentStore $commentStore
45 * @param IConnectionProvider $dbProvider
46 * @param LogFormatterFactory $logFormatterFactory
48 public function __construct(
49 RevisionListBase $list,
50 $row,
51 CommentStore $commentStore,
52 IConnectionProvider $dbProvider,
53 LogFormatterFactory $logFormatterFactory
54 ) {
55 parent::__construct( $list, $row );
56 $this->commentStore = $commentStore;
57 $this->dbProvider = $dbProvider;
58 $this->logFormatterFactory = $logFormatterFactory;
61 public function getIdField() {
62 return 'log_id';
65 public function getTimestampField() {
66 return 'log_timestamp';
69 public function getAuthorIdField() {
70 return 'log_user';
73 public function getAuthorNameField() {
74 return 'log_user_text';
77 public function getAuthorActorField() {
78 return 'log_actor';
81 public function canView() {
82 return LogEventsList::userCan(
83 $this->row, LogPage::DELETED_RESTRICTED, $this->list->getAuthority()
87 public function canViewContent() {
88 return true; // none
91 public function getBits() {
92 return (int)$this->row->log_deleted;
95 public function setBits( $bits ) {
96 $dbw = $this->dbProvider->getPrimaryDatabase();
98 $dbw->newUpdateQueryBuilder()
99 ->update( 'logging' )
100 ->set( [ 'log_deleted' => $bits ] )
101 ->where( [
102 'log_id' => $this->row->log_id,
103 'log_deleted' => $this->getBits() // cas
105 ->caller( __METHOD__ )->execute();
107 if ( !$dbw->affectedRows() ) {
108 // Concurrent fail!
109 return false;
112 $dbw->newUpdateQueryBuilder()
113 ->update( 'recentchanges' )
114 ->set( [
115 'rc_deleted' => $bits,
116 'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
118 ->where( [
119 'rc_logid' => $this->row->log_id,
120 'rc_timestamp' => $this->row->log_timestamp // index
122 ->caller( __METHOD__ )->execute();
124 return true;
127 public function getHTML() {
128 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
129 $this->row->log_timestamp, $this->list->getUser() ) );
130 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
131 $formatter = $this->logFormatterFactory->newFromRow( $this->row );
132 $formatter->setContext( $this->list->getContext() );
133 $formatter->setAudience( LogFormatter::FOR_THIS_USER );
135 // Log link for this page
136 $loglink = $this->getLinkRenderer()->makeLink(
137 SpecialPage::getTitleFor( 'Log' ),
138 $this->list->msg( 'log' )->text(),
140 [ 'page' => $title->getPrefixedText() ]
142 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
143 // User links and action text
144 $action = $formatter->getActionText();
146 $dir = $this->list->getLanguage()->getDir();
147 $comment = Html::rawElement( 'bdi', [ 'dir' => $dir ], $formatter->getComment() );
149 $content = "$loglink $date $action $comment";
150 $attribs = [];
151 if ( $this->row->ts_tags ) {
152 [ $tagSummary, $classes ] = ChangeTags::formatSummaryRow(
153 $this->row->ts_tags,
154 'revisiondelete',
155 $this->list->getContext()
157 $content .= " $tagSummary";
158 $attribs['class'] = implode( ' ', $classes );
160 return Xml::tags( 'li', $attribs, $content );
163 public function getApiData( ApiResult $result ) {
164 $logEntry = DatabaseLogEntry::newFromRow( $this->row );
165 $user = $this->list->getAuthority();
166 $ret = [
167 'id' => $logEntry->getId(),
168 'type' => $logEntry->getType(),
169 'action' => $logEntry->getSubtype(),
170 'userhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_USER ),
171 'commenthidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_COMMENT ),
172 'actionhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_ACTION ),
175 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
176 $ret['params'] = $this->logFormatterFactory->newFromEntry( $logEntry )->formatParametersForApi();
178 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) {
179 $ret += [
180 'userid' => $this->row->log_user ?? 0,
181 'user' => $this->row->log_user_text,
184 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
185 $ret += [
186 'comment' => $this->commentStore->getComment( 'log_comment', $this->row )->text,
190 return $ret;