MediaWiki REL1_31
RevDelRevisionItem.php
Go to the documentation of this file.
1<?php
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' => RecentChange::PRC_PATROLLED
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
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
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
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
185 public function getTags() {
186 return $this->row->ts_tags;
187 }
188
189 public function getApiData( ApiResult $result ) {
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}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
This class represents the result of the API operations.
Definition ApiResult.php:33
static formatSummaryRow( $tags, $page, IContextSource $context=null)
Creates HTML for the given tags.
static revComment(Revision $rev, $local=false, $isPublic=false)
Wrap and format the given revision's comment block, if the current user is allowed to view it.
Definition Linker.php:1480
static revUserLink( $rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition Linker.php:1048
Abstract base class for deletable items.
Item class for a live revision table row.
setBits( $bits)
Set the visibility of the item.
canViewContent()
Returns true if the current user can view the item text/file.
getTimestampField()
Get the DB field name storing timestamps.
canView()
Returns true if the current user can view the item.
getAuthorActorField()
Get the DB field name storing actor ids.
getBits()
Get the current deletion bitfield value.
getAuthorNameField()
Get the DB field name storing user names.
getApiData(ApiResult $result)
Get the return information about the revision for the API.
getAuthorIdField()
Get the DB field name storing user ids.
getRevisionLink()
Get the HTML link to the revision text.
isHideCurrentOp( $newBits)
Returns true if the item is "current", and the operation to set the given bits can't be executed for ...
getIdField()
Get the DB field name associated with the ID list.
getDiffLink()
Get the HTML link to the diff.
$row
The database result row.
RevisionListBase $list
The parent.
getId()
Get the ID, as it would appear in the ids URL parameter.
getLinkRenderer()
Returns an instance of LinkRenderer.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:2005
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition hooks.txt:2014
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition hooks.txt:1777
const DB_MASTER
Definition defines.php:29