MediaWiki  master
RevDelLogItem.php
Go to the documentation of this file.
1 <?php
25 
29 class RevDelLogItem extends RevDelItem {
30 
32  private $commentStore;
33 
39  public function __construct(
41  $row,
42  CommentStore $commentStore
43  ) {
44  parent::__construct( $list, $row );
45  $this->commentStore = $commentStore;
46  }
47 
48  public function getIdField() {
49  return 'log_id';
50  }
51 
52  public function getTimestampField() {
53  return 'log_timestamp';
54  }
55 
56  public function getAuthorIdField() {
57  return 'log_user';
58  }
59 
60  public function getAuthorNameField() {
61  return 'log_user_text';
62  }
63 
64  public function getAuthorActorField() {
65  return 'log_actor';
66  }
67 
68  public function canView() {
70  $this->row, LogPage::DELETED_RESTRICTED, $this->list->getAuthority()
71  );
72  }
73 
74  public function canViewContent() {
75  return true; // none
76  }
77 
78  public function getBits() {
79  return (int)$this->row->log_deleted;
80  }
81 
82  public function setBits( $bits ) {
83  $dbw = wfGetDB( DB_PRIMARY );
84 
85  $dbw->newUpdateQueryBuilder()
86  ->update( 'logging' )
87  ->set( [ 'log_deleted' => $bits ] )
88  ->where( [
89  'log_id' => $this->row->log_id,
90  'log_deleted' => $this->getBits() // cas
91  ] )
92  ->caller( __METHOD__ )->execute();
93 
94  if ( !$dbw->affectedRows() ) {
95  // Concurrent fail!
96  return false;
97  }
98 
99  $dbw->newUpdateQueryBuilder()
100  ->update( 'recentchanges' )
101  ->set( [
102  'rc_deleted' => $bits,
103  'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
104  ] )
105  ->where( [
106  'rc_logid' => $this->row->log_id,
107  'rc_timestamp' => $this->row->log_timestamp // index
108  ] )
109  ->caller( __METHOD__ )->execute();
110 
111  return true;
112  }
113 
114  public function getHTML() {
115  $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
116  $this->row->log_timestamp, $this->list->getUser() ) );
117  $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
118  $formatter = LogFormatter::newFromRow( $this->row );
119  $formatter->setContext( $this->list->getContext() );
120  $formatter->setAudience( LogFormatter::FOR_THIS_USER );
121 
122  // Log link for this page
123  $loglink = $this->getLinkRenderer()->makeLink(
124  SpecialPage::getTitleFor( 'Log' ),
125  $this->list->msg( 'log' )->text(),
126  [],
127  [ 'page' => $title->getPrefixedText() ]
128  );
129  $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
130  // User links and action text
131  $action = $formatter->getActionText();
132 
133  $comment = $this->list->getLanguage()->getDirMark() .
134  $formatter->getComment();
135 
136  $content = "$loglink $date $action $comment";
137  $attribs = [];
138  if ( $this->row->ts_tags ) {
139  [ $tagSummary, $classes ] = ChangeTags::formatSummaryRow(
140  $this->row->ts_tags,
141  'revisiondelete',
142  $this->list->getContext()
143  );
144  $content .= " $tagSummary";
145  $attribs['class'] = implode( ' ', $classes );
146  }
147  return Xml::tags( 'li', $attribs, $content );
148  }
149 
150  public function getApiData( ApiResult $result ) {
151  $logEntry = DatabaseLogEntry::newFromRow( $this->row );
152  $user = $this->list->getAuthority();
153  $ret = [
154  'id' => $logEntry->getId(),
155  'type' => $logEntry->getType(),
156  'action' => $logEntry->getSubtype(),
157  'userhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_USER ),
158  'commenthidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_COMMENT ),
159  'actionhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_ACTION ),
160  ];
161 
162  if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
163  $ret['params'] = LogFormatter::newFromEntry( $logEntry )->formatParametersForApi();
164  }
165  if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) {
166  $ret += [
167  'userid' => $this->row->log_user ?? 0,
168  'user' => $this->row->log_user_text,
169  ];
170  }
171  if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
172  $ret += [
173  'comment' => $this->commentStore->getComment( 'log_comment', $this->row )->text,
174  ];
175  }
176 
177  return $ret;
178  }
179 }
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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.
Definition: ChangeTags.php:147
static newFromRow( $row)
Constructs new LogEntry from database result row.
static userCan( $row, $field, Authority $performer)
Determine if the current user is allowed to view a particular field of this log row,...
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
const FOR_THIS_USER
const DELETED_USER
Definition: LogPage.php:46
const DELETED_RESTRICTED
Definition: LogPage.php:47
const DELETED_COMMENT
Definition: LogPage.php:45
const DELETED_ACTION
Definition: LogPage.php:44
Handle database storage of comments such as edit summaries and log reasons.
Parent class for all special pages.
Definition: SpecialPage.php:65
Represents a title within MediaWiki.
Definition: Title.php:76
const PRC_AUTOPATROLLED
Abstract base class for deletable items.
Definition: RevDelItem.php:27
Item class for a logging table row.
getAuthorActorField()
Get the DB field name storing actor ids.
__construct(RevisionListBase $list, $row, CommentStore $commentStore)
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.
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.
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:141
const DB_PRIMARY
Definition: defines.php:28
$content
Definition: router.php:76