MediaWiki  1.34.0
RevDelRevisionItem.php
Go to the documentation of this file.
1 <?php
23 
31  public $revision;
32 
33  public function __construct( $list, $row ) {
34  parent::__construct( $list, $row );
35  $this->revision = static::initRevision( $list, $row );
36  }
37 
45  protected static function initRevision( $list, $row ) {
46  return new Revision( $row );
47  }
48 
49  public function getIdField() {
50  return 'rev_id';
51  }
52 
53  public function getTimestampField() {
54  return 'rev_timestamp';
55  }
56 
57  public function getAuthorIdField() {
58  return 'rev_user';
59  }
60 
61  public function getAuthorNameField() {
62  return 'rev_user_text';
63  }
64 
65  public function getAuthorActorField() {
66  return 'rev_actor';
67  }
68 
69  public function canView() {
70  return $this->revision->userCan(
71  RevisionRecord::DELETED_RESTRICTED, $this->list->getUser()
72  );
73  }
74 
75  public function canViewContent() {
76  return $this->revision->userCan(
77  RevisionRecord::DELETED_TEXT, $this->list->getUser()
78  );
79  }
80 
81  public function getBits() {
82  return $this->revision->getVisibility();
83  }
84 
85  public function setBits( $bits ) {
86  $dbw = wfGetDB( DB_MASTER );
87  // Update revision table
88  $dbw->update( 'revision',
89  [ 'rev_deleted' => $bits ],
90  [
91  'rev_id' => $this->revision->getId(),
92  'rev_page' => $this->revision->getPage(),
93  'rev_deleted' => $this->getBits() // cas
94  ],
95  __METHOD__
96  );
97  if ( !$dbw->affectedRows() ) {
98  // Concurrent fail!
99  return false;
100  }
101  // Update recentchanges table
102  $dbw->update( 'recentchanges',
103  [
104  'rc_deleted' => $bits,
105  'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
106  ],
107  [
108  'rc_this_oldid' => $this->revision->getId(), // condition
109  // non-unique timestamp index
110  'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ),
111  ],
112  __METHOD__
113  );
114 
115  return true;
116  }
117 
118  public function isDeleted() {
119  return $this->revision->isDeleted( RevisionRecord::DELETED_TEXT );
120  }
121 
122  public function isHideCurrentOp( $newBits ) {
123  return ( $newBits & RevisionRecord::DELETED_TEXT )
124  && $this->list->getCurrent() == $this->getId();
125  }
126 
132  protected function getRevisionLink() {
133  $date = $this->list->getLanguage()->userTimeAndDate(
134  $this->revision->getTimestamp(), $this->list->getUser() );
135 
136  if ( $this->isDeleted() && !$this->canViewContent() ) {
137  return htmlspecialchars( $date );
138  }
139 
140  return $this->getLinkRenderer()->makeKnownLink(
141  $this->list->title,
142  $date,
143  [],
144  [
145  'oldid' => $this->revision->getId(),
146  'unhide' => 1
147  ]
148  );
149  }
150 
156  protected function getDiffLink() {
157  if ( $this->isDeleted() && !$this->canViewContent() ) {
158  return $this->list->msg( 'diff' )->escaped();
159  } else {
160  return $this->getLinkRenderer()->makeKnownLink(
161  $this->list->title,
162  $this->list->msg( 'diff' )->text(),
163  [],
164  [
165  'diff' => $this->revision->getId(),
166  'oldid' => 'prev',
167  'unhide' => 1
168  ]
169  );
170  }
171  }
172 
177  public function getHTML() {
178  $difflink = $this->list->msg( 'parentheses' )
179  ->rawParams( $this->getDiffLink() )->escaped();
180  $revlink = $this->getRevisionLink();
181  $userlink = Linker::revUserLink( $this->revision );
182  $comment = Linker::revComment( $this->revision );
183  if ( $this->isDeleted() ) {
184  $revlink = "<span class=\"history-deleted\">$revlink</span>";
185  }
186  $content = "$difflink $revlink $userlink $comment";
187  $attribs = [];
188  $tags = $this->getTags();
189  if ( $tags ) {
190  list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow(
191  $tags,
192  'revisiondelete',
193  $this->list->getContext()
194  );
195  $content .= " $tagSummary";
196  $attribs['class'] = implode( ' ', $classes );
197  }
198  return Xml::tags( 'li', $attribs, $content );
199  }
200 
204  public function getTags() {
205  return $this->row->ts_tags;
206  }
207 
208  public function getApiData( ApiResult $result ) {
209  $rev = $this->revision;
210  $user = $this->list->getUser();
211  $ret = [
212  'id' => $rev->getId(),
213  'timestamp' => wfTimestamp( TS_ISO_8601, $rev->getTimestamp() ),
214  'userhidden' => (bool)$rev->isDeleted( RevisionRecord::DELETED_USER ),
215  'commenthidden' => (bool)$rev->isDeleted( RevisionRecord::DELETED_COMMENT ),
216  'texthidden' => (bool)$rev->isDeleted( RevisionRecord::DELETED_TEXT ),
217  ];
218  if ( $rev->userCan( RevisionRecord::DELETED_USER, $user ) ) {
219  $ret += [
220  'userid' => $rev->getUser( RevisionRecord::FOR_THIS_USER ),
221  'user' => $rev->getUserText( RevisionRecord::FOR_THIS_USER ),
222  ];
223  }
224  if ( $rev->userCan( RevisionRecord::DELETED_COMMENT, $user ) ) {
225  $ret += [
226  'comment' => $rev->getComment( RevisionRecord::FOR_THIS_USER ),
227  ];
228  }
229 
230  return $ret;
231  }
232 }
RevDelRevisionItem\getBits
getBits()
Get the current deletion bitfield value.
Definition: RevDelRevisionItem.php:81
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
RevDelRevisionItem\isDeleted
isDeleted()
Definition: RevDelRevisionItem.php:118
Revision\getUser
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's user id if it's available to the specified audience.
Definition: Revision.php:603
Linker\revUserLink
static revUserLink( $rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1101
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1869
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:122
RevDelRevisionItem\getAuthorActorField
getAuthorActorField()
Get the DB field name storing actor ids.
Definition: RevDelRevisionItem.php:65
Linker\revComment
static revComment(Revision $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:1577
RevDelRevisionItem\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevDelRevisionItem.php:49
RevisionItemBase\$list
RevisionListBase $list
The parent.
Definition: RevisionItemBase.php:30
Revision
Definition: Revision.php:40
RevDelRevisionItem\__construct
__construct( $list, $row)
Definition: RevDelRevisionItem.php:33
RevDelRevisionItem\canView
canView()
Returns true if the current user can view the item.
Definition: RevDelRevisionItem.php:69
RevDelRevisionItem\initRevision
static initRevision( $list, $row)
Create revision object from $row sourced from $list.
Definition: RevDelRevisionItem.php:45
RevDelRevisionItem\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.
Definition: RevDelRevisionItem.php:75
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
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2575
DB_MASTER
const DB_MASTER
Definition: defines.php:26
RevDelRevisionItem\getDiffLink
getDiffLink()
Get the HTML link to the diff.
Definition: RevDelRevisionItem.php:156
$content
$content
Definition: router.php:78
RevDelRevisionItem\getRevisionLink
getRevisionLink()
Get the HTML link to the revision text.
Definition: RevDelRevisionItem.php:132
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:208
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
RecentChange\PRC_AUTOPATROLLED
const PRC_AUTOPATROLLED
Definition: RecentChange.php:81
RevDelRevisionItem\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.
Definition: RevDelRevisionItem.php:53
RevDelRevisionItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevDelRevisionItem.php:57
RevDelRevisionItem\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.
Definition: RevDelRevisionItem.php:61
RevDelRevisionItem\getTags
getTags()
Definition: RevDelRevisionItem.php:204
RevDelRevisionItem
Definition: RevDelRevisionItem.php:29
RevDelRevisionItem\setBits
setBits( $bits)
Set the visibility of the item.
Definition: RevDelRevisionItem.php:85
RevDelRevisionItem\$revision
Revision $revision
Definition: RevDelRevisionItem.php:31
ChangeTags\formatSummaryRow
static formatSummaryRow( $tags, $page, IContextSource $context=null)
Creates HTML for the given tags.
Definition: ChangeTags.php:94
RevDelRevisionItem\getHTML
getHTML()
Definition: RevDelRevisionItem.php:177
RevDelItem
Abstract base class for deletable items.
Definition: RevDelItem.php:25