MediaWiki  master
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 }
RevisionListBase $list
The parent.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
const DB_MASTER
Definition: defines.php:26
getDiffLink()
Get the HTML link to the diff.
__construct( $list, $row)
getId()
Get the ID, as it would appear in the ids URL parameter.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
$row
The database result row.
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision&#39;s user id if it&#39;s available to the specified audience.
Definition: Revision.php:603
Abstract base class for deletable items.
Definition: RevDelItem.php:25
static initRevision( $list, $row)
Create revision object from $row sourced from $list.
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:130
This class represents the result of the API operations.
Definition: ApiResult.php:35
getApiData(ApiResult $result)
static revUserLink( $rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1101
getLinkRenderer()
Returns an instance of LinkRenderer.
getRevisionLink()
Get the HTML link to the revision text.
static formatSummaryRow( $tags, $page, IContextSource $context=null)
Creates HTML for the given tags.
Definition: ChangeTags.php:94
static revComment(Revision $rev, $local=false, $isPublic=false, $useParentheses=true)
Wrap and format the given revision&#39;s comment block, if the current user is allowed to view it...
Definition: Linker.php:1572
$content
Definition: router.php:78
const PRC_AUTOPATROLLED