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 $this->getRevisionRecord()->userCan(
83  RevisionRecord::DELETED_RESTRICTED,
84  $this->list->getAuthority()
85  );
86  }
87 
88  public function canViewContent() {
89  return $this->getRevisionRecord()->userCan(
90  RevisionRecord::DELETED_TEXT,
91  $this->list->getAuthority()
92  );
93  }
94 
95  public function getBits() {
96  return $this->getRevisionRecord()->getVisibility();
97  }
98 
99  public function setBits( $bits ) {
100  $revRecord = $this->getRevisionRecord();
101 
102  $dbw = wfGetDB( DB_PRIMARY );
103  // Update revision table
104  $dbw->update( 'revision',
105  [ 'rev_deleted' => $bits ],
106  [
107  'rev_id' => $revRecord->getId(),
108  'rev_page' => $revRecord->getPageId(),
109  'rev_deleted' => $this->getBits() // cas
110  ],
111  __METHOD__
112  );
113  if ( !$dbw->affectedRows() ) {
114  // Concurrent fail!
115  return false;
116  }
117  // Update recentchanges table
118  $dbw->update( 'recentchanges',
119  [
120  'rc_deleted' => $bits,
121  'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
122  ],
123  [
124  'rc_this_oldid' => $revRecord->getId(), // condition
125  ],
126  __METHOD__
127  );
128 
129  return true;
130  }
131 
132  public function isDeleted() {
133  return $this->getRevisionRecord()->isDeleted( RevisionRecord::DELETED_TEXT );
134  }
135 
136  public function isHideCurrentOp( $newBits ) {
137  return ( $newBits & RevisionRecord::DELETED_TEXT )
138  && $this->list->getCurrent() == $this->getId();
139  }
140 
146  protected function getRevisionLink() {
147  $date = $this->list->getLanguage()->userTimeAndDate(
148  $this->getRevisionRecord()->getTimestamp(),
149  $this->list->getUser()
150  );
151 
152  if ( $this->isDeleted() && !$this->canViewContent() ) {
153  return htmlspecialchars( $date );
154  }
155 
156  return $this->getLinkRenderer()->makeKnownLink(
157  $this->list->getPage(),
158  $date,
159  [],
160  [
161  'oldid' => $this->getRevisionRecord()->getId(),
162  'unhide' => 1
163  ]
164  );
165  }
166 
172  protected function getDiffLink() {
173  if ( $this->isDeleted() && !$this->canViewContent() ) {
174  return $this->list->msg( 'diff' )->escaped();
175  } else {
176  return $this->getLinkRenderer()->makeKnownLink(
177  $this->list->getPage(),
178  $this->list->msg( 'diff' )->text(),
179  [],
180  [
181  'diff' => $this->getRevisionRecord()->getId(),
182  'oldid' => 'prev',
183  'unhide' => 1
184  ]
185  );
186  }
187  }
188 
193  public function getHTML() {
194  $revRecord = $this->getRevisionRecord();
195 
196  $difflink = $this->list->msg( 'parentheses' )
197  ->rawParams( $this->getDiffLink() )->escaped();
198  $revlink = $this->getRevisionLink();
199  $userlink = Linker::revUserLink( $revRecord );
200  $comment = Linker::revComment( $revRecord );
201  if ( $this->isDeleted() ) {
202  $class = Linker::getRevisionDeletedClass( $revRecord );
203  $revlink = "<span class=\"$class\">$revlink</span>";
204  }
205  $content = "$difflink $revlink $userlink $comment";
206  $attribs = [];
207  $tags = $this->getTags();
208  if ( $tags ) {
209  list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow(
210  $tags,
211  'revisiondelete',
212  $this->list->getContext()
213  );
214  $content .= " $tagSummary";
215  $attribs['class'] = implode( ' ', $classes );
216  }
217  return Xml::tags( 'li', $attribs, $content );
218  }
219 
223  public function getTags() {
224  return $this->row->ts_tags;
225  }
226 
227  public function getApiData( ApiResult $result ) {
228  $revRecord = $this->getRevisionRecord();
229  $authority = $this->list->getAuthority();
230  $ret = [
231  'id' => $revRecord->getId(),
232  'timestamp' => wfTimestamp( TS_ISO_8601, $revRecord->getTimestamp() ),
233  'userhidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_USER ),
234  'commenthidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_COMMENT ),
235  'texthidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_TEXT ),
236  ];
237  if ( $revRecord->userCan( RevisionRecord::DELETED_USER, $authority ) ) {
238  $revUser = $revRecord->getUser( RevisionRecord::FOR_THIS_USER, $authority );
239  $ret += [
240  'userid' => $revUser ? $revUser->getId() : 0,
241  'user' => $revUser ? $revUser->getName() : '',
242  ];
243  }
244  if ( $revRecord->userCan( RevisionRecord::DELETED_COMMENT, $authority ) ) {
245  $revComment = $revRecord->getComment( RevisionRecord::FOR_THIS_USER, $authority );
246  $ret += [
247  'comment' => $revComment ? $revComment->text : ''
248  ];
249  }
250 
251  return $ret;
252  }
253 }
RevDelRevisionItem\getBits
getBits()
Get the current deletion bitfield value.
Definition: RevDelRevisionItem.php:95
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
RevDelRevisionItem\isDeleted
isDeleted()
Definition: RevDelRevisionItem.php:132
RevisionListBase
List for revision table items for a single page.
Definition: RevisionListBase.php:30
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:184
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1692
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:136
RevDelRevisionItem\getAuthorActorField
getAuthorActorField()
Get the DB field name storing actor ids.
Definition: RevDelRevisionItem.php:77
Linker\revUserLink
static revUserLink(RevisionRecord $revRecord, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1275
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:31
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:88
ApiResult
This class represents the result of the API operations.
Definition: ApiResult.php:35
Linker\getRevisionDeletedClass
static getRevisionDeletedClass(RevisionRecord $revisionRecord)
Returns css class of a deleted revision.
Definition: Linker.php:1303
RevisionItemBase\getLinkRenderer
getLinkRenderer()
Returns an instance of LinkRenderer.
Definition: RevisionItemBase.php:178
RevDelRevisionItem\$revisionRecord
RevisionRecord $revisionRecord
Definition: RevDelRevisionItem.php:32
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2226
RevDelRevisionItem\initRevisionRecord
static initRevisionRecord( $list, $row)
Create RevisionRecord object from $row sourced from $list.
Definition: RevDelRevisionItem.php:46
Linker\revComment
static revComment(RevisionRecord $revRecord, $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:1784
RevDelRevisionItem\getDiffLink
getDiffLink()
Get the HTML link to the diff.
Definition: RevDelRevisionItem.php:172
$content
$content
Definition: router.php:76
RevDelRevisionItem\getRevisionLink
getRevisionLink()
Get the HTML link to the revision text.
Definition: RevDelRevisionItem.php:146
RevisionItemBase\getId
getId()
Get the ID, as it would appear in the ids URL parameter.
Definition: RevisionItemBase.php:95
RevDelRevisionItem\getApiData
getApiData(ApiResult $result)
Get the return information about the revision for the API.
Definition: RevDelRevisionItem.php:227
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:132
RevisionItemBase\getTimestamp
getTimestamp()
Get the timestamp in MW 14-char form.
Definition: RevisionItemBase.php:122
RevDelRevisionItem\__construct
__construct(RevisionListBase $list, $row)
Definition: RevDelRevisionItem.php:34
RecentChange\PRC_AUTOPATROLLED
const PRC_AUTOPATROLLED
Definition: RecentChange.php:93
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:223
RevDelRevisionItem
Definition: RevDelRevisionItem.php:30
RevisionItemBase\$row
stdClass $row
The database result row.
Definition: RevisionItemBase.php:34
RevDelRevisionItem\setBits
setBits( $bits)
Set the visibility of the item.
Definition: RevDelRevisionItem.php:99
ChangeTags\formatSummaryRow
static formatSummaryRow( $tags, $page, IContextSource $context=null)
Creates HTML for the given tags.
Definition: ChangeTags.php:194
RevDelRevisionItem\getHTML
getHTML()
Definition: RevDelRevisionItem.php:193
RevDelItem
Abstract base class for deletable items.
Definition: RevDelItem.php:25