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
19 * @ingroup RevisionDelete
22 use MediaWiki\MediaWikiServices
;
23 use MediaWiki\Revision\RevisionRecord
;
26 * Item class for a logging table row
28 class RevDelLogItem
extends RevDelItem
{
30 /** @var CommentStore */
31 private $commentStore;
34 * @param RevisionListBase $list
35 * @param stdClass $row DB result row
36 * @param CommentStore $commentStore
38 public function __construct(
39 RevisionListBase
$list,
41 CommentStore
$commentStore
43 parent
::__construct( $list, $row );
44 $this->commentStore
= $commentStore;
47 public function getIdField() {
51 public function getTimestampField() {
52 return 'log_timestamp';
55 public function getAuthorIdField() {
59 public function getAuthorNameField() {
60 return 'log_user_text';
63 public function getAuthorActorField() {
67 public function canView() {
68 return LogEventsList
::userCan(
69 $this->row
, RevisionRecord
::DELETED_RESTRICTED
, $this->list->getUser()
73 public function canViewContent() {
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
93 if ( !$dbw->affectedRows() ) {
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
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();
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 ) ) {
161 'userid' => $this->row
->log_user ??
0,
162 'user' => $this->row
->log_user_text
,
165 if ( LogEventsList
::userCan( $this->row
, LogPage
::DELETED_COMMENT
, $user ) ) {
167 'comment' => $this->commentStore
->getComment( 'log_comment', $this->row
)->text
,