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