Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 48
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Hooks
0.00% covered (danger)
0.00%
0 / 48
0.00% covered (danger)
0.00%
0 / 2
110
0.00% covered (danger)
0.00%
0 / 1
 onArticleViewHeader
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
30
 onArticleViewFooter
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2/**
3 * Hooks for PageNotice extension
4 *
5 * @file
6 * @ingroup Extensions
7 * @author Daniel Kinzler, brightbyte.de
8 * @copyright © 2007 Daniel Kinzler
9 * @license GPL-2.0-or-later
10 */
11
12namespace MediaWiki\Extension\PageNotice;
13
14use Article;
15use MediaWiki\Html\Html;
16use MediaWiki\Page\Hook\ArticleViewFooterHook;
17use MediaWiki\Page\Hook\ArticleViewHeaderHook;
18
19class Hooks implements ArticleViewHeaderHook, ArticleViewFooterHook {
20    /**
21     * Renders relevant header notices for the current page.
22     * @param Article $article
23     * @param bool &$outputDone
24     * @param bool &$pcache
25     */
26    public function onArticleViewHeader( $article, &$outputDone, &$pcache ) {
27        $pageNoticeDisablePerPageNotices = $article->getContext()
28            ->getConfig()
29            ->get( 'PageNoticeDisablePerPageNotices' );
30
31        $out = $article->getContext()->getOutput();
32        $title = $out->getTitle();
33        $name = $title->getPrefixedDBKey();
34        $ns = $title->getNamespace();
35
36        $header = $out->msg( "top-notice-$name" );
37        $nsheader = $out->msg( "top-notice-ns-$ns" );
38
39        $needStyles = false;
40
41        if ( !$pageNoticeDisablePerPageNotices && !$header->isBlank() ) {
42            $out->addHTML(
43                Html::rawElement(
44                    'div',
45                    [ 'id' => 'top-notice' ],
46                    $header->parse()
47                )
48            );
49            $needStyles = true;
50        }
51        if ( !$nsheader->isBlank() ) {
52            $out->addHTML(
53                Html::rawElement(
54                    'div',
55                    [ 'id' => 'top-notice-ns' ],
56                    $nsheader->parse()
57                )
58            );
59            $needStyles = true;
60        }
61
62        if ( $needStyles ) {
63            $out->addModuleStyles( 'ext.pageNotice' );
64        }
65    }
66
67    /**
68     * Renders relevant footer notices for the current page.
69     * @param Article $article
70     * @param bool $patrolFooterShown
71     */
72    public function onArticleViewFooter( $article, $patrolFooterShown ) {
73        $pageNoticeDisablePerPageNotices = $article->getContext()
74            ->getConfig()
75            ->get( 'PageNoticeDisablePerPageNotices' );
76
77        $out = $article->getContext()->getOutput();
78        $title = $out->getTitle();
79        $name = $title->getPrefixedDBKey();
80        $ns = $title->getNamespace();
81
82        $footer = $out->msg( "bottom-notice-$name" );
83        $nsfooter = $out->msg( "bottom-notice-ns-$ns" );
84
85        $needStyles = false;
86
87        if ( !$pageNoticeDisablePerPageNotices && !$footer->isBlank() ) {
88            $out->addHTML( '<div id="bottom-notice">' . $footer->parse() . '</div>' );
89            $needStyles = true;
90        }
91        if ( !$nsfooter->isBlank() ) {
92            $out->addHTML( '<div id="bottom-notice-ns">' . $nsfooter->parse() . '</div>' );
93            $needStyles = true;
94        }
95
96        if ( $needStyles ) {
97            $out->addModuleStyles( 'ext.pageNotice' );
98        }
99    }
100}