MediaWiki master
RevDelLogItem.php
Go to the documentation of this file.
1<?php
36
41
43 private $commentStore;
44 private IConnectionProvider $dbProvider;
45 private LogFormatterFactory $logFormatterFactory;
46
54 public function __construct(
56 $row,
57 CommentStore $commentStore,
58 IConnectionProvider $dbProvider,
59 LogFormatterFactory $logFormatterFactory
60 ) {
61 parent::__construct( $list, $row );
62 $this->commentStore = $commentStore;
63 $this->dbProvider = $dbProvider;
64 $this->logFormatterFactory = $logFormatterFactory;
65 }
66
67 public function getIdField() {
68 return 'log_id';
69 }
70
71 public function getTimestampField() {
72 return 'log_timestamp';
73 }
74
75 public function getAuthorIdField() {
76 return 'log_user';
77 }
78
79 public function getAuthorNameField() {
80 return 'log_user_text';
81 }
82
83 public function getAuthorActorField() {
84 return 'log_actor';
85 }
86
87 public function canView() {
88 return LogEventsList::userCan(
89 $this->row, LogPage::DELETED_RESTRICTED, $this->list->getAuthority()
90 );
91 }
92
93 public function canViewContent() {
94 return true; // none
95 }
96
97 public function getBits() {
98 return (int)$this->row->log_deleted;
99 }
100
101 public function setBits( $bits ) {
102 $dbw = $this->dbProvider->getPrimaryDatabase();
103
104 $dbw->newUpdateQueryBuilder()
105 ->update( 'logging' )
106 ->set( [ 'log_deleted' => $bits ] )
107 ->where( [
108 'log_id' => $this->row->log_id,
109 'log_deleted' => $this->getBits() // cas
110 ] )
111 ->caller( __METHOD__ )->execute();
112
113 if ( !$dbw->affectedRows() ) {
114 // Concurrent fail!
115 return false;
116 }
117
118 $dbw->newUpdateQueryBuilder()
119 ->update( 'recentchanges' )
120 ->set( [
121 'rc_deleted' => $bits,
122 'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
123 ] )
124 ->where( [
125 'rc_logid' => $this->row->log_id,
126 'rc_timestamp' => $this->row->log_timestamp // index
127 ] )
128 ->caller( __METHOD__ )->execute();
129
130 return true;
131 }
132
133 public function getHTML() {
134 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
135 $this->row->log_timestamp, $this->list->getUser() ) );
136 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
137 $formatter = $this->logFormatterFactory->newFromRow( $this->row );
138 $formatter->setContext( $this->list->getContext() );
139 $formatter->setAudience( LogFormatter::FOR_THIS_USER );
140
141 // Log link for this page
142 $loglink = $this->getLinkRenderer()->makeLink(
143 SpecialPage::getTitleFor( 'Log' ),
144 $this->list->msg( 'log' )->text(),
145 [],
146 [ 'page' => $title->getPrefixedText() ]
147 );
148 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
149 // User links and action text
150 $action = $formatter->getActionText();
151
152 $dir = $this->list->getLanguage()->getDir();
153 $comment = Html::rawElement( 'bdi', [ 'dir' => $dir ], $formatter->getComment() );
154
155 $content = "$loglink $date $action $comment";
156 $attribs = [];
157 if ( $this->row->ts_tags ) {
158 [ $tagSummary, $classes ] = ChangeTags::formatSummaryRow(
159 $this->row->ts_tags,
160 'revisiondelete',
161 $this->list->getContext()
162 );
163 $content .= " $tagSummary";
164 $attribs['class'] = $classes;
165 }
166 return Html::rawElement( 'li', $attribs, $content );
167 }
168
169 public function getApiData( ApiResult $result ) {
170 $logEntry = DatabaseLogEntry::newFromRow( $this->row );
171 $user = $this->list->getAuthority();
172 $ret = [
173 'id' => $logEntry->getId(),
174 'type' => $logEntry->getType(),
175 'action' => $logEntry->getSubtype(),
176 'userhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_USER ),
177 'commenthidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_COMMENT ),
178 'actionhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_ACTION ),
179 ];
180
181 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
182 $ret['params'] = $this->logFormatterFactory->newFromEntry( $logEntry )->formatParametersForApi();
183 }
184 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) {
185 $ret += [
186 'userid' => $this->row->log_user ?? 0,
187 'user' => $this->row->log_user_text,
188 ];
189 }
190 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
191 $ret += [
192 'comment' => $this->commentStore->getComment( 'log_comment', $this->row )->text,
193 ];
194 }
195
196 return $ret;
197 }
198}
This class represents the result of the API operations.
Definition ApiResult.php:45
Recent changes tagging.
Handle database storage of comments such as edit summaries and log reasons.
This class is a collection of static functions that serve two purposes:
Definition Html.php:57
A value class to process existing log entries.
Implements the default log formatting.
Class to simplify the use of log pages.
Definition LogPage.php:50
Utility class for creating and reading rows in the recentchanges table.
getLinkRenderer()
Returns an instance of LinkRenderer.
stdClass $row
The database result row.
List for revision table items for a single page.
Parent class for all special pages.
Represents a title within MediaWiki.
Definition Title.php:78
Abstract base class for deletable items.
Item class for a logging table row.
getAuthorActorField()
Get the DB field name storing actor ids.
getIdField()
Get the DB field name associated with the ID list.
getBits()
Get the current deletion bitfield value.
getAuthorNameField()
Get the DB field name storing user names.
setBits( $bits)
Set the visibility of the item.
__construct(RevisionListBase $list, $row, CommentStore $commentStore, IConnectionProvider $dbProvider, LogFormatterFactory $logFormatterFactory)
canViewContent()
Returns true if the current user can view the item text/file.
getHTML()
Get the HTML of the list item.
canView()
Returns true if the current user can view the item.
getAuthorIdField()
Get the DB field name storing user ids.
getApiData(ApiResult $result)
Get the return information about the revision for the API.
getTimestampField()
Get the DB field name storing timestamps.
Provide primary and replica IDatabase connections.