MediaWiki master
RevDelLogItem.php
Go to the documentation of this file.
1<?php
9
23use stdClass;
25
30
32 private $commentStore;
33 private IConnectionProvider $dbProvider;
34 private LogFormatterFactory $logFormatterFactory;
35
43 public function __construct(
45 $row,
46 CommentStore $commentStore,
47 IConnectionProvider $dbProvider,
48 LogFormatterFactory $logFormatterFactory
49 ) {
50 parent::__construct( $list, $row );
51 $this->commentStore = $commentStore;
52 $this->dbProvider = $dbProvider;
53 $this->logFormatterFactory = $logFormatterFactory;
54 }
55
57 public function getIdField() {
58 return 'log_id';
59 }
60
62 public function getTimestampField() {
63 return 'log_timestamp';
64 }
65
67 public function getAuthorIdField() {
68 return 'log_user';
69 }
70
72 public function getAuthorNameField() {
73 return 'log_user_text';
74 }
75
77 public function getAuthorActorField() {
78 return 'log_actor';
79 }
80
82 public function canView() {
83 return LogEventsList::userCan(
84 $this->row, LogPage::DELETED_RESTRICTED, $this->list->getAuthority()
85 );
86 }
87
89 public function canViewContent() {
90 return true; // none
91 }
92
94 public function getBits() {
95 return (int)$this->row->log_deleted;
96 }
97
99 public function setBits( $bits ) {
100 $dbw = $this->dbProvider->getPrimaryDatabase();
101
102 $dbw->newUpdateQueryBuilder()
103 ->update( 'logging' )
104 ->set( [ 'log_deleted' => $bits ] )
105 ->where( [
106 'log_id' => $this->row->log_id,
107 'log_deleted' => $this->getBits() // cas
108 ] )
109 ->caller( __METHOD__ )->execute();
110
111 if ( !$dbw->affectedRows() ) {
112 // Concurrent fail!
113 return false;
114 }
115
116 $dbw->newUpdateQueryBuilder()
117 ->update( 'recentchanges' )
118 ->set( [
119 'rc_deleted' => $bits,
120 'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
121 ] )
122 ->where( [
123 'rc_logid' => $this->row->log_id,
124 'rc_timestamp' => $this->row->log_timestamp // index
125 ] )
126 ->caller( __METHOD__ )->execute();
127
128 return true;
129 }
130
132 public function getHTML() {
133 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
134 $this->row->log_timestamp, $this->list->getUser() ) );
135 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
136 $formatter = $this->logFormatterFactory->newFromRow( $this->row );
137 $formatter->setContext( $this->list->getContext() );
138 $formatter->setAudience( LogFormatter::FOR_THIS_USER );
139
140 // Log link for this page
141 $loglink = $this->getLinkRenderer()->makeLink(
143 $this->list->msg( 'log' )->text(),
144 [],
145 [ 'page' => $title->getPrefixedText() ]
146 );
147 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
148 // User links and action text
149 $action = $formatter->getActionText();
150
151 $dir = $this->list->getLanguage()->getDir();
152 $comment = Html::rawElement( 'bdi', [ 'dir' => $dir ], $formatter->getComment() );
153
154 $content = "$loglink $date $action $comment";
155 $attribs = [];
156 if ( $this->row->ts_tags ) {
157 [ $tagSummary, $classes ] = ChangeTags::formatSummaryRow(
158 $this->row->ts_tags,
159 'revisiondelete',
160 $this->list->getContext()
161 );
162 $content .= " $tagSummary";
163 $attribs['class'] = $classes;
164 }
165 return Html::rawElement( 'li', $attribs, $content );
166 }
167
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}
199
201class_alias( RevDelLogItem::class, 'RevDelLogItem' );
This class represents the result of the API operations.
Definition ApiResult.php:34
Recent changes tagging.
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:43
A value class to process existing log entries.
Implements the default log formatting.
Class to simplify the use of log pages.
Definition LogPage.php:35
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
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
__construct(RevisionListBase $list, $row, CommentStore $commentStore, IConnectionProvider $dbProvider, LogFormatterFactory $logFormatterFactory)
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.