3 namespace MediaWiki\Pager
;
5 use MediaWiki\Context\IContextSource
;
6 use MediaWiki\HookContainer\HookRunner
;
7 use MediaWiki\Html\Html
;
8 use MediaWiki\Linker\Linker
;
9 use MediaWiki\Linker\LinkRenderer
;
10 use MediaWiki\Page\PageIdentity
;
11 use MediaWiki\Revision\RevisionRecord
;
14 * Generate a set of tools for a revision.
19 private $preventClickjacking = false;
24 * Generate a set of tools for a revision.
25 * Will perform permission checks where necessary.
26 * @param RevisionRecord $revRecord The revision to generate tools for.
27 * @param RevisionRecord|null $previousRevRecord The previous revision (if any). Optional.
28 * Used to produce undo links.
29 * @param bool $showRollbackLink Whether to show the rollback link. Only set to true if the
30 * revision is the latest revision of its page and it has a parent.
31 * FIXME why don't we do these checks ourselves?
32 * @param HookRunner $hookRunner
33 * @param PageIdentity $title The page to generate tools for. It is the caller's responsibility
34 * to ensure that the page is already in the link cache.
35 * @param IContextSource $context
36 * @param LinkRenderer $linkRenderer
38 public function __construct(
39 RevisionRecord
$revRecord,
40 ?RevisionRecord
$previousRevRecord,
41 bool $showRollbackLink,
42 HookRunner
$hookRunner,
44 IContextSource
$context,
45 LinkRenderer
$linkRenderer
48 $authority = $context->getAuthority();
49 # Rollback and undo links
50 $userCanEditTitle = $authority->probablyCan( 'edit', $title );
51 if ( $showRollbackLink && $userCanEditTitle ) {
52 if ( $authority->probablyCan( 'rollback', $title ) ) {
53 // Get a rollback link without the brackets
54 $rollbackLink = Linker
::generateRollback(
59 if ( $rollbackLink ) {
60 $this->preventClickjacking
= true;
61 $tools['mw-rollback'] = $rollbackLink;
65 if ( $userCanEditTitle && $previousRevRecord ) {
66 if ( !$revRecord->isDeleted( RevisionRecord
::DELETED_TEXT
)
67 && !$previousRevRecord->isDeleted( RevisionRecord
::DELETED_TEXT
)
69 # Create undo tooltip for the first (=latest) line only
70 $undoTooltip = $showRollbackLink
71 ?
[ 'title' => $context->msg( 'tooltip-undo' )->text() ]
73 $undolink = $linkRenderer->makeKnownLink(
75 $context->msg( 'editundo' )->text(),
79 'undoafter' => $previousRevRecord->getId(),
80 'undo' => $revRecord->getId()
83 $tools['mw-undo'] = "<span class=\"mw-history-undo\">{$undolink}</span>";
86 // Allow extension to add their own links here
87 // FIXME previously this was only called on history; restore that and deprecate in favor
88 // of a more generic hook (See T326180)
89 $hookRunner->onHistoryTools(
95 $this->tools
= $tools;
98 public function shouldPreventClickjacking() {
99 return $this->preventClickjacking
;
102 public function toHTML() {
103 $tools = $this->tools
;
106 $s2 .= ' ' . Html
::openElement( 'span', [ 'class' => 'mw-changeslist-links mw-pager-tools' ] );
107 foreach ( $tools as $tool ) {
108 $s2 .= Html
::rawElement( 'span', [], $tool );
110 $s2 .= Html
::closeElement( 'span' );
117 * Retain the old class name for backwards compatibility.
118 * @deprecated since 1.41
120 class_alias( PagerTools
::class, 'PagerTools' );