MediaWiki  master
RevisionItem.php
Go to the documentation of this file.
1 <?php
25 
31  protected $revisionRecord;
32 
34  protected $context;
35 
36  public function __construct( RevisionListBase $list, $row ) {
37  parent::__construct( $list, $row );
38  $this->revisionRecord = MediaWikiServices::getInstance()
39  ->getRevisionFactory()
40  ->newRevisionFromRow( $row );
41  $this->context = $list->getContext();
42  }
43 
49  protected function getRevisionRecord() : RevisionRecord {
50  return $this->revisionRecord;
51  }
52 
53  public function getIdField() {
54  return 'rev_id';
55  }
56 
57  public function getTimestampField() {
58  return 'rev_timestamp';
59  }
60 
61  public function getAuthorIdField() {
62  return 'rev_user';
63  }
64 
65  public function getAuthorNameField() {
66  return 'rev_user_text';
67  }
68 
69  public function canView() {
70  return RevisionRecord::userCanBitfield(
71  $this->getRevisionRecord()->getVisibility(),
72  RevisionRecord::DELETED_RESTRICTED,
73  $this->context->getUser()
74  );
75  }
76 
77  public function canViewContent() {
78  return RevisionRecord::userCanBitfield(
79  $this->getRevisionRecord()->getVisibility(),
80  RevisionRecord::DELETED_TEXT,
81  $this->context->getUser()
82  );
83  }
84 
85  public function isDeleted() {
86  return $this->getRevisionRecord()->isDeleted( RevisionRecord::DELETED_TEXT );
87  }
88 
96  protected function getRevisionLink() {
97  $revRecord = $this->getRevisionRecord();
98  $date = $this->list->getLanguage()->userTimeAndDate(
99  $revRecord->getTimestamp(), $this->list->getUser() );
100 
101  if ( $this->isDeleted() && !$this->canViewContent() ) {
102  return htmlspecialchars( $date );
103  }
104  $linkRenderer = $this->getLinkRenderer();
105  return $linkRenderer->makeKnownLink(
106  $this->list->title,
107  $date,
108  [],
109  [
110  'oldid' => $revRecord->getId(),
111  'unhide' => 1
112  ]
113  );
114  }
115 
123  protected function getDiffLink() {
124  if ( $this->isDeleted() && !$this->canViewContent() ) {
125  return $this->context->msg( 'diff' )->escaped();
126  } else {
127  $linkRenderer = $this->getLinkRenderer();
128  return $linkRenderer->makeKnownLink(
129  $this->list->title,
130  $this->list->msg( 'diff' )->text(),
131  [],
132  [
133  'diff' => $this->getRevisionRecord()->getId(),
134  'oldid' => 'prev',
135  'unhide' => 1
136  ]
137  );
138  }
139  }
140 
147  public function getHTML() {
148  $difflink = $this->context->msg( 'parentheses' )
149  ->rawParams( $this->getDiffLink() )->escaped();
150  $revlink = $this->getRevisionLink();
151  $userlink = Linker::revUserLink( $this->getRevisionRecord() );
152  $comment = Linker::revComment( $this->getRevisionRecord() );
153  if ( $this->isDeleted() ) {
154  $revlink = "<span class=\"history-deleted\">$revlink</span>";
155  }
156  return "<li>$difflink $revlink $userlink $comment</li>";
157  }
158 }
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:40
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
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:144
RevisionItemBase
Abstract base class for revision items.
Definition: RevisionItemBase.php:28
RevisionItem\canView
canView()
Returns true if the current user can view the item.
Definition: RevisionItem.php:69
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:1607
RevisionItem\isDeleted
isDeleted()
Definition: RevisionItem.php:85
RevisionItem\$revisionRecord
RevisionRecord $revisionRecord
Definition: RevisionItem.php:31
RevisionItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevisionItem.php:61
RevisionItemBase\$list
RevisionListBase $list
The parent.
Definition: RevisionItemBase.php:30
RevisionItem\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.
Definition: RevisionItem.php:77
RevisionItemBase\getLinkRenderer
getLinkRenderer()
Returns an instance of LinkRenderer.
Definition: RevisionItemBase.php:174
RevisionItem\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.
Definition: RevisionItem.php:65
RevisionItem\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevisionItem.php:53
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:34
RevisionItemBase\$row
$row
The database result row.
Definition: RevisionItemBase.php:33
RevisionItem
Item class for a live revision table row.
Definition: RevisionItem.php:29
RevisionItem\__construct
__construct(RevisionListBase $list, $row)
Definition: RevisionItem.php:36
RevisionItem\getRevisionLink
getRevisionLink()
Get the HTML link to the revision text.
Definition: RevisionItem.php:96
RevisionItem\getDiffLink
getDiffLink()
Get the HTML link to the diff.
Definition: RevisionItem.php:123
RevisionItem\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.
Definition: RevisionItem.php:57
RevisionItem\$context
RequestContext $context
Definition: RevisionItem.php:34
RevisionItem\getRevisionRecord
getRevisionRecord()
Get the RevisionRecord for the item.
Definition: RevisionItem.php:49
RevisionItem\getHTML
getHTML()
Definition: RevisionItem.php:147