-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHideSection.hooks.php
88 lines (72 loc) · 2.15 KB
/
HideSection.hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Hooks for extension HideSection.
* @ingroup Extensions
*/
class HideSectionHooks {
private static function shouldHaveHideSection( Skin $skin ): bool {
$name = $skin->getSkinName();
return !( $name === 'minerva' )
&& !in_array( $name, ExtensionRegistry::getInstance()->getAttribute( 'HideSectionDisabled' ) );
}
public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {
global $wgHideSectionTitleLink;
if ( !self::shouldHaveHideSection( $skin ) ) {
return;
}
$out->addModules( 'ext.hideSection' );
if ( $wgHideSectionTitleLink ) {
$hideelem = Html::Rawelement( 'span',
[ 'class' => 'hidesection-head' ],
);
$title = $out->getPageTitle();
// Append to page title
$out->setPageTitle( $title . $hideelem );
}
return true;
}
public static function onSkinEditSectionLinks( $skin, $title, $section, $tooltip, &$links, $lang ) {
if ( !self::shouldHaveHideSection( $skin ) ) {
return;
}
global $wgHideSectionHideText;
if ($wgHideSectionHideText) return true;
$hidetext = wfMessage( 'hidesection-hide' )->text();
$showtext = wfMessage( 'hidesection-show' )->text();
$titletext = wfMessage( 'hidesection-hidetitle' )->text();
// Add hide/show link next to edit links
if ($section !== 0) {
$links['hidesection'] = [
'targetTitle' => $title,
'text' => $hidetext,
'attribs' => [
"class" => "hidesection-link internal",
"data-show" => $showtext,
"data-hide" => $hidetext,
"data-section" => $section,
"title" => $titletext,
],
'query' => array(),
'options' => array(),
];
}
// Add hide all/show all link on first section
if ($section == 1) {
$showall = wfMessage( 'hidesection-showall' )->text();
$hideall = wfMessage( 'hidesection-hideall' )->text();
$titleall = wfMessage( 'hidesection-hidealltitle' )->text();
$links['hidesectionall'] = [
'targetTitle' => $title,
'text' => $hideall,
'attribs' => [
"class" => "hidesection-all internal",
"data-show" => $showall,
"data-hide" => $hideall,
"title" => $titleall,
],
'query' => array(),
'options' => array(),
];
}
}
}