Update OOjs UI to v0.1.0-pre (40de4dabe6)
[lhc/web/wiklou.git] / includes / revisiondelete / RevDelLogItem.php
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.
7 *
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.
12 *
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
17 *
18 * @file
19 * @ingroup RevisionDelete
20 */
21
22 /**
23 * Item class for a logging table row
24 */
25 class RevDelLogItem extends RevDelItem {
26 public function getIdField() {
27 return 'log_id';
28 }
29
30 public function getTimestampField() {
31 return 'log_timestamp';
32 }
33
34 public function getAuthorIdField() {
35 return 'log_user';
36 }
37
38 public function getAuthorNameField() {
39 return 'log_user_text';
40 }
41
42 public function canView() {
43 return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED, $this->list->getUser() );
44 }
45
46 public function canViewContent() {
47 return true; // none
48 }
49
50 public function getBits() {
51 return $this->row->log_deleted;
52 }
53
54 public function setBits( $bits ) {
55 $dbw = wfGetDB( DB_MASTER );
56 $dbw->update( 'recentchanges',
57 array(
58 'rc_deleted' => $bits,
59 'rc_patrolled' => 1
60 ),
61 array(
62 'rc_logid' => $this->row->log_id,
63 'rc_timestamp' => $this->row->log_timestamp // index
64 ),
65 __METHOD__
66 );
67 $dbw->update( 'logging',
68 array( 'log_deleted' => $bits ),
69 array(
70 'log_id' => $this->row->log_id,
71 'log_deleted' => $this->getBits()
72 ),
73 __METHOD__
74 );
75
76 return (bool)$dbw->affectedRows();
77 }
78
79 public function getHTML() {
80 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
81 $this->row->log_timestamp, $this->list->getUser() ) );
82 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
83 $formatter = LogFormatter::newFromRow( $this->row );
84 $formatter->setContext( $this->list->getContext() );
85 $formatter->setAudience( LogFormatter::FOR_THIS_USER );
86
87 // Log link for this page
88 $loglink = Linker::link(
89 SpecialPage::getTitleFor( 'Log' ),
90 $this->list->msg( 'log' )->escaped(),
91 array(),
92 array( 'page' => $title->getPrefixedText() )
93 );
94 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
95 // User links and action text
96 $action = $formatter->getActionText();
97 // Comment
98 $comment = $this->list->getLanguage()->getDirMark()
99 . Linker::commentBlock( $this->row->log_comment );
100
101 if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
102 $comment = '<span class="history-deleted">' . $comment . '</span>';
103 }
104
105 return "<li>$loglink $date $action $comment</li>";
106 }
107
108 public function getApiData( ApiResult $result ) {
109 $logEntry = DatabaseLogEntry::newFromRow( $this->row );
110 $user = $this->list->getUser();
111 $ret = array(
112 'id' => $logEntry->getId(),
113 'type' => $logEntry->getType(),
114 'action' => $logEntry->getSubtype(),
115 );
116 $ret += $logEntry->isDeleted( LogPage::DELETED_USER )
117 ? array( 'userhidden' => '' )
118 : array();
119 $ret += $logEntry->isDeleted( LogPage::DELETED_COMMENT )
120 ? array( 'commenthidden' => '' )
121 : array();
122 $ret += $logEntry->isDeleted( LogPage::DELETED_ACTION )
123 ? array( 'actionhidden' => '' )
124 : array();
125
126 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
127 ApiQueryLogEvents::addLogParams(
128 $result,
129 $ret,
130 $logEntry->getParameters(),
131 $logEntry->getType(),
132 $logEntry->getSubtype(),
133 $logEntry->getTimestamp(),
134 $logEntry->isLegacy()
135 );
136 }
137 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) {
138 $ret += array(
139 'userid' => $this->row->log_user,
140 'user' => $this->row->log_user_text,
141 );
142 }
143 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
144 $ret += array(
145 'comment' => $this->row->log_comment,
146 );
147 }
148
149 return $ret;
150 }
151 }