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