MediaWiki master
RevDelLogItem.php
Go to the documentation of this file.
1<?php
28
33
35 private $commentStore;
36 private IConnectionProvider $dbProvider;
37
44 public function __construct(
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}
This class represents the result of the API operations.
Definition ApiResult.php:36
static formatSummaryRow( $tags, $unused, MessageLocalizer $localizer=null)
Creates HTML for the given tags.
Handle database storage of comments such as edit summaries and log reasons.
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:79
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.
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.
__construct(RevisionListBase $list, $row, CommentStore $commentStore, IConnectionProvider $dbProvider)
Provide primary and replica IDatabase connections.