MediaWiki  master
RevisionItem.php
Go to the documentation of this file.
1 <?php
25 
31  protected $revisionRecord;
32 
34  protected $context;
35 
37  public function __construct( RevisionListBase $list, $row ) {
38  parent::__construct( $list, $row );
39  $this->revisionRecord = MediaWikiServices::getInstance()
40  ->getRevisionFactory()
41  ->newRevisionFromRow( $row );
42  $this->context = $list->getContext();
43  }
44 
50  protected function getRevisionRecord() : RevisionRecord {
51  return $this->revisionRecord;
52  }
53 
55  public function getIdField() {
56  return 'rev_id';
57  }
58 
60  public function getTimestampField() {
61  return 'rev_timestamp';
62  }
63 
65  public function getAuthorIdField() {
66  return 'rev_user';
67  }
68 
70  public function getAuthorNameField() {
71  return 'rev_user_text';
72  }
73 
75  public function canView() {
76  return RevisionRecord::userCanBitfield(
77  $this->getRevisionRecord()->getVisibility(),
78  RevisionRecord::DELETED_RESTRICTED,
79  $this->context->getUser()
80  );
81  }
82 
84  public function canViewContent() {
85  return RevisionRecord::userCanBitfield(
86  $this->getRevisionRecord()->getVisibility(),
87  RevisionRecord::DELETED_TEXT,
88  $this->context->getUser()
89  );
90  }
91 
95  public function isDeleted() {
96  return $this->getRevisionRecord()->isDeleted( RevisionRecord::DELETED_TEXT );
97  }
98 
106  protected function getRevisionLink() {
107  $revRecord = $this->getRevisionRecord();
108  $date = $this->list->getLanguage()->userTimeAndDate(
109  $revRecord->getTimestamp(), $this->list->getUser() );
110 
111  if ( $this->isDeleted() && !$this->canViewContent() ) {
112  return htmlspecialchars( $date );
113  }
114  $linkRenderer = $this->getLinkRenderer();
115  return $linkRenderer->makeKnownLink(
116  $this->list->title,
117  $date,
118  [],
119  [
120  'oldid' => $revRecord->getId(),
121  'unhide' => 1
122  ]
123  );
124  }
125 
133  protected function getDiffLink() {
134  if ( $this->isDeleted() && !$this->canViewContent() ) {
135  return $this->context->msg( 'diff' )->escaped();
136  } else {
137  $linkRenderer = $this->getLinkRenderer();
138  return $linkRenderer->makeKnownLink(
139  $this->list->title,
140  $this->list->msg( 'diff' )->text(),
141  [],
142  [
143  'diff' => $this->getRevisionRecord()->getId(),
144  'oldid' => 'prev',
145  'unhide' => 1
146  ]
147  );
148  }
149  }
150 
157  public function getHTML() {
158  $difflink = $this->context->msg( 'parentheses' )
159  ->rawParams( $this->getDiffLink() )->escaped();
160  $revlink = $this->getRevisionLink();
161  $userlink = Linker::revUserLink( $this->getRevisionRecord() );
162  $comment = Linker::revComment( $this->getRevisionRecord() );
163  if ( $this->isDeleted() ) {
164  $revlink = "<span class=\"history-deleted\">$revlink</span>";
165  }
166  return "<li>$difflink $revlink $userlink $comment</li>";
167  }
168 }
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:45
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
Linker\revUserLink
static revUserLink( $rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1100
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:166
RevisionItemBase
Abstract base class for revision items.
Definition: RevisionItemBase.php:29
RevisionItem\canView
canView()
Returns true if the current user can view the item.bool
Definition: RevisionItem.php:75
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:1604
RevisionItem\isDeleted
isDeleted()
Definition: RevisionItem.php:95
RevisionItem\$revisionRecord
RevisionRecord $revisionRecord
Definition: RevisionItem.php:31
RevisionItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.Override this function. string|false
Definition: RevisionItem.php:65
RevisionItemBase\$list
RevisionListBase $list
The parent.
Definition: RevisionItemBase.php:31
RevisionItem\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.bool
Definition: RevisionItem.php:84
RevisionItemBase\getLinkRenderer
getLinkRenderer()
Returns an instance of LinkRenderer.
Definition: RevisionItemBase.php:178
RevisionItem\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.Override this function. string|false
Definition: RevisionItem.php:70
RevisionItem\getIdField
getIdField()
Get the DB field name associated with the ID list.Override this function. string|null
Definition: RevisionItem.php:55
RequestContext
Group all the pieces relevant to the context of a request into one instance @newable.
Definition: RequestContext.php:39
RevisionItem
Item class for a live revision table row.
Definition: RevisionItem.php:29
RevisionItem\__construct
__construct(RevisionListBase $list, $row)
DB result row
Definition: RevisionItem.php:37
RevisionItem\getRevisionLink
getRevisionLink()
Get the HTML link to the revision text.
Definition: RevisionItem.php:106
RevisionItem\getDiffLink
getDiffLink()
Get the HTML link to the diff.
Definition: RevisionItem.php:133
RevisionItem\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.Override this function. string|false
Definition: RevisionItem.php:60
RevisionItem\$context
RequestContext $context
Definition: RevisionItem.php:34
RevisionItemBase\$row
stdClass $row
The database result row.
Definition: RevisionItemBase.php:34
RevisionItem\getRevisionRecord
getRevisionRecord()
Get the RevisionRecord for the item.
Definition: RevisionItem.php:50
RevisionItem\getHTML
getHTML()
Definition: RevisionItem.php:157