MediaWiki  master
RevDelRevisionItem.php
Go to the documentation of this file.
1 <?php
24 
33 
34  public function __construct( RevisionListBase $list, $row ) {
35  parent::__construct( $list, $row );
36  $this->revisionRecord = static::initRevisionRecord( $list, $row );
37  }
38 
46  protected static function initRevisionRecord( $list, $row ) {
47  return MediaWikiServices::getInstance()
48  ->getRevisionFactory()
49  ->newRevisionFromRow( $row );
50  }
51 
57  protected function getRevisionRecord() : RevisionRecord {
58  return $this->revisionRecord;
59  }
60 
61  public function getIdField() {
62  return 'rev_id';
63  }
64 
65  public function getTimestampField() {
66  return 'rev_timestamp';
67  }
68 
69  public function getAuthorIdField() {
70  return 'rev_user';
71  }
72 
73  public function getAuthorNameField() {
74  return 'rev_user_text';
75  }
76 
77  public function getAuthorActorField() {
78  return 'rev_actor';
79  }
80 
81  public function canView() {
82  return RevisionRecord::userCanBitfield(
83  $this->getRevisionRecord()->getVisibility(),
84  RevisionRecord::DELETED_RESTRICTED,
85  $this->list->getUser()
86  );
87  }
88 
89  public function canViewContent() {
90  return RevisionRecord::userCanBitfield(
91  $this->getRevisionRecord()->getVisibility(),
92  RevisionRecord::DELETED_TEXT,
93  $this->list->getUser()
94  );
95  }
96 
97  public function getBits() {
98  return $this->getRevisionRecord()->getVisibility();
99  }
100 
101  public function setBits( $bits ) {
102  $revRecord = $this->getRevisionRecord();
103 
104  $dbw = wfGetDB( DB_MASTER );
105  // Update revision table
106  $dbw->update( 'revision',
107  [ 'rev_deleted' => $bits ],
108  [
109  'rev_id' => $revRecord->getId(),
110  'rev_page' => $revRecord->getPageId(),
111  'rev_deleted' => $this->getBits() // cas
112  ],
113  __METHOD__
114  );
115  if ( !$dbw->affectedRows() ) {
116  // Concurrent fail!
117  return false;
118  }
119  // Update recentchanges table
120  $dbw->update( 'recentchanges',
121  [
122  'rc_deleted' => $bits,
123  'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
124  ],
125  [
126  'rc_this_oldid' => $revRecord->getId(), // condition
127  ],
128  __METHOD__
129  );
130 
131  return true;
132  }
133 
134  public function isDeleted() {
135  return $this->getRevisionRecord()->isDeleted( RevisionRecord::DELETED_TEXT );
136  }
137 
138  public function isHideCurrentOp( $newBits ) {
139  return ( $newBits & RevisionRecord::DELETED_TEXT )
140  && $this->list->getCurrent() == $this->getId();
141  }
142 
148  protected function getRevisionLink() {
149  $date = $this->list->getLanguage()->userTimeAndDate(
150  $this->getRevisionRecord()->getTimestamp(),
151  $this->list->getUser()
152  );
153 
154  if ( $this->isDeleted() && !$this->canViewContent() ) {
155  return htmlspecialchars( $date );
156  }
157 
158  return $this->getLinkRenderer()->makeKnownLink(
159  $this->list->title,
160  $date,
161  [],
162  [
163  'oldid' => $this->getRevisionRecord()->getId(),
164  'unhide' => 1
165  ]
166  );
167  }
168 
174  protected function getDiffLink() {
175  if ( $this->isDeleted() && !$this->canViewContent() ) {
176  return $this->list->msg( 'diff' )->escaped();
177  } else {
178  return $this->getLinkRenderer()->makeKnownLink(
179  $this->list->title,
180  $this->list->msg( 'diff' )->text(),
181  [],
182  [
183  'diff' => $this->getRevisionRecord()->getId(),
184  'oldid' => 'prev',
185  'unhide' => 1
186  ]
187  );
188  }
189  }
190 
195  public function getHTML() {
196  $revRecord = $this->getRevisionRecord();
197 
198  $difflink = $this->list->msg( 'parentheses' )
199  ->rawParams( $this->getDiffLink() )->escaped();
200  $revlink = $this->getRevisionLink();
201  $userlink = Linker::revUserLink( $revRecord );
202  $comment = Linker::revComment( $revRecord );
203  if ( $this->isDeleted() ) {
204  $revlink = "<span class=\"history-deleted\">$revlink</span>";
205  }
206  $content = "$difflink $revlink $userlink $comment";
207  $attribs = [];
208  $tags = $this->getTags();
209  if ( $tags ) {
210  list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow(
211  $tags,
212  'revisiondelete',
213  $this->list->getContext()
214  );
215  $content .= " $tagSummary";
216  $attribs['class'] = implode( ' ', $classes );
217  }
218  return Xml::tags( 'li', $attribs, $content );
219  }
220 
224  public function getTags() {
225  return $this->row->ts_tags;
226  }
227 
228  public function getApiData( ApiResult $result ) {
229  $revRecord = $this->getRevisionRecord();
230  $user = $this->list->getUser();
231  $ret = [
232  'id' => $revRecord->getId(),
233  'timestamp' => wfTimestamp( TS_ISO_8601, $revRecord->getTimestamp() ),
234  'userhidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_USER ),
235  'commenthidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_COMMENT ),
236  'texthidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_TEXT ),
237  ];
238  if ( RevisionRecord::userCanBitfield(
239  $revRecord->getVisibility(),
240  RevisionRecord::DELETED_USER,
241  $user
242  ) ) {
243  $revUser = $revRecord->getUser( RevisionRecord::FOR_THIS_USER, $user );
244  $ret += [
245  'userid' => $revUser ? $revUser->getId() : 0,
246  'user' => $revUser ? $revUser->getName() : '',
247  ];
248  }
249  if ( RevisionRecord::userCanBitfield(
250  $revRecord->getVisibility(),
251  RevisionRecord::DELETED_COMMENT,
252  $user
253  ) ) {
254  $revComment = $revRecord->getComment( RevisionRecord::FOR_THIS_USER, $user );
255  $ret += [
256  'comment' => $revComment ? $revComment->text : ''
257  ];
258  }
259 
260  return $ret;
261  }
262 }
RevDelRevisionItem\getBits
getBits()
Get the current deletion bitfield value.
Definition: RevDelRevisionItem.php:97
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
RevDelRevisionItem\isDeleted
isDeleted()
Definition: RevDelRevisionItem.php:134
Linker\revUserLink
static revUserLink( $rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1101
RevisionListBase
List for revision table items for a single page.
Definition: RevisionListBase.php:29
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:149
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1806
RevDelRevisionItem\isHideCurrentOp
isHideCurrentOp( $newBits)
Returns true if the item is "current", and the operation to set the given bits can't be executed for ...
Definition: RevDelRevisionItem.php:138
Linker\revComment
static revComment( $rev, $local=false, $isPublic=false, $useParentheses=true)
Wrap and format the given revision's comment block, if the current user is allowed to view it.
Definition: Linker.php:1606
RevDelRevisionItem\getAuthorActorField
getAuthorActorField()
Get the DB field name storing actor ids.
Definition: RevDelRevisionItem.php:77
RevDelRevisionItem\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevDelRevisionItem.php:61
RevisionItemBase\$list
RevisionListBase $list
The parent.
Definition: RevisionItemBase.php:30
RevDelRevisionItem\canView
canView()
Returns true if the current user can view the item.
Definition: RevDelRevisionItem.php:81
RevDelRevisionItem\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.
Definition: RevDelRevisionItem.php:89
ApiResult
This class represents the result of the API operations.
Definition: ApiResult.php:35
RevisionItemBase\getLinkRenderer
getLinkRenderer()
Returns an instance of LinkRenderer.
Definition: RevisionItemBase.php:174
RevDelRevisionItem\$revisionRecord
RevisionRecord $revisionRecord
Definition: RevDelRevisionItem.php:32
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2463
RevDelRevisionItem\initRevisionRecord
static initRevisionRecord( $list, $row)
Create revision object from $row sourced from $list.
Definition: RevDelRevisionItem.php:46
DB_MASTER
const DB_MASTER
Definition: defines.php:26
RevDelRevisionItem\getDiffLink
getDiffLink()
Get the HTML link to the diff.
Definition: RevDelRevisionItem.php:174
$content
$content
Definition: router.php:76
RevDelRevisionItem\getRevisionLink
getRevisionLink()
Get the HTML link to the revision text.
Definition: RevDelRevisionItem.php:148
RevisionItemBase\getId
getId()
Get the ID, as it would appear in the ids URL parameter.
Definition: RevisionItemBase.php:94
RevDelRevisionItem\getApiData
getApiData(ApiResult $result)
Get the return information about the revision for the API.
Definition: RevDelRevisionItem.php:228
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:130
RevisionItemBase\$row
$row
The database result row.
Definition: RevisionItemBase.php:33
RevisionItemBase\getTimestamp
getTimestamp()
Get the timestamp in MW 14-char form.
Definition: RevisionItemBase.php:121
RevDelRevisionItem\__construct
__construct(RevisionListBase $list, $row)
Definition: RevDelRevisionItem.php:34
RecentChange\PRC_AUTOPATROLLED
const PRC_AUTOPATROLLED
Definition: RecentChange.php:82
RevDelRevisionItem\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.
Definition: RevDelRevisionItem.php:65
RevDelRevisionItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevDelRevisionItem.php:69
RevDelRevisionItem\getRevisionRecord
getRevisionRecord()
Get the RevisionRecord for the item.
Definition: RevDelRevisionItem.php:57
RevDelRevisionItem\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.
Definition: RevDelRevisionItem.php:73
RevDelRevisionItem\getTags
getTags()
Definition: RevDelRevisionItem.php:224
RevDelRevisionItem
Definition: RevDelRevisionItem.php:30
RevDelRevisionItem\setBits
setBits( $bits)
Set the visibility of the item.
Definition: RevDelRevisionItem.php:101
ChangeTags\formatSummaryRow
static formatSummaryRow( $tags, $page, IContextSource $context=null)
Creates HTML for the given tags.
Definition: ChangeTags.php:100
RevDelRevisionItem\getHTML
getHTML()
Definition: RevDelRevisionItem.php:195
RevDelItem
Abstract base class for deletable items.
Definition: RevDelItem.php:25