Pastakhov has uploaded a new change for review. https://gerrit.wikimedia.org/r/257276
Change subject: Restore compatibility of transclude function (v 3.7.0) ...................................................................... Restore compatibility of transclude function (v 3.7.0) * Allow false or null as template name * Third parameter is parsed Change-Id: Ib2399165d1a2f5fa0f63b473f64185c9c09cb3fe --- M PhpTagsFunctions.json M PhpTagsFunctions.php M includes/PhpTagsFuncUseful.php 3 files changed, 42 insertions(+), 31 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PhpTagsFunctions refs/changes/76/257276/1 diff --git a/PhpTagsFunctions.json b/PhpTagsFunctions.json index d8d5563..c367881 100644 --- a/PhpTagsFunctions.json +++ b/PhpTagsFunctions.json @@ -2960,8 +2960,7 @@ "parameters": [ { "type": "mixed", "name": "title" }, { "type": "array", "name": "parameters", "default": "array()" }, - { "type": "mixed", "name": "default", "default": "null" }, - { "type": "bool", "name": "return", "default": "false" } + { "type": "mixed", "name": "default", "default": "null" } ], "onfailure": "false", "return": "string", diff --git a/PhpTagsFunctions.php b/PhpTagsFunctions.php index d458b6a..048ab6e 100644 --- a/PhpTagsFunctions.php +++ b/PhpTagsFunctions.php @@ -15,7 +15,7 @@ die( 'This file is an extension to MediaWiki and thus not a valid entry point.' ); } -const PHPTAGS_FUNCTIONS_VERSION = '3.6.0'; +const PHPTAGS_FUNCTIONS_VERSION = '3.7.0'; // Register this extension on Special:Version $wgExtensionCredits['phptags'][] = array( diff --git a/includes/PhpTagsFuncUseful.php b/includes/PhpTagsFuncUseful.php index 9c49947..075090d 100644 --- a/includes/PhpTagsFuncUseful.php +++ b/includes/PhpTagsFuncUseful.php @@ -51,14 +51,25 @@ return $variables['argc'] - 1; } - public static function f_transclude( $template, $parameters = array(), $default = null, $return = false ) { + public static function f_transclude( $template, $parameters = array(), $default = null ) { $parser = \PhpTags\Renderer::getParser(); $frame = \PhpTags\Renderer::getFrame(); + + foreach ( $parameters as $key => $value ) { + if ( is_scalar( $value ) ) { + $parameters[$key] = (string)$value; + continue; + } + throw new \PhpTags\HookException( 'Expects parameter 2 to be array that contains only string values' ); + } + if ( $frame->depth >= $parser->mOptions->getMaxTemplateDepth() ) { throw new \PhpTags\HookException( 'Template depth limit exceeded' ); } - if ( $template instanceof \PhpTags\GenericObject ) { + if ( $template === false || $template === true || $template === null ) { + $title = false; + } else if ( $template instanceof \PhpTags\GenericObject ) { $title = $template->value; if ( false === $title instanceof \Title ) { if ( $template->getName() !== 'WTitle' ) { @@ -72,38 +83,39 @@ throw new \PhpTags\PhpTagsException( \PhpTags\PhpTagsException::WARNING_EXPECTS_PARAMETER, array(1, 'string or WTitle', gettype($template)) ); } - if ( \MWNamespace::isNonincludable( $title->getNamespace() ) ) { - throw new \PhpTags\HookException( 'Template inclusion denied' ); - } - list( $dom, $finalTitle ) = $parser->getTemplateDom( $title ); - if ( $dom === false ) { - if ( $default !== null ) { - return $default; + if ( $title ) { + if ( \MWNamespace::isNonincludable( $title->getNamespace() ) ) { + throw new \PhpTags\HookException( 'Template inclusion denied' ); } - throw new \PhpTags\HookException( "Template \"{$title->getPrefixedText()}\" does not exist" ); - } - if ( !$frame->loopCheck( $finalTitle ) ) { - throw new \PhpTags\HookException( 'Template loop detected' ); + if ( $title->isExternal() ) { + throw new \PhpTags\HookException( 'Cannot transclude external template' ); + } + if ( $title->isSpecialPage() ) { + throw new \PhpTags\HookException( 'Cannot transclude special page' ); + } + + list( $dom, $finalTitle ) = $parser->getTemplateDom( $title ); + if ( !$frame->loopCheck( $finalTitle ) ) { + throw new \PhpTags\HookException( 'Template loop detected' ); + } } - foreach ( $parameters as $key => $value ) { - if ( is_scalar( $value ) ) { - $parameters[$key] = (string)$value; - continue; + if ( !$title || !$dom ) { + if ( $default === null ) { + $titleName = $title ? '"' . $title->getPrefixedText() . '"' : 'NULL'; + throw new \PhpTags\HookException( "Template $titleName does not exist" ); } - throw new \PhpTags\HookException( 'Expects parameter 2 to be array that contains only string values' ); + $dom = $parser->getPreprocessor()->preprocessToObj( + str_replace( array( "\r\n", "\r" ), "\n", $default ), + $frame->depth ? Parser::PTD_FOR_INCLUSION : 0 + ); + $newFrame = $parser->getPreprocessor()->newFrame(); + } else { + $fargs = $parser->getPreprocessor()->newPartNodeArray( $parameters ); + $newFrame = $frame->newChild( $fargs, $finalTitle, -1 ); } - $fargs = $parser->getPreprocessor()->newPartNodeArray( $parameters ); - $newFrame = $frame->newChild( $fargs, $finalTitle, -1 ); - $strip = $newFrame->expand( $dom ); - if ( $return ) { - if ( defined( 'PHPTAGS_WIDGETS_VERSION' ) && version_compare( PHPTAGS_WIDGETS_VERSION, '1.6.0', '<' ) ) { - throw new \PhpTags\HookException( 'You cannot use this function for return value while using PhpTags Widgets until version 1.6.0.', \PhpTags\HookException::EXCEPTION_FATAL ); - } - return $parser->mStripState->unstripGeneral( $strip ); - } - return new \PhpTags\outStrip( true, $strip ); + return $newFrame->expand( $dom ); } } -- To view, visit https://gerrit.wikimedia.org/r/257276 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib2399165d1a2f5fa0f63b473f64185c9c09cb3fe Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/PhpTagsFunctions Gerrit-Branch: master Gerrit-Owner: Pastakhov <pastak...@yandex.ru> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits