MediaWiki  master
RevDelRevisionItem.php
Go to the documentation of this file.
1 <?php
23 
31  public $revision;
32 
33  public function __construct( RevisionListBase $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  ],
110  __METHOD__
111  );
112 
113  return true;
114  }
115 
116  public function isDeleted() {
117  return $this->revision->isDeleted( RevisionRecord::DELETED_TEXT );
118  }
119 
120  public function isHideCurrentOp( $newBits ) {
121  return ( $newBits & RevisionRecord::DELETED_TEXT )
122  && $this->list->getCurrent() == $this->getId();
123  }
124 
130  protected function getRevisionLink() {
131  $date = $this->list->getLanguage()->userTimeAndDate(
132  $this->revision->getTimestamp(), $this->list->getUser() );
133 
134  if ( $this->isDeleted() && !$this->canViewContent() ) {
135  return htmlspecialchars( $date );
136  }
137 
138  return $this->getLinkRenderer()->makeKnownLink(
139  $this->list->title,
140  $date,
141  [],
142  [
143  'oldid' => $this->revision->getId(),
144  'unhide' => 1
145  ]
146  );
147  }
148 
154  protected function getDiffLink() {
155  if ( $this->isDeleted() && !$this->canViewContent() ) {
156  return $this->list->msg( 'diff' )->escaped();
157  } else {
158  return $this->getLinkRenderer()->makeKnownLink(
159  $this->list->title,
160  $this->list->msg( 'diff' )->text(),
161  [],
162  [
163  'diff' => $this->revision->getId(),
164  'oldid' => 'prev',
165  'unhide' => 1
166  ]
167  );
168  }
169  }
170 
175  public function getHTML() {
176  $difflink = $this->list->msg( 'parentheses' )
177  ->rawParams( $this->getDiffLink() )->escaped();
178  $revlink = $this->getRevisionLink();
179  $userlink = Linker::revUserLink( $this->revision );
180  $comment = Linker::revComment( $this->revision );
181  if ( $this->isDeleted() ) {
182  $revlink = "<span class=\"history-deleted\">$revlink</span>";
183  }
184  $content = "$difflink $revlink $userlink $comment";
185  $attribs = [];
186  $tags = $this->getTags();
187  if ( $tags ) {
188  list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow(
189  $tags,
190  'revisiondelete',
191  $this->list->getContext()
192  );
193  $content .= " $tagSummary";
194  $attribs['class'] = implode( ' ', $classes );
195  }
196  return Xml::tags( 'li', $attribs, $content );
197  }
198 
202  public function getTags() {
203  return $this->row->ts_tags;
204  }
205 
206  public function getApiData( ApiResult $result ) {
207  $rev = $this->revision;
208  $user = $this->list->getUser();
209  $ret = [
210  'id' => $rev->getId(),
211  'timestamp' => wfTimestamp( TS_ISO_8601, $rev->getTimestamp() ),
212  'userhidden' => (bool)$rev->isDeleted( RevisionRecord::DELETED_USER ),
213  'commenthidden' => (bool)$rev->isDeleted( RevisionRecord::DELETED_COMMENT ),
214  'texthidden' => (bool)$rev->isDeleted( RevisionRecord::DELETED_TEXT ),
215  ];
216  if ( $rev->userCan( RevisionRecord::DELETED_USER, $user ) ) {
217  $ret += [
218  'userid' => $rev->getUser( RevisionRecord::FOR_THIS_USER ),
219  'user' => $rev->getUserText( RevisionRecord::FOR_THIS_USER ),
220  ];
221  }
222  if ( $rev->userCan( RevisionRecord::DELETED_COMMENT, $user ) ) {
223  $ret += [
224  'comment' => $rev->getComment( RevisionRecord::FOR_THIS_USER ),
225  ];
226  }
227 
228  return $ret;
229  }
230 }
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:116
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
RevisionListBase
List for revision table items for a single page.
Definition: RevisionListBase.php:29
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1871
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:120
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:1573
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\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:2579
DB_MASTER
const DB_MASTER
Definition: defines.php:26
RevDelRevisionItem\getDiffLink
getDiffLink()
Get the HTML link to the diff.
Definition: RevDelRevisionItem.php:154
$content
$content
Definition: router.php:78
RevDelRevisionItem\getRevisionLink
getRevisionLink()
Get the HTML link to the revision text.
Definition: RevDelRevisionItem.php:130
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:206
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
RevDelRevisionItem\__construct
__construct(RevisionListBase $list, $row)
Definition: RevDelRevisionItem.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:202
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:99
RevDelRevisionItem\getHTML
getHTML()
Definition: RevDelRevisionItem.php:175
RevDelItem
Abstract base class for deletable items.
Definition: RevDelItem.php:25