MediaWiki  1.33.0
RevisionItem.php
Go to the documentation of this file.
1 <?php
28  protected $revision;
29 
31  protected $context;
32 
33  public function __construct( $list, $row ) {
34  parent::__construct( $list, $row );
35  $this->revision = new Revision( $row );
36  $this->context = $list->getContext();
37  }
38 
39  public function getIdField() {
40  return 'rev_id';
41  }
42 
43  public function getTimestampField() {
44  return 'rev_timestamp';
45  }
46 
47  public function getAuthorIdField() {
48  return 'rev_user';
49  }
50 
51  public function getAuthorNameField() {
52  return 'rev_user_text';
53  }
54 
55  public function canView() {
56  return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->context->getUser() );
57  }
58 
59  public function canViewContent() {
60  return $this->revision->userCan( Revision::DELETED_TEXT, $this->context->getUser() );
61  }
62 
63  public function isDeleted() {
64  return $this->revision->isDeleted( Revision::DELETED_TEXT );
65  }
66 
74  protected function getRevisionLink() {
75  $date = $this->list->getLanguage()->userTimeAndDate(
76  $this->revision->getTimestamp(), $this->list->getUser() );
77 
78  if ( $this->isDeleted() && !$this->canViewContent() ) {
79  return htmlspecialchars( $date );
80  }
81  $linkRenderer = $this->getLinkRenderer();
82  return $linkRenderer->makeKnownLink(
83  $this->list->title,
84  $date,
85  [],
86  [
87  'oldid' => $this->revision->getId(),
88  'unhide' => 1
89  ]
90  );
91  }
92 
100  protected function getDiffLink() {
101  if ( $this->isDeleted() && !$this->canViewContent() ) {
102  return $this->context->msg( 'diff' )->escaped();
103  } else {
104  $linkRenderer = $this->getLinkRenderer();
105  return $linkRenderer->makeKnownLink(
106  $this->list->title,
107  $this->list->msg( 'diff' )->text(),
108  [],
109  [
110  'diff' => $this->revision->getId(),
111  'oldid' => 'prev',
112  'unhide' => 1
113  ]
114  );
115  }
116  }
117 
124  public function getHTML() {
125  $difflink = $this->context->msg( 'parentheses' )
126  ->rawParams( $this->getDiffLink() )->escaped();
127  $revlink = $this->getRevisionLink();
128  $userlink = Linker::revUserLink( $this->revision );
129  $comment = Linker::revComment( $this->revision );
130  if ( $this->isDeleted() ) {
131  $revlink = "<span class=\"history-deleted\">$revlink</span>";
132  }
133  return "<li>$difflink $revlink $userlink $comment</li>";
134  }
135 }
Revision\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: Revision.php:49
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:40
Linker\revUserLink
static revUserLink( $rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1063
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:55
RevisionItem\isDeleted
isDeleted()
Definition: RevisionItem.php:63
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:1510
$linkRenderer
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition: hooks.txt:1985
RevisionItem\__construct
__construct( $list, $row)
Definition: RevisionItem.php:33
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
RevisionItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevisionItem.php:47
RevisionItemBase\$list
RevisionListBase $list
The parent.
Definition: RevisionItemBase.php:30
Revision
Definition: Revision.php:40
RevisionItem\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.
Definition: RevisionItem.php:59
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:51
RevisionItem\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevisionItem.php:39
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:32
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
RevisionItem\$revision
Revision $revision
Definition: RevisionItem.php:28
RevisionItemBase\$row
$row
The database result row.
Definition: RevisionItemBase.php:33
RevisionItem
Item class for a live revision table row.
Definition: RevisionItem.php:26
RevisionItem\getRevisionLink
getRevisionLink()
Get the HTML link to the revision text.
Definition: RevisionItem.php:74
RevisionItem\getDiffLink
getDiffLink()
Get the HTML link to the diff.
Definition: RevisionItem.php:100
RevisionItem\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.
Definition: RevisionItem.php:43
revision
In both all secondary updates will be triggered handle like object that caches derived data representing a revision
Definition: pageupdater.txt:78
RevisionItem\$context
RequestContext $context
Definition: RevisionItem.php:31
Revision\DELETED_TEXT
const DELETED_TEXT
Definition: Revision.php:46
RevisionItem\getHTML
getHTML()
Definition: RevisionItem.php:124