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 $this->getRevisionRecord()->userCan(
77  RevisionRecord::DELETED_RESTRICTED,
78  $this->context->getAuthority()
79  );
80  }
81 
83  public function canViewContent() {
84  return $this->getRevisionRecord()->userCan(
85  RevisionRecord::DELETED_TEXT,
86  $this->context->getAuthority()
87  );
88  }
89 
93  public function isDeleted() {
94  return $this->getRevisionRecord()->isDeleted( RevisionRecord::DELETED_TEXT );
95  }
96 
104  protected function getRevisionLink() {
105  $revRecord = $this->getRevisionRecord();
106  $date = $this->list->getLanguage()->userTimeAndDate(
107  $revRecord->getTimestamp(), $this->list->getUser() );
108 
109  if ( $this->isDeleted() && !$this->canViewContent() ) {
110  return htmlspecialchars( $date );
111  }
112  $linkRenderer = $this->getLinkRenderer();
113  return $linkRenderer->makeKnownLink(
114  Title::castFromPageIdentity( $this->list->getPage() ),
115  $date,
116  [],
117  [
118  'oldid' => $revRecord->getId(),
119  'unhide' => 1
120  ]
121  );
122  }
123 
131  protected function getDiffLink() {
132  if ( $this->isDeleted() && !$this->canViewContent() ) {
133  return $this->context->msg( 'diff' )->escaped();
134  } else {
135  $linkRenderer = $this->getLinkRenderer();
136  return $linkRenderer->makeKnownLink(
137  $this->list->getPage(),
138  $this->list->msg( 'diff' )->text(),
139  [],
140  [
141  'diff' => $this->getRevisionRecord()->getId(),
142  'oldid' => 'prev',
143  'unhide' => 1
144  ]
145  );
146  }
147  }
148 
155  public function getHTML() {
156  $difflink = $this->context->msg( 'parentheses' )
157  ->rawParams( $this->getDiffLink() )->escaped();
158  $revlink = $this->getRevisionLink();
159  $userlink = Linker::revUserLink( $this->getRevisionRecord() );
160  $comment = Linker::revComment( $this->getRevisionRecord() );
161  if ( $this->isDeleted() ) {
163  $revlink = "<span class=\"$class\">$revlink</span>";
164  }
165  return "<li>$difflink $revlink $userlink $comment</li>";
166  }
167 }
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:47
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
RevisionListBase
List for revision table items for a single page.
Definition: RevisionListBase.php:30
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:186
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
RevisionItem\isDeleted
isDeleted()
Definition: RevisionItem.php:93
Linker\revUserLink
static revUserLink(RevisionRecord $revRecord, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1275
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
Title\castFromPageIdentity
static castFromPageIdentity(?PageIdentity $pageIdentity)
Return a Title for a given PageIdentity.
Definition: Title.php:364
RevisionItem\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.bool
Definition: RevisionItem.php:83
Linker\getRevisionDeletedClass
static getRevisionDeletedClass(RevisionRecord $revisionRecord)
Returns css class of a deleted revision.
Definition: Linker.php:1303
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:41
Linker\revComment
static revComment(RevisionRecord $revRecord, $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:1784
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:104
RevisionItem\getDiffLink
getDiffLink()
Get the HTML link to the diff.
Definition: RevisionItem.php:131
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:155