Split RevisionDelete.php to separate files
[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 var $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 canView() {
51 return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->list->getUser() );
52 }
53
54 public function canViewContent() {
55 return $this->revision->userCan( Revision::DELETED_TEXT, $this->list->getUser() );
56 }
57
58 public function getBits() {
59 return $this->revision->getVisibility();
60 }
61
62 public function setBits( $bits ) {
63 $dbw = wfGetDB( DB_MASTER );
64 // Update revision table
65 $dbw->update( 'revision', array( 'rev_deleted' => $bits ), array( 'rev_id' => $this->revision->getId(), 'rev_page' => $this->revision->getPage(), 'rev_deleted' => $this->getBits() ), __METHOD__ );
66 if ( !$dbw->affectedRows() ) {
67 // Concurrent fail!
68 return false;
69 }
70 // Update recentchanges table
71 $dbw->update( 'recentchanges', array( 'rc_deleted' => $bits, 'rc_patrolled' => 1 ), array( 'rc_this_oldid' => $this->revision->getId(), // condition
72 // non-unique timestamp index
73 'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ), ), __METHOD__ );
74
75 return true;
76 }
77
78 public function isDeleted() {
79 return $this->revision->isDeleted( Revision::DELETED_TEXT );
80 }
81
82 public function isHideCurrentOp( $newBits ) {
83 return ( $newBits & Revision::DELETED_TEXT ) && $this->list->getCurrent() == $this->getId();
84 }
85
86 /**
87 * Get the HTML link to the revision text.
88 * Overridden by RevDelArchiveItem.
89 * @return string
90 */
91 protected function getRevisionLink() {
92 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate( $this->revision->getTimestamp(), $this->list->getUser() ) );
93
94 if ( $this->isDeleted() && !$this->canViewContent() ) {
95 return $date;
96 }
97
98 return Linker::linkKnown( $this->list->title, $date, array(), array( 'oldid' => $this->revision->getId(), 'unhide' => 1 ) );
99 }
100
101 /**
102 * Get the HTML link to the diff.
103 * Overridden by RevDelArchiveItem
104 * @return string
105 */
106 protected function getDiffLink() {
107 if ( $this->isDeleted() && !$this->canViewContent() ) {
108 return $this->list->msg( 'diff' )->escaped();
109 } else {
110 return Linker::linkKnown( $this->list->title, $this->list->msg( 'diff' )->escaped(), array(), array( 'diff' => $this->revision->getId(), 'oldid' => 'prev', 'unhide' => 1 ) );
111 }
112 }
113
114 public function getHTML() {
115 $difflink = $this->list->msg( 'parentheses' )
116 ->rawParams( $this->getDiffLink() )->escaped();
117 $revlink = $this->getRevisionLink();
118 $userlink = Linker::revUserLink( $this->revision );
119 $comment = Linker::revComment( $this->revision );
120 if ( $this->isDeleted() ) {
121 $revlink = "<span class=\"history-deleted\">$revlink</span>";
122 }
123
124 return "<li>$difflink $revlink $userlink $comment</li>";
125 }
126
127 public function getApiData( ApiResult $result ) {
128 $rev = $this->revision;
129 $user = $this->list->getUser();
130 $ret = array( 'id' => $rev->getId(), 'timestamp' => wfTimestamp( TS_ISO_8601, $rev->getTimestamp() ), );
131 $ret += $rev->isDeleted( Revision::DELETED_USER ) ? array( 'userhidden' => '' ) : array();
132 $ret += $rev->isDeleted( Revision::DELETED_COMMENT ) ? array( 'commenthidden' => '' ) : array();
133 $ret += $rev->isDeleted( Revision::DELETED_TEXT ) ? array( 'texthidden' => '' ) : array();
134 if ( $rev->userCan( Revision::DELETED_USER, $user ) ) {
135 $ret += array( 'userid' => $rev->getUser( Revision::FOR_THIS_USER ), 'user' => $rev->getUserText( Revision::FOR_THIS_USER ), );
136 }
137 if ( $rev->userCan( Revision::DELETED_COMMENT, $user ) ) {
138 $ret += array( 'comment' => $rev->getComment( Revision::FOR_THIS_USER ), );
139 }
140
141 return $ret;
142 }
143 }