-
Notifications
You must be signed in to change notification settings - Fork 18
/
HeaderFooter.class.php
98 lines (74 loc) · 2.76 KB
/
HeaderFooter.class.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
<?php
/**
* @package HeaderFooter
*/
class HeaderFooter
{
/**
* Main Hook
*/
public static function hOutputPageParserOutput( &$op, $parserOutput ) {
$action = $op->parserOptions()->getUser()->getRequest()->getVal("action");
if ( ($action == 'edit') || ($action == 'submit') || ($action == 'history') ) {
return true;
}
global $wgTitle;
$ns = $wgTitle->getNsText();
$name = $wgTitle->getPrefixedDBKey();
$text = $parserOutput->getText();
$nsheader = self::conditionalInclude( $text, '__NONSHEADER__', 'hf-nsheader', $ns );
$header = self::conditionalInclude( $text, '__NOHEADER__', 'hf-header', $name );
$footer = self::conditionalInclude( $text, '__NOFOOTER__', 'hf-footer', $name );
$nsfooter = self::conditionalInclude( $text, '__NONSFOOTER__', 'hf-nsfooter', $ns );
$parserOutput->setText( $nsheader . $header . $text . $footer . $nsfooter );
global $egHeaderFooterEnableAsyncHeader, $egHeaderFooterEnableAsyncFooter;
if ( $egHeaderFooterEnableAsyncFooter || $egHeaderFooterEnableAsyncHeader ) {
$op->addModules( 'ext.headerfooter.dynamicload' );
}
return true;
}
/**
* Verifies & Strips ''disable command'', returns $content if all OK.
*/
static function conditionalInclude( &$text, $disableWord, $class, $unique ) {
// is there a disable command lurking around?
$disable = strpos( $text, $disableWord ) !== false;
// if there is, get rid of it
// make sure that the disableWord does not break the REGEX below!
$text = preg_replace('/'.$disableWord.'/si', '', $text );
// if there is a disable command, then don't return anything
if ( $disable ) {
return null;
}
$msgId = "$class-$unique"; // also HTML ID
$div = "<div class='$class' id='$msgId'>";
global $egHeaderFooterEnableAsyncHeader, $egHeaderFooterEnableAsyncFooter;
$isHeader = $class === 'hf-nsheader' || $class === 'hf-header';
$isFooter = $class === 'hf-nsfooter' || $class === 'hf-footer';
if ( ( $egHeaderFooterEnableAsyncFooter && $isFooter )
|| ( $egHeaderFooterEnableAsyncHeader && $isHeader ) ) {
// Just drop an empty div into the page. Will fill it with async
// request after page load
return $div . '</div>';
}
else {
$msgText = wfMessage( $msgId )->parse();
// don't need to bother if there is no content.
if ( empty( $msgText ) ) {
return null;
}
if ( wfMessage( $msgId )->inContentLanguage()->isBlank() ) {
return null;
}
return $div . $msgText . '</div>';
}
}
public static function onResourceLoaderGetConfigVars ( array &$vars ) {
global $egHeaderFooterEnableAsyncHeader, $egHeaderFooterEnableAsyncFooter;
$vars['egHeaderFooter'] = [
'enableAsyncHeader' => $egHeaderFooterEnableAsyncHeader,
'enableAsyncFooter' => $egHeaderFooterEnableAsyncFooter,
];
return true;
}
}