MediaWiki  master
RevDelLogItem.php
Go to the documentation of this file.
1 <?php
24 
28 class RevDelLogItem extends RevDelItem {
29  public function getIdField() {
30  return 'log_id';
31  }
32 
33  public function getTimestampField() {
34  return 'log_timestamp';
35  }
36 
37  public function getAuthorIdField() {
38  return 'log_user';
39  }
40 
41  public function getAuthorNameField() {
42  return 'log_user_text';
43  }
44 
45  public function getAuthorActorField() {
46  return 'log_actor';
47  }
48 
49  public function canView() {
51  $this->row, RevisionRecord::DELETED_RESTRICTED, $this->list->getUser()
52  );
53  }
54 
55  public function canViewContent() {
56  return true; // none
57  }
58 
59  public function getBits() {
60  return (int)$this->row->log_deleted;
61  }
62 
63  public function setBits( $bits ) {
64  $dbw = wfGetDB( DB_PRIMARY );
65 
66  $dbw->update( 'logging',
67  [ 'log_deleted' => $bits ],
68  [
69  'log_id' => $this->row->log_id,
70  'log_deleted' => $this->getBits() // cas
71  ],
72  __METHOD__
73  );
74 
75  if ( !$dbw->affectedRows() ) {
76  // Concurrent fail!
77  return false;
78  }
79 
80  $dbw->update( 'recentchanges',
81  [
82  'rc_deleted' => $bits,
83  'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
84  ],
85  [
86  'rc_logid' => $this->row->log_id,
87  'rc_timestamp' => $this->row->log_timestamp // index
88  ],
89  __METHOD__
90  );
91 
92  return true;
93  }
94 
95  public function getHTML() {
96  $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
97  $this->row->log_timestamp, $this->list->getUser() ) );
98  $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
99  $formatter = LogFormatter::newFromRow( $this->row );
100  $formatter->setContext( $this->list->getContext() );
101  $formatter->setAudience( LogFormatter::FOR_THIS_USER );
102 
103  // Log link for this page
104  $loglink = $this->getLinkRenderer()->makeLink(
105  SpecialPage::getTitleFor( 'Log' ),
106  $this->list->msg( 'log' )->text(),
107  [],
108  [ 'page' => $title->getPrefixedText() ]
109  );
110  $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
111  // User links and action text
112  $action = $formatter->getActionText();
113 
114  $comment = MediaWikiServices::getInstance()
115  ->getCommentStore()
116  ->getComment( 'log_comment', $this->row )
117  ->text;
118  // @phan-suppress-next-line SecurityCheck-DoubleEscaped false positive
119  $comment = $this->list->getLanguage()->getDirMark()
120  . Linker::commentBlock( $comment );
121 
122  if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
123  $comment = '<span class="history-deleted">' . $comment . '</span>';
124  }
125 
126  return "<li>$loglink $date $action $comment</li>";
127  }
128 
129  public function getApiData( ApiResult $result ) {
130  $logEntry = DatabaseLogEntry::newFromRow( $this->row );
131  $user = $this->list->getUser();
132  $ret = [
133  'id' => $logEntry->getId(),
134  'type' => $logEntry->getType(),
135  'action' => $logEntry->getSubtype(),
136  'userhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_USER ),
137  'commenthidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_COMMENT ),
138  'actionhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_ACTION ),
139  ];
140 
141  if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
142  $ret['params'] = LogFormatter::newFromEntry( $logEntry )->formatParametersForApi();
143  }
144  if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) {
145  $ret += [
146  'userid' => $this->row->log_user ?? 0,
147  'user' => $this->row->log_user_text,
148  ];
149  }
150  if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
151  $ret += [
152  'comment' => CommentStore::getStore()->getComment( 'log_comment', $this->row )
153  ->text,
154  ];
155  }
156 
157  return $ret;
158  }
159 }
RevDelLogItem\getApiData
getApiData(ApiResult $result)
Get the return information about the revision for the API.
Definition: RevDelLogItem.php:129
LogFormatter\FOR_THIS_USER
const FOR_THIS_USER
Definition: LogFormatter.php:45
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
RevDelLogItem\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.
Definition: RevDelLogItem.php:55
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:180
RevDelLogItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevDelLogItem.php:37
LogEventsList\userCan
static userCan( $row, $field, Authority $performer)
Determine if the current user is allowed to view a particular field of this log row,...
Definition: LogEventsList.php:531
RevDelLogItem\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevDelLogItem.php:29
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:107
RevDelLogItem\setBits
setBits( $bits)
Set the visibility of the item.
Definition: RevDelLogItem.php:63
RevDelLogItem\canView
canView()
Returns true if the current user can view the item.
Definition: RevDelLogItem.php:49
RevDelLogItem\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.
Definition: RevDelLogItem.php:41
DatabaseLogEntry\newFromRow
static newFromRow( $row)
Constructs new LogEntry from database result row.
Definition: DatabaseLogEntry.php:96
LogPage\DELETED_COMMENT
const DELETED_COMMENT
Definition: LogPage.php:40
LogFormatter\newFromRow
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
Definition: LogFormatter.php:74
ApiResult
This class represents the result of the API operations.
Definition: ApiResult.php:35
RevisionItemBase\getLinkRenderer
getLinkRenderer()
Returns an instance of LinkRenderer.
Definition: RevisionItemBase.php:178
LogPage\DELETED_USER
const DELETED_USER
Definition: LogPage.php:41
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2306
$title
$title
Definition: testCompression.php:38
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:650
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:39
RevDelLogItem\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.
Definition: RevDelLogItem.php:33
Linker\commentBlock
static commentBlock( $comment, $title=null, $local=false, $wikiId=null, $useParentheses=true)
Wrap a comment in standard punctuation and formatting if it's non-empty, otherwise return empty strin...
Definition: Linker.php:1583
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
RevDelLogItem\getAuthorActorField
getAuthorActorField()
Get the DB field name storing actor ids.
Definition: RevDelLogItem.php:45
RevDelLogItem\getHTML
getHTML()
Get the HTML of the list item.
Definition: RevDelLogItem.php:95
RecentChange\PRC_AUTOPATROLLED
const PRC_AUTOPATROLLED
Definition: RecentChange.php:93
LogEventsList\isDeleted
static isDeleted( $row, $field)
Definition: LogEventsList.php:578
CommentStore\getStore
static getStore()
Definition: CommentStore.php:120
RevDelLogItem\getBits
getBits()
Get the current deletion bitfield value.
Definition: RevDelLogItem.php:59
RevDelLogItem
Item class for a logging table row.
Definition: RevDelLogItem.php:28
LogFormatter\newFromEntry
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
Definition: LogFormatter.php:54
RevDelItem
Abstract base class for deletable items.
Definition: RevDelItem.php:25