MediaWiki master
RevDelLogItem.php
Go to the documentation of this file.
1<?php
9
23use stdClass;
25
30
39 public function __construct(
41 $row,
42 private readonly CommentStore $commentStore,
43 private readonly IConnectionProvider $dbProvider,
44 private readonly LogFormatterFactory $logFormatterFactory,
45 private readonly ChangeTagsFormatter $changeTagsFormatter,
46 ) {
47 parent::__construct( $list, $row );
48 }
49
51 public function getIdField() {
52 return 'log_id';
53 }
54
56 public function getTimestampField() {
57 return 'log_timestamp';
58 }
59
61 public function getAuthorIdField() {
62 return 'log_user';
63 }
64
66 public function getAuthorNameField() {
67 return 'log_user_text';
68 }
69
71 public function getAuthorActorField() {
72 return 'log_actor';
73 }
74
76 public function canView() {
77 return LogEventsList::userCan(
78 $this->row, LogPage::DELETED_RESTRICTED, $this->list->getAuthority()
79 );
80 }
81
83 public function canViewContent() {
84 return true; // none
85 }
86
88 public function getBits() {
89 return (int)$this->row->log_deleted;
90 }
91
93 public function setBits( $bits ) {
94 $dbw = $this->dbProvider->getPrimaryDatabase();
95
96 $dbw->newUpdateQueryBuilder()
97 ->update( 'logging' )
98 ->set( [ 'log_deleted' => $bits ] )
99 ->where( [
100 'log_id' => $this->row->log_id,
101 'log_deleted' => $this->getBits() // cas
102 ] )
103 ->caller( __METHOD__ )->execute();
104
105 if ( !$dbw->affectedRows() ) {
106 // Concurrent fail!
107 return false;
108 }
109
110 $dbw->newUpdateQueryBuilder()
111 ->update( 'recentchanges' )
112 ->set( [
113 'rc_deleted' => $bits,
114 'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
115 ] )
116 ->where( [
117 'rc_logid' => $this->row->log_id,
118 'rc_timestamp' => $this->row->log_timestamp // index
119 ] )
120 ->caller( __METHOD__ )->execute();
121
122 return true;
123 }
124
126 public function getHTML() {
127 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
128 $this->row->log_timestamp, $this->list->getUser() ) );
129 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
130 $formatter = $this->logFormatterFactory->newFromRow( $this->row );
131 $formatter->setContext( $this->list->getContext() );
132 $formatter->setAudience( LogFormatter::FOR_THIS_USER );
133
134 // Log link for this page
135 $loglink = $this->getLinkRenderer()->makeLink(
137 $this->list->msg( 'log' )->text(),
138 [],
139 [ 'page' => $title->getPrefixedText() ]
140 );
141 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
142 // User links and action text
143 $action = $formatter->getActionText();
144
145 $dir = $this->list->getLanguage()->getDir();
146 $comment = Html::rawElement( 'bdi', [ 'dir' => $dir ], $formatter->getComment() );
147
148 $content = "$loglink $date $action $comment";
149 $attribs = [];
150 if ( $this->row->ts_tags ) {
151 [ $tagSummary, $classes ] = $this->changeTagsFormatter->formatTagsAsSummaryList(
152 $this->row->ts_tags,
153 $this->list->getContext(),
154 $this->list->getAuthority()
155 );
156 $content .= " $tagSummary";
157 $attribs['class'] = $classes;
158 }
159 return Html::rawElement( 'li', $attribs, $content );
160 }
161
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}
193
195class_alias( RevDelLogItem::class, 'RevDelLogItem' );
This class represents the result of the API operations.
Definition ApiResult.php:34
Formats change tags for display in HTML and use filter dropdown menus.
Handle database storage of comments such as edit summaries and log reasons.
makeTitle( $linkId)
Convert a link ID to a Title.to override Title
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
A value class to process existing log entries.
Implements the default log formatting.
Class to simplify the use of log pages.
Definition LogPage.php:34
Utility class for creating and reading rows in the recentchanges table.
Abstract base class for deletable items.
Item class for a logging table row.
getAuthorNameField()
Get the DB field name storing user names.Override this function. string|false
getApiData(ApiResult $result)
Get the return information about the revision for the API.1.23 array Data for the API result
__construct(RevisionListBase $list, $row, private readonly CommentStore $commentStore, private readonly IConnectionProvider $dbProvider, private readonly LogFormatterFactory $logFormatterFactory, private readonly ChangeTagsFormatter $changeTagsFormatter,)
setBits( $bits)
Set the visibility of the item.This should do any necessary DB queries.The DB update query should hav...
getAuthorIdField()
Get the DB field name storing user ids.Override this function. string|false
getIdField()
Get the DB field name associated with the ID list.Override this function. string|null
getHTML()
Get the HTML of the list item.Should be include "<li></li>" tags. This is used to show the list in HT...
getTimestampField()
Get the DB field name storing timestamps.Override this function. string|false
getAuthorActorField()
Get the DB field name storing actor ids.Override this function. 1.31 string|false
canViewContent()
Returns true if the current user can view the item text/file.bool
getBits()
Get the current deletion bitfield value.int
canView()
Returns true if the current user can view the item.bool
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.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Represents a title within MediaWiki.
Definition Title.php:69
Provide primary and replica IDatabase connections.