Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Fix functionality header footer magic words #1

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions HeaderFooter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public static function hOutputPageParserOutput( &$op, $parserOutput ) {
$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 );
$nsheader = self::conditionalInclude( 'hf_nsheader', 'hf-nsheader', $ns, $parserOutput );
$header = self::conditionalInclude( 'hf_header', 'hf-header', $name, $parserOutput );
$footer = self::conditionalInclude( 'hf_footer', 'hf-footer', $name, $parserOutput );
$nsfooter = self::conditionalInclude( 'hf_nsfooter', 'hf-nsfooter', $ns, $parserOutput );

// Grab only raw text to prevent doubled parser-output class
$text = $parserOutput->getRawText();
$parserOutput->setText( $nsheader . $header . $text . $footer . $nsfooter );

global $egHeaderFooterEnableAsyncHeader, $egHeaderFooterEnableAsyncFooter;
Expand All @@ -38,20 +38,18 @@ public static function hOutputPageParserOutput( &$op, $parserOutput ) {
return true;
}

public static function onGetDoubleUnderscoreIDs( &$doubleUnderscoreIDs ) {
$doubleUnderscoreIDs[] = 'hf_nsheader';
$doubleUnderscoreIDs[] = 'hf_header';
$doubleUnderscoreIDs[] = 'hf_footer';
$doubleUnderscoreIDs[] = 'hf_nsfooter';
}

/**
* 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 ) {
static function conditionalInclude( $disableWord, $class, $unique, $parser ) {
if ( $parser->getPageProperty( $disableWord ) !== null ) {
return null;
}

Expand Down
6 changes: 5 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
},
"Hooks": {
"OutputPageParserOutput": "HeaderFooter::hOutputPageParserOutput",
"ResourceLoaderGetConfigVars": "HeaderFooter::onResourceLoaderGetConfigVars"
"ResourceLoaderGetConfigVars": "HeaderFooter::onResourceLoaderGetConfigVars",
"GetDoubleUnderscoreIDs": "HeaderFooter::onGetDoubleUnderscoreIDs"
},
"MessagesDirs": {
"HeaderFooter": [
"i18n"
]
},
"ExtensionMessagesFiles": {
"HeaderFooterMagic": "languages/HeaderFooter.i18n.magic.php"
},
"ResourceFileModulePaths": {
"localBasePath": "modules",
"remoteExtPath": "HeaderFooter/modules"
Expand Down
16 changes: 16 additions & 0 deletions languages/HeaderFooter.i18n.magic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
$magicWords = [];

$magicWords['en'] = [
'hf_footer' => [ 0, '__NOFOOTER__', '__NOFOOTER__' ],
'hf_nsfooter' => [ 0, '__NONSFOOTER__', '__NONSFOOTER__' ],
'hf_header' => [ 0, '__NOHEADER__', '__NOHEADER__' ],
'hf_nsheader' => [ 0, '__NONSHEADER__', '__NONSHEADER__' ],
];

$magicWords['de'] = [
'hf_footer' => [ 0, '__NOFOOTER__', '__NOFOOTER__' ],
'hf_nsfooter' => [ 0, '__NONSFOOTER__', '__NONSFOOTER__' ],
'hf_header' => [ 0, '__NOHEADER__', '__NOHEADER__' ],
'hf_nsheader' => [ 0, '__NONSHEADER__', '__NONSHEADER__' ],
];