-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hooks.php
100 lines (86 loc) · 2.46 KB
/
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
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Hooks for PageNotice extension
*
* @file
* @ingroup Extensions
* @author Daniel Kinzler, brightbyte.de
* @copyright © 2007 Daniel Kinzler
* @license GPL-2.0-or-later
*/
namespace MediaWiki\Extension\PageNotice;
use Article;
use MediaWiki\Html\Html;
use MediaWiki\Page\Hook\ArticleViewFooterHook;
use MediaWiki\Page\Hook\ArticleViewHeaderHook;
class Hooks implements ArticleViewHeaderHook, ArticleViewFooterHook {
/**
* Renders relevant header notices for the current page.
* @param Article $article
* @param bool &$outputDone
* @param bool &$pcache
*/
public function onArticleViewHeader( $article, &$outputDone, &$pcache ) {
$pageNoticeDisablePerPageNotices = $article->getContext()
->getConfig()
->get( 'PageNoticeDisablePerPageNotices' );
$out = $article->getContext()->getOutput();
$title = $out->getTitle();
$name = $title->getPrefixedDBKey();
$ns = $title->getNamespace();
$header = $out->msg( "top-notice-$name" );
$nsheader = $out->msg( "top-notice-ns-$ns" );
$needStyles = false;
if ( !$pageNoticeDisablePerPageNotices && !$header->isBlank() ) {
$out->addHTML(
Html::rawElement(
'div',
[ 'id' => 'top-notice' ],
$header->parse()
)
);
$needStyles = true;
}
if ( !$nsheader->isBlank() ) {
$out->addHTML(
Html::rawElement(
'div',
[ 'id' => 'top-notice-ns' ],
$nsheader->parse()
)
);
$needStyles = true;
}
if ( $needStyles ) {
$out->addModuleStyles( 'ext.pageNotice' );
}
}
/**
* Renders relevant footer notices for the current page.
* @param Article $article
* @param bool $patrolFooterShown
*/
public function onArticleViewFooter( $article, $patrolFooterShown ) {
$pageNoticeDisablePerPageNotices = $article->getContext()
->getConfig()
->get( 'PageNoticeDisablePerPageNotices' );
$out = $article->getContext()->getOutput();
$title = $out->getTitle();
$name = $title->getPrefixedDBKey();
$ns = $title->getNamespace();
$footer = $out->msg( "bottom-notice-$name" );
$nsfooter = $out->msg( "bottom-notice-ns-$ns" );
$needStyles = false;
if ( !$pageNoticeDisablePerPageNotices && !$footer->isBlank() ) {
$out->addHTML( '<div id="bottom-notice">' . $footer->parse() . '</div>' );
$needStyles = true;
}
if ( !$nsfooter->isBlank() ) {
$out->addHTML( '<div id="bottom-notice-ns">' . $nsfooter->parse() . '</div>' );
$needStyles = true;
}
if ( $needStyles ) {
$out->addModuleStyles( 'ext.pageNotice' );
}
}
}