MediaWiki  master
RevDelLogItem.php
Go to the documentation of this file.
1 <?php
23 
27 class RevDelLogItem extends RevDelItem {
28 
30  private $commentStore;
31 
37  public function __construct(
39  $row,
41  ) {
42  parent::__construct( $list, $row );
43  $this->commentStore = $commentStore;
44  }
45 
46  public function getIdField() {
47  return 'log_id';
48  }
49 
50  public function getTimestampField() {
51  return 'log_timestamp';
52  }
53 
54  public function getAuthorIdField() {
55  return 'log_user';
56  }
57 
58  public function getAuthorNameField() {
59  return 'log_user_text';
60  }
61 
62  public function getAuthorActorField() {
63  return 'log_actor';
64  }
65 
66  public function canView() {
68  $this->row, RevisionRecord::DELETED_RESTRICTED, $this->list->getUser()
69  );
70  }
71 
72  public function canViewContent() {
73  return true; // none
74  }
75 
76  public function getBits() {
77  return (int)$this->row->log_deleted;
78  }
79 
80  public function setBits( $bits ) {
81  $dbw = wfGetDB( DB_PRIMARY );
82 
83  $dbw->update( 'logging',
84  [ 'log_deleted' => $bits ],
85  [
86  'log_id' => $this->row->log_id,
87  'log_deleted' => $this->getBits() // cas
88  ],
89  __METHOD__
90  );
91 
92  if ( !$dbw->affectedRows() ) {
93  // Concurrent fail!
94  return false;
95  }
96 
97  $dbw->update( 'recentchanges',
98  [
99  'rc_deleted' => $bits,
100  'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
101  ],
102  [
103  'rc_logid' => $this->row->log_id,
104  'rc_timestamp' => $this->row->log_timestamp // index
105  ],
106  __METHOD__
107  );
108 
109  return true;
110  }
111 
112  public function getHTML() {
113  $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
114  $this->row->log_timestamp, $this->list->getUser() ) );
115  $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
116  $formatter = LogFormatter::newFromRow( $this->row );
117  $formatter->setContext( $this->list->getContext() );
118  $formatter->setAudience( LogFormatter::FOR_THIS_USER );
119 
120  // Log link for this page
121  $loglink = $this->getLinkRenderer()->makeLink(
122  SpecialPage::getTitleFor( 'Log' ),
123  $this->list->msg( 'log' )->text(),
124  [],
125  [ 'page' => $title->getPrefixedText() ]
126  );
127  $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
128  // User links and action text
129  $action = $formatter->getActionText();
130 
131  $comment = $this->commentStore->getComment( 'log_comment', $this->row )->text;
132  $comment = $this->list->getLanguage()->getDirMark()
133  . Linker::commentBlock( $comment );
134 
135  if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
136  $comment = '<span class="history-deleted">' . $comment . '</span>';
137  }
138 
139  return "<li>$loglink $date $action $comment</li>";
140  }
141 
142  public function getApiData( ApiResult $result ) {
143  $logEntry = DatabaseLogEntry::newFromRow( $this->row );
144  $user = $this->list->getUser();
145  $ret = [
146  'id' => $logEntry->getId(),
147  'type' => $logEntry->getType(),
148  'action' => $logEntry->getSubtype(),
149  'userhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_USER ),
150  'commenthidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_COMMENT ),
151  'actionhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_ACTION ),
152  ];
153 
154  if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
155  $ret['params'] = LogFormatter::newFromEntry( $logEntry )->formatParametersForApi();
156  }
157  if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) {
158  $ret += [
159  'userid' => $this->row->log_user ?? 0,
160  'user' => $this->row->log_user_text,
161  ];
162  }
163  if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
164  $ret += [
165  'comment' => $this->commentStore->getComment( 'log_comment', $this->row )->text,
166  ];
167  }
168 
169  return $ret;
170  }
171 }
RevDelLogItem\getApiData
getApiData(ApiResult $result)
Get the return information about the revision for the API.
Definition: RevDelLogItem.php:142
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:72
RevisionListBase
List for revision table items for a single page.
Definition: RevisionListBase.php:30
RevDelLogItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevDelLogItem.php:54
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:521
CommentStore
Handle database storage of comments such as edit summaries and log reasons.
Definition: CommentStore.php:42
RevDelLogItem\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevDelLogItem.php:46
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:80
RevDelLogItem\canView
canView()
Returns true if the current user can view the item.
Definition: RevDelLogItem.php:66
RevDelLogItem\$commentStore
CommentStore $commentStore
Definition: RevDelLogItem.php:30
RevisionItemBase\$list
RevisionListBase $list
The parent.
Definition: RevisionItemBase.php:31
RevDelLogItem\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.
Definition: RevDelLogItem.php:58
DatabaseLogEntry\newFromRow
static newFromRow( $row)
Constructs new LogEntry from database result row.
Definition: DatabaseLogEntry.php:97
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:2203
$title
$title
Definition: testCompression.php:38
RevDelLogItem\__construct
__construct(RevisionListBase $list, $row, CommentStore $commentStore)
Definition: RevDelLogItem.php:37
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:50
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:1749
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
RevDelLogItem\getAuthorActorField
getAuthorActorField()
Get the DB field name storing actor ids.
Definition: RevDelLogItem.php:62
RevDelLogItem\getHTML
getHTML()
Get the HTML of the list item.
Definition: RevDelLogItem.php:112
RecentChange\PRC_AUTOPATROLLED
const PRC_AUTOPATROLLED
Definition: RecentChange.php:93
LogEventsList\isDeleted
static isDeleted( $row, $field)
Definition: LogEventsList.php:568
RevisionItemBase\$row
stdClass $row
The database result row.
Definition: RevisionItemBase.php:34
RevDelLogItem\getBits
getBits()
Get the current deletion bitfield value.
Definition: RevDelLogItem.php:76
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:54
RevDelItem
Abstract base class for deletable items.
Definition: RevDelItem.php:25