MediaWiki 1.43.1
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 $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(
55 $revRecord,
56 $context,
57 [ 'noBrackets' ]
58 );
59 if ( $rollbackLink ) {
60 $this->preventClickjacking = true;
61 $tools['mw-rollback'] = $rollbackLink;
62 }
63 }
64 }
65 if ( $userCanEditTitle && $previousRevRecord ) {
66 if ( !$revRecord->isDeleted( RevisionRecord::DELETED_TEXT )
67 && !$previousRevRecord->isDeleted( RevisionRecord::DELETED_TEXT )
68 ) {
69 # Create undo tooltip for the first (=latest) line only
70 $undoTooltip = $showRollbackLink
71 ? [ 'title' => $context->msg( 'tooltip-undo' )->text() ]
72 : [];
73 $undolink = $linkRenderer->makeKnownLink(
74 $title,
75 $context->msg( 'editundo' )->text(),
76 $undoTooltip,
77 [
78 'action' => 'edit',
79 'undoafter' => $previousRevRecord->getId(),
80 'undo' => $revRecord->getId()
81 ]
82 );
83 $tools['mw-undo'] = "<span class=\"mw-history-undo\">{$undolink}</span>";
84 }
85 }
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(
90 $revRecord,
91 $tools,
92 $previousRevRecord,
93 $authority->getUser()
94 );
95 $this->tools = $tools;
96 }
97
98 public function shouldPreventClickjacking() {
99 return $this->preventClickjacking;
100 }
101
102 public function toHTML() {
103 $tools = $this->tools;
104 $s2 = '';
105 if ( $tools ) {
106 $s2 .= ' ' . Html::openElement( 'span', [ 'class' => 'mw-changeslist-links mw-pager-tools' ] );
107 foreach ( $tools as $tool ) {
108 $s2 .= Html::rawElement( 'span', [], $tool );
109 }
110 $s2 .= Html::closeElement( 'span' );
111 }
112 return $s2;
113 }
114}
115
120class_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:57
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.