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