MediaWiki  master
RevDelLogItem.php
Go to the documentation of this file.
1 <?php
24 
28 class RevDelLogItem extends RevDelItem {
29 
31  private $commentStore;
32 
38  public function __construct(
40  $row,
42  ) {
43  parent::__construct( $list, $row );
44  $this->commentStore = $commentStore;
45  }
46 
47  public function getIdField() {
48  return 'log_id';
49  }
50 
51  public function getTimestampField() {
52  return 'log_timestamp';
53  }
54 
55  public function getAuthorIdField() {
56  return 'log_user';
57  }
58 
59  public function getAuthorNameField() {
60  return 'log_user_text';
61  }
62 
63  public function getAuthorActorField() {
64  return 'log_actor';
65  }
66 
67  public function canView() {
69  $this->row, RevisionRecord::DELETED_RESTRICTED, $this->list->getUser()
70  );
71  }
72 
73  public function canViewContent() {
74  return true; // none
75  }
76 
77  public function getBits() {
78  return (int)$this->row->log_deleted;
79  }
80 
81  public function setBits( $bits ) {
82  $dbw = wfGetDB( DB_PRIMARY );
83 
84  $dbw->update( 'logging',
85  [ 'log_deleted' => $bits ],
86  [
87  'log_id' => $this->row->log_id,
88  'log_deleted' => $this->getBits() // cas
89  ],
90  __METHOD__
91  );
92 
93  if ( !$dbw->affectedRows() ) {
94  // Concurrent fail!
95  return false;
96  }
97 
98  $dbw->update( 'recentchanges',
99  [
100  'rc_deleted' => $bits,
101  'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
102  ],
103  [
104  'rc_logid' => $this->row->log_id,
105  'rc_timestamp' => $this->row->log_timestamp // index
106  ],
107  __METHOD__
108  );
109 
110  return true;
111  }
112 
113  public function getHTML() {
114  $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
115  $this->row->log_timestamp, $this->list->getUser() ) );
116  $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
117  $formatter = LogFormatter::newFromRow( $this->row );
118  $formatter->setContext( $this->list->getContext() );
119  $formatter->setAudience( LogFormatter::FOR_THIS_USER );
120 
121  // Log link for this page
122  $loglink = $this->getLinkRenderer()->makeLink(
123  SpecialPage::getTitleFor( 'Log' ),
124  $this->list->msg( 'log' )->text(),
125  [],
126  [ 'page' => $title->getPrefixedText() ]
127  );
128  $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
129  // User links and action text
130  $action = $formatter->getActionText();
131 
132  $commentRaw = $this->commentStore->getComment( 'log_comment', $this->row )->text;
133  $commentFormatter = MediaWikiServices::getInstance()->getCommentFormatter();
134  $dirMark = $this->list->getLanguage()->getDirMark();
135  $comment = $dirMark . $commentFormatter->formatBlock( $commentRaw );
136 
137  if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
138  $comment = '<span class="history-deleted">' . $comment . '</span>';
139  }
140 
141  $content = "$loglink $date $action $comment";
142  $attribs = [];
143  if ( $this->row->ts_tags ) {
144  list( $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->getUser();
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 }
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, $page, MessageLocalizer $localizer=null)
Creates HTML for the given tags.
Definition: ChangeTags.php:182
Handle database storage of comments such as edit summaries and log reasons.
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 isDeleted( $row, $field)
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:42
const DELETED_COMMENT
Definition: LogPage.php:41
const DELETED_ACTION
Definition: LogPage.php:40
Service locator for MediaWiki core services.
Page revision base class.
const PRC_AUTOPATROLLED
Abstract base class for deletable items.
Definition: RevDelItem.php:25
Item class for a logging table row.
CommentStore $commentStore
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 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,...
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:638
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:134
const DB_PRIMARY
Definition: defines.php:28
$content
Definition: router.php:76