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