MediaWiki  master
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 }
static newFromRow( $row)
Constructs new LogEntry from database result row.
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Item class for a logging table row.
const DB_MASTER
Definition: defines.php:26
const DELETED_COMMENT
Definition: LogPage.php:35
Abstract base class for deletable items.
Definition: RevDelItem.php:25
static isDeleted( $row, $field)
const FOR_THIS_USER
This class represents the result of the API operations.
Definition: ApiResult.php:35
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:83
getApiData(ApiResult $result)
const DELETED_USER
Definition: LogPage.php:36
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:584
static getStore()
static userCan( $row, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this log row, if it&#39;s marked as deleted and/or restricted log type.
getLinkRenderer()
Returns an instance of LinkRenderer.
const DELETED_ACTION
Definition: LogPage.php:34
const PRC_AUTOPATROLLED
static commentBlock( $comment, $title=null, $local=false, $wikiId=null, $useParentheses=true)
Wrap a comment in standard punctuation and formatting if it&#39;s non-empty, otherwise return empty strin...
Definition: Linker.php:1543