MediaWiki master
PagerTools.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Pager;
4
12
18 private $preventClickjacking = false;
19 private $tools = [];
20
36 public function __construct(
37 RevisionRecord $revRecord,
38 ?RevisionRecord $previousRevRecord,
39 bool $showRollbackLink,
40 HookRunner $hookRunner,
41 PageIdentity $title,
42 IContextSource $context,
43 LinkRenderer $linkRenderer
44 ) {
45 $tools = [];
46 $authority = $context->getAuthority();
47 # Rollback and undo links
48 $userCanEditTitle = $authority->probablyCan( 'edit', $title );
49 if ( $showRollbackLink && $userCanEditTitle ) {
50 if ( $authority->probablyCan( 'rollback', $title ) ) {
51 // Get a rollback link without the brackets
52 $rollbackLink = Linker::generateRollback(
53 $revRecord,
54 $context,
55 [ 'noBrackets' ]
56 );
57 if ( $rollbackLink ) {
58 $this->preventClickjacking = true;
59 $tools[] = $rollbackLink;
60 }
61 }
62 }
63 if ( $userCanEditTitle && $previousRevRecord ) {
64 if ( !$revRecord->isDeleted( RevisionRecord::DELETED_TEXT )
65 && !$previousRevRecord->isDeleted( RevisionRecord::DELETED_TEXT )
66 ) {
67 # Create undo tooltip for the first (=latest) line only
68 $undoTooltip = $showRollbackLink
69 ? [ 'title' => $context->msg( 'tooltip-undo' )->text() ]
70 : [];
71 $undolink = $linkRenderer->makeKnownLink(
72 $title,
73 $context->msg( 'editundo' )->text(),
74 $undoTooltip,
75 [
76 'action' => 'edit',
77 'undoafter' => $previousRevRecord->getId(),
78 'undo' => $revRecord->getId()
79 ]
80 );
81 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
82 }
83 }
84 // Allow extension to add their own links here
85 // FIXME previously this was only called on history; restore that and deprecate in favor
86 // of a more generic hook (See T326180)
87 $hookRunner->onHistoryTools(
88 $revRecord,
89 $tools,
90 $previousRevRecord,
91 $authority->getUser()
92 );
93 $this->tools = $tools;
94 }
95
96 public function shouldPreventClickjacking() {
97 return $this->preventClickjacking;
98 }
99
100 public function toHTML() {
101 $tools = $this->tools;
102 $s2 = '';
103 if ( $tools ) {
104 $s2 .= ' ' . Html::openElement( 'span', [ 'class' => 'mw-changeslist-links mw-pager-tools' ] );
105 foreach ( $tools as $tool ) {
106 $s2 .= Html::rawElement( 'span', [], $tool );
107 }
108 $s2 .= Html::closeElement( 'span' );
109 }
110 return $s2;
111 }
112}
113
118class_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:65
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.