diff --git a/ApiGetHeaderFooter.php b/ApiGetHeaderFooter.php index aa43a90..839d54d 100644 --- a/ApiGetHeaderFooter.php +++ b/ApiGetHeaderFooter.php @@ -7,6 +7,8 @@ * @since Version 3.0 */ +use Wikimedia\ParamValidator\ParamValidator; + /** * API module to review revisions */ @@ -48,12 +50,12 @@ public function execute() { public function getAllowedParams() { return array( 'contexttitle' => array( - ApiBase::PARAM_REQUIRED => true, - ApiBase::PARAM_TYPE => 'string' + ParamValidator::PARAM_REQUIRED => true, + ParamValidator::PARAM_TYPE => 'string' ), 'messageid' => array( - ApiBase::PARAM_REQUIRED => true, - ApiBase::PARAM_TYPE => 'string' + ParamValidator::PARAM_REQUIRED => true, + ParamValidator::PARAM_TYPE => 'string' ) ); } diff --git a/HeaderFooter.class.php b/HeaderFooter.class.php index 611e348..ed9ba74 100644 --- a/HeaderFooter.class.php +++ b/HeaderFooter.class.php @@ -6,10 +6,12 @@ class HeaderFooter { /** * Main Hook + * @param OutputPage $op + * @param ParserOutput $parserOutput */ public static function hOutputPageParserOutput( &$op, $parserOutput ) { - $action = $op->parserOptions()->getUser()->getRequest()->getVal("action"); + $action = $op->getRequest()->getVal("action"); if ( ($action == 'edit') || ($action == 'submit') || ($action == 'history') ) { return true; } @@ -19,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; @@ -36,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; } diff --git a/HeaderFooter.php b/HeaderFooter.php deleted file mode 100644 index ade7159..0000000 --- a/HeaderFooter.php +++ /dev/null @@ -1,14 +0,0 @@ -=1.0.1" - }, - "autoload": { - "files": ["HeaderFooter.php"] + "composer/installers": ">=1.0.1|~2" } } diff --git a/extension.json b/extension.json index 018d425..da44be0 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "HeaderFooter", - "version": "3.0.0", + "version": "4.0.0", "author": "Jean-Lou Dupont, James Montalvo, Douglas Mason", "url": "http://mediawiki.org/wiki/Extension:HeaderFooter", "descriptionmsg": "headerfooter-desc", @@ -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" @@ -32,10 +36,14 @@ ] } }, + "config_prefix": "egHeaderFooter", "config": { - "_prefix": "eg", - "HeaderFooterEnableAsyncHeader": false, - "HeaderFooterEnableAsyncFooter": false + "EnableAsyncHeader": { + "value": false + }, + "EnableAsyncFooter": { + "value": false + } }, - "manifest_version": 1 + "manifest_version": 2 } diff --git a/languages/HeaderFooter.i18n.magic.php b/languages/HeaderFooter.i18n.magic.php new file mode 100644 index 0000000..ccb94b6 --- /dev/null +++ b/languages/HeaderFooter.i18n.magic.php @@ -0,0 +1,16 @@ + [ 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__' ], +];