Add `actor` table and code to start using it
[lhc/web/wiklou.git] / includes / revisiondelete / RevDelRevisionItem.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 live revision table row
24 */
25 class RevDelRevisionItem extends RevDelItem {
26 /** @var Revision */
27 public $revision;
28
29 public function __construct( $list, $row ) {
30 parent::__construct( $list, $row );
31 $this->revision = new Revision( $row );
32 }
33
34 public function getIdField() {
35 return 'rev_id';
36 }
37
38 public function getTimestampField() {
39 return 'rev_timestamp';
40 }
41
42 public function getAuthorIdField() {
43 return 'rev_user';
44 }
45
46 public function getAuthorNameField() {
47 return 'rev_user_text';
48 }
49
50 public function getAuthorActorField() {
51 return 'rev_actor';
52 }
53
54 public function canView() {
55 return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->list->getUser() );
56 }
57
58 public function canViewContent() {
59 return $this->revision->userCan( Revision::DELETED_TEXT, $this->list->getUser() );
60 }
61
62 public function getBits() {
63 return $this->revision->getVisibility();
64 }
65
66 public function setBits( $bits ) {
67 $dbw = wfGetDB( DB_MASTER );
68 // Update revision table
69 $dbw->update( 'revision',
70 [ 'rev_deleted' => $bits ],
71 [
72 'rev_id' => $this->revision->getId(),
73 'rev_page' => $this->revision->getPage(),
74 'rev_deleted' => $this->getBits() // cas
75 ],
76 __METHOD__
77 );
78 if ( !$dbw->affectedRows() ) {
79 // Concurrent fail!
80 return false;
81 }
82 // Update recentchanges table
83 $dbw->update( 'recentchanges',
84 [
85 'rc_deleted' => $bits,
86 'rc_patrolled' => 1
87 ],
88 [
89 'rc_this_oldid' => $this->revision->getId(), // condition
90 // non-unique timestamp index
91 'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ),
92 ],
93 __METHOD__
94 );
95
96 return true;
97 }
98
99 public function isDeleted() {
100 return $this->revision->isDeleted( Revision::DELETED_TEXT );
101 }
102
103 public function isHideCurrentOp( $newBits ) {
104 return ( $newBits & Revision::DELETED_TEXT )
105 && $this->list->getCurrent() == $this->getId();
106 }
107
108 /**
109 * Get the HTML link to the revision text.
110 * Overridden by RevDelArchiveItem.
111 * @return string
112 */
113 protected function getRevisionLink() {
114 $date = $this->list->getLanguage()->userTimeAndDate(
115 $this->revision->getTimestamp(), $this->list->getUser() );
116
117 if ( $this->isDeleted() && !$this->canViewContent() ) {
118 return htmlspecialchars( $date );
119 }
120
121 return $this->getLinkRenderer()->makeKnownLink(
122 $this->list->title,
123 $date,
124 [],
125 [
126 'oldid' => $this->revision->getId(),
127 'unhide' => 1
128 ]
129 );
130 }
131
132 /**
133 * Get the HTML link to the diff.
134 * Overridden by RevDelArchiveItem
135 * @return string
136 */
137 protected function getDiffLink() {
138 if ( $this->isDeleted() && !$this->canViewContent() ) {
139 return $this->list->msg( 'diff' )->escaped();
140 } else {
141 return $this->getLinkRenderer()->makeKnownLink(
142 $this->list->title,
143 $this->list->msg( 'diff' )->text(),
144 [],
145 [
146 'diff' => $this->revision->getId(),
147 'oldid' => 'prev',
148 'unhide' => 1
149 ]
150 );
151 }
152 }
153
154 /**
155 * @return string A HTML <li> element representing this revision, showing
156 * change tags and everything
157 */
158 public function getHTML() {
159 $difflink = $this->list->msg( 'parentheses' )
160 ->rawParams( $this->getDiffLink() )->escaped();
161 $revlink = $this->getRevisionLink();
162 $userlink = Linker::revUserLink( $this->revision );
163 $comment = Linker::revComment( $this->revision );
164 if ( $this->isDeleted() ) {
165 $revlink = "<span class=\"history-deleted\">$revlink</span>";
166 }
167 $content = "$difflink $revlink $userlink $comment";
168 $attribs = [];
169 $tags = $this->getTags();
170 if ( $tags ) {
171 list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow(
172 $tags,
173 'revisiondelete',
174 $this->list->getContext()
175 );
176 $content .= " $tagSummary";
177 $attribs['class'] = implode( ' ', $classes );
178 }
179 return Xml::tags( 'li', $attribs, $content );
180 }
181
182 /**
183 * @return string Comma-separated list of tags
184 */
185 public function getTags() {
186 return $this->row->ts_tags;
187 }
188
189 public function getApiData( ApiResult $result ) {
190 $rev = $this->revision;
191 $user = $this->list->getUser();
192 $ret = [
193 'id' => $rev->getId(),
194 'timestamp' => wfTimestamp( TS_ISO_8601, $rev->getTimestamp() ),
195 'userhidden' => (bool)$rev->isDeleted( Revision::DELETED_USER ),
196 'commenthidden' => (bool)$rev->isDeleted( Revision::DELETED_COMMENT ),
197 'texthidden' => (bool)$rev->isDeleted( Revision::DELETED_TEXT ),
198 ];
199 if ( $rev->userCan( Revision::DELETED_USER, $user ) ) {
200 $ret += [
201 'userid' => $rev->getUser( Revision::FOR_THIS_USER ),
202 'user' => $rev->getUserText( Revision::FOR_THIS_USER ),
203 ];
204 }
205 if ( $rev->userCan( Revision::DELETED_COMMENT, $user ) ) {
206 $ret += [
207 'comment' => $rev->getComment( Revision::FOR_THIS_USER ),
208 ];
209 }
210
211 return $ret;
212 }
213 }