MediaWiki master
PagerTools.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Pager;
4
12
19 private $preventClickjacking = false;
21 private $tools = [];
22
38 public function __construct(
39 RevisionRecord $revRecord,
40 ?RevisionRecord $previousRevRecord,
41 bool $showRollbackLink,
42 HookRunner $hookRunner,
43 PageIdentity $title,
44 IContextSource $context,
45 LinkRenderer $linkRenderer
46 ) {
47 $tools = [];
48 $authority = $context->getAuthority();
49 # Rollback and undo links
50 if ( ( $showRollbackLink || $previousRevRecord )
51 // probablyCan loads page restriction data, call only when needed
52 && $authority->probablyCan( 'edit', $title )
53 ) {
54 if ( $showRollbackLink && $authority->probablyCan( 'rollback', $title ) ) {
55 // Get a rollback link without the brackets
56 $rollbackLink = Linker::generateRollback(
57 $revRecord,
58 $context,
59 [ 'noBrackets' ]
60 );
61 if ( $rollbackLink ) {
62 $this->preventClickjacking = true;
63 $tools['mw-rollback'] = $rollbackLink;
64 }
65 }
66 if ( $previousRevRecord
67 && !$revRecord->isDeleted( RevisionRecord::DELETED_TEXT )
68 && !$previousRevRecord->isDeleted( RevisionRecord::DELETED_TEXT )
69 ) {
70 # Create undo tooltip for the first (=latest) line only
71 $undoTooltip = $showRollbackLink
72 ? [ 'title' => $context->msg( 'tooltip-undo' )->text() ]
73 : [];
74 $undolink = $linkRenderer->makeKnownLink(
75 $title,
76 $context->msg( 'editundo' )->text(),
77 $undoTooltip,
78 [
79 'action' => 'edit',
80 'undoafter' => $previousRevRecord->getId(),
81 'undo' => $revRecord->getId()
82 ]
83 );
84 $tools['mw-undo'] = "<span class=\"mw-history-undo\">{$undolink}</span>";
85 }
86 }
87 // Allow extension to add their own links here
88 // FIXME previously this was only called on history; restore that and deprecate in favor
89 // of a more generic hook (See T326180)
90 $hookRunner->onHistoryTools(
91 $revRecord,
92 $tools,
93 $previousRevRecord,
94 $authority->getUser()
95 );
96 $this->tools = $tools;
97 }
98
99 public function shouldPreventClickjacking() {
100 return $this->preventClickjacking;
101 }
102
103 public function toHTML() {
104 $tools = $this->tools;
105 $s2 = '';
106 if ( $tools ) {
107 $s2 .= ' ' . Html::openElement( 'span', [ 'class' => 'mw-changeslist-links mw-pager-tools' ] );
108 foreach ( $tools as $tool ) {
109 $s2 .= Html::rawElement( 'span', [], $tool );
110 }
111 $s2 .= Html::closeElement( 'span' );
112 }
113 return $s2;
114 }
115}
116
121class_alias( PagerTools::class, 'PagerTools' );
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
onHistoryTools( $revRecord, &$links, $prevRevRecord, $userIdentity)
Use this hook to override or extend the revision tools available from the page history view,...
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
Class that generates HTML for internal links.
makeKnownLink( $target, $text=null, array $extraAttribs=[], array $query=[])
Make a link that's styled as if the target page exists (usually a "blue link", although the styling m...
Some internal bits split of from Skin.php.
Definition Linker.php:63
Generate a set of tools for a revision.
__construct(RevisionRecord $revRecord, ?RevisionRecord $previousRevRecord, bool $showRollbackLink, HookRunner $hookRunner, PageIdentity $title, IContextSource $context, LinkRenderer $linkRenderer)
Generate a set of tools for a revision.
Page revision base class.
getUser( $audience=self::FOR_PUBLIC, ?Authority $performer=null)
Fetch revision's author's user identity, if it's available to the specified audience.
isDeleted( $field)
MCR migration note: this replaced Revision::isDeleted.
getId( $wikiId=self::LOCAL)
Get revision ID.
Interface for objects which can provide a MediaWiki context on request.
Interface for objects (potentially) representing an editable wiki page.
msg( $key,... $params)
This is the method for getting translated interface messages.