MediaWiki master
ChangeToolsFactory.php
Go to the documentation of this file.
1<?php
2
4
11
18
22 public function __construct(
23 private readonly HookRunner $hookRunner,
24 private readonly LinkRenderer $linkRenderer,
25 ) {
26 }
27
39 public function buildChangeTools(
40 RevisionRecord $revision,
41 ?RevisionRecord $previousRevision,
42 bool $showRollbackLink,
43 IContextSource $context,
44 ): ChangeTools {
45 $tools = [];
46 $preventClickjacking = false;
47 $title = $revision->getPage();
48 $authority = $context->getAuthority();
49
50 // Rollback and undo links
51 if ( ( $showRollbackLink || $previousRevision )
52 // probablyCan loads page restriction data, call only when needed
53 && $authority->probablyCan( 'edit', $title )
54 ) {
55 if ( $showRollbackLink && $authority->probablyCan( 'rollback', $title ) ) {
56 // Get a rollback link without the brackets
57 $rollbackLink = Linker::generateRollback(
58 $revision,
59 $context,
60 [ 'noBrackets' ]
61 );
62 if ( $rollbackLink ) {
63 $preventClickjacking = true;
64 $tools['mw-rollback'] = $rollbackLink;
65 }
66 }
67 if ( $previousRevision
68 && !$revision->isDeleted( RevisionRecord::DELETED_TEXT )
69 && !$previousRevision->isDeleted( RevisionRecord::DELETED_TEXT )
70 ) {
71 // Create undo tooltip for the first (=latest) line only
72 $undoTooltip = $showRollbackLink
73 ? [ 'title' => $context->msg( 'tooltip-undo' )->text() ]
74 : [];
75 $undoLink = $this->linkRenderer->makeKnownLink(
76 $title,
77 $context->msg( 'editundo' )->text(),
78 $undoTooltip,
79 [
80 'action' => 'edit',
81 'undoafter' => $previousRevision->getId(),
82 'undo' => $revision->getId()
83 ]
84 );
85 $tools['mw-undo'] = Html::rawElement(
86 'span',
87 [
88 'class' => [ 'mw-history-undo', 'mw-change-tools-undo' ]
89 ],
90 $undoLink,
91 );
92 }
93 }
94
95 // Allow extension to add their own links here
96 // FIXME previously this was only called on history; restore that and deprecate in favor
97 // of a more generic hook (See T326180)
98 $this->hookRunner->onHistoryTools(
99 $revision,
100 $tools,
101 $previousRevision,
102 $authority->getUser()
103 );
104 return new ChangeTools( $tools, $preventClickjacking );
105 }
106
107}
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
Class that generates HTML for internal links.
Some internal bits split of from Skin.php.
Definition Linker.php:48
__construct(private readonly HookRunner $hookRunner, private readonly LinkRenderer $linkRenderer,)
buildChangeTools(RevisionRecord $revision, ?RevisionRecord $previousRevision, bool $showRollbackLink, IContextSource $context,)
Generate a set of tools for a revision.
A set of tools for a change, e.g.
Page revision base class.
isDeleted(int $field)
MCR migration note: this replaced Revision::isDeleted.
getPage()
Returns the page this revision belongs to.
getId( $wikiId=self::LOCAL)
Get revision ID.
Interface for objects which can provide a MediaWiki context on request.
msg( $key,... $params)
This is the method for getting translated interface messages.