From 2a07e8002a12a5a5671914e7fb23bd9edb4ee3be Mon Sep 17 00:00:00 2001 From: tengel Date: Wed, 20 Mar 2024 09:20:41 -0500 Subject: [PATCH] remove nopreload hook entirely, use noinclude instead --- Preloader.php | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/Preloader.php b/Preloader.php index abd322d..d899fbd 100644 --- a/Preloader.php +++ b/Preloader.php @@ -2,10 +2,8 @@ /** * Extension allows preloading of custom content into all edit forms - * when creating an article - * - * Also adds a new tag which is used to mark sections which - * shouldn't be preloaded, ever; has no effect on the rendering of pages + * when creating an article. and are respected + * and stripped during new article population. * * @file * @ingroup Extensions @@ -20,8 +18,8 @@ if( !defined( 'MEDIAWIKI' ) ) { $wgExtensionCredits['other'][] = array( 'path' => __FILE__, 'name' => 'Preloader', - 'author' => 'Rob Church', - 'version' => '1.1.1', + 'author' => 'Rob Church, Troy Engel', + 'version' => '1.1.2', 'url' => 'https://www.mediawiki.org/wiki/Extension:Preloader', 'descriptionmsg' => 'preloader-desc', ); @@ -33,15 +31,9 @@ $wgExtensionMessagesFiles['Preloader'] = dirname(__FILE__) . '/Preloader.i18n.p $wgPreloaderSource[ NS_MAIN ] = 'Template:Preload'; $wgHooks['EditFormPreloadText'][] = 'Preloader::mainHook'; -$wgHooks['ParserFirstCallInit'][] = 'Preloader::setParserHook'; class Preloader { - public static function setParserHook( $parser ) { - $parser->setHook( 'nopreload', array( __CLASS__, 'parserHook' ) ); - return true; - } - /** Hook function for the preloading */ public static function mainHook( &$text, &$title ) { $src = self::preloadSource( $title->getNamespace() ); @@ -53,12 +45,6 @@ class Preloader { return true; } - /** Hook function for the parser */ - public static function parserHook( $input, $args, &$parser ) { - $output = $parser->parse( $input, $parser->getTitle(), $parser->getOptions(), false, false ); - return $output->getText(); - } - /** * Determine what page should be used as the source of preloaded text * for a given namespace and return the title (in text form) @@ -92,12 +78,13 @@ class Preloader { } /** - * Remove sections from the text and trim whitespace + * Remove sections from the text and trim whitespace * * @param $text * @return string */ static function transform( $text ) { - return trim( preg_replace( '/.*<\/nopreload>/s', '', $text ) ); + $text = trim( preg_replace( '/<\/?includeonly>/s', '', $text ) ); + return trim( preg_replace( '/.*<\/noinclude>/s', '', $text ) ); } }