MediaWiki master
RevDelLogItem.php
Go to the documentation of this file.
1<?php
30
35
37 private $commentStore;
38 private IConnectionProvider $dbProvider;
39 private LogFormatterFactory $logFormatterFactory;
40
48 public function __construct(
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;
59 }
60
61 public function getIdField() {
62 return 'log_id';
63 }
64
65 public function getTimestampField() {
66 return 'log_timestamp';
67 }
68
69 public function getAuthorIdField() {
70 return 'log_user';
71 }
72
73 public function getAuthorNameField() {
74 return 'log_user_text';
75 }
76
77 public function getAuthorActorField() {
78 return 'log_actor';
79 }
80
81 public function canView() {
82 return LogEventsList::userCan(
83 $this->row, LogPage::DELETED_RESTRICTED, $this->list->getAuthority()
84 );
85 }
86
87 public function canViewContent() {
88 return true; // none
89 }
90
91 public function getBits() {
92 return (int)$this->row->log_deleted;
93 }
94
95 public function setBits( $bits ) {
96 $dbw = $this->dbProvider->getPrimaryDatabase();
97
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
104 ] )
105 ->caller( __METHOD__ )->execute();
106
107 if ( !$dbw->affectedRows() ) {
108 // Concurrent fail!
109 return false;
110 }
111
112 $dbw->newUpdateQueryBuilder()
113 ->update( 'recentchanges' )
114 ->set( [
115 'rc_deleted' => $bits,
116 'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
117 ] )
118 ->where( [
119 'rc_logid' => $this->row->log_id,
120 'rc_timestamp' => $this->row->log_timestamp // index
121 ] )
122 ->caller( __METHOD__ )->execute();
123
124 return true;
125 }
126
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 );
134
135 // Log link for this page
136 $loglink = $this->getLinkRenderer()->makeLink(
137 SpecialPage::getTitleFor( 'Log' ),
138 $this->list->msg( 'log' )->text(),
139 [],
140 [ 'page' => $title->getPrefixedText() ]
141 );
142 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
143 // User links and action text
144 $action = $formatter->getActionText();
145
146 $dir = $this->list->getLanguage()->getDir();
147 $comment = Html::rawElement( 'bdi', [ 'dir' => $dir ], $formatter->getComment() );
148
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()
156 );
157 $content .= " $tagSummary";
158 $attribs['class'] = implode( ' ', $classes );
159 }
160 return Xml::tags( 'li', $attribs, $content );
161 }
162
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 ),
173 ];
174
175 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
176 $ret['params'] = $this->logFormatterFactory->newFromEntry( $logEntry )->formatParametersForApi();
177 }
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,
182 ];
183 }
184 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
185 $ret += [
186 'comment' => $this->commentStore->getComment( 'log_comment', $this->row )->text,
187 ];
188 }
189
190 return $ret;
191 }
192}
static formatSummaryRow( $tags, $unused, ?MessageLocalizer $localizer=null)
Creates HTML for the given tags.
This class represents the result of the API operations.
Definition ApiResult.php:43
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:56
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
Module of static functions for generating XML.
Definition Xml.php:37
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.