Don't double-escape the ellipses in Language::truncateForVisual()
[mediawiki.git] / includes / revisiondelete / RevDelLogItem.php
blob18d8339b0c205822167055d5a3f33870445af292
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup RevisionDelete
22 use MediaWiki\MediaWikiServices;
23 use MediaWiki\Revision\RevisionRecord;
25 /**
26 * Item class for a logging table row
28 class RevDelLogItem extends RevDelItem {
30 /** @var CommentStore */
31 private $commentStore;
33 /**
34 * @param RevisionListBase $list
35 * @param stdClass $row DB result row
36 * @param CommentStore $commentStore
38 public function __construct(
39 RevisionListBase $list,
40 $row,
41 CommentStore $commentStore
42 ) {
43 parent::__construct( $list, $row );
44 $this->commentStore = $commentStore;
47 public function getIdField() {
48 return 'log_id';
51 public function getTimestampField() {
52 return 'log_timestamp';
55 public function getAuthorIdField() {
56 return 'log_user';
59 public function getAuthorNameField() {
60 return 'log_user_text';
63 public function getAuthorActorField() {
64 return 'log_actor';
67 public function canView() {
68 return LogEventsList::userCan(
69 $this->row, RevisionRecord::DELETED_RESTRICTED, $this->list->getUser()
73 public function canViewContent() {
74 return true; // none
77 public function getBits() {
78 return (int)$this->row->log_deleted;
81 public function setBits( $bits ) {
82 $dbw = wfGetDB( DB_PRIMARY );
84 $dbw->update( 'logging',
85 [ 'log_deleted' => $bits ],
87 'log_id' => $this->row->log_id,
88 'log_deleted' => $this->getBits() // cas
90 __METHOD__
93 if ( !$dbw->affectedRows() ) {
94 // Concurrent fail!
95 return false;
98 $dbw->update( 'recentchanges',
100 'rc_deleted' => $bits,
101 'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
104 'rc_logid' => $this->row->log_id,
105 'rc_timestamp' => $this->row->log_timestamp // index
107 __METHOD__
110 return true;
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 );
121 // Log link for this page
122 $loglink = $this->getLinkRenderer()->makeLink(
123 SpecialPage::getTitleFor( 'Log' ),
124 $this->list->msg( 'log' )->text(),
126 [ 'page' => $title->getPrefixedText() ]
128 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
129 // User links and action text
130 $action = $formatter->getActionText();
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 );
137 if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
138 $comment = '<span class="history-deleted">' . $comment . '</span>';
141 return "<li>$loglink $date $action $comment</li>";
144 public function getApiData( ApiResult $result ) {
145 $logEntry = DatabaseLogEntry::newFromRow( $this->row );
146 $user = $this->list->getUser();
147 $ret = [
148 'id' => $logEntry->getId(),
149 'type' => $logEntry->getType(),
150 'action' => $logEntry->getSubtype(),
151 'userhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_USER ),
152 'commenthidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_COMMENT ),
153 'actionhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_ACTION ),
156 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
157 $ret['params'] = LogFormatter::newFromEntry( $logEntry )->formatParametersForApi();
159 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) {
160 $ret += [
161 'userid' => $this->row->log_user ?? 0,
162 'user' => $this->row->log_user_text,
165 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
166 $ret += [
167 'comment' => $this->commentStore->getComment( 'log_comment', $this->row )->text,
171 return $ret;