Kji has submitted this change and it was merged.
Change subject: Added template parameters to the hierarchyParent parser
function.
......................................................................
Added template parameters to the hierarchyParent parser function.
Users can now pass the introtemplate, template, and outrotemplate
optional parameters when calling the hierarchyParent parser function to
customize the output formatting.
Corrected i18n backwards compatibility.
Fixed a bug causing introtemplates to depend on outrotemplate existance.
The introtemplate parameter for the hierarchyParent and hierarchyChildren
parser functions no longer requires an outrotemplate be provided in order
to function properly.
Updated version number from 1.0 to 1.1.
Change-Id: If1be8b033718305b0ce6360cde8709ad4261ebba
---
M HierarchyBuilder.php
1 file changed, 40 insertions(+), 8 deletions(-)
Approvals:
Kji: Verified; Looks good to me, approved
diff --git a/HierarchyBuilder.php b/HierarchyBuilder.php
index 2e74d74..2838fef 100644
--- a/HierarchyBuilder.php
+++ b/HierarchyBuilder.php
@@ -46,15 +46,16 @@
$wgExtensionCredits['parserhook'][] = array (
'path' => __FILE__,
'name' => 'HierarchyBuilder',
- 'version' => '1.0',
+ 'version' => '1.1',
'author' => array(
'[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy
Cicalese]',
- '[https://www.mediawiki.org/wiki/User.kji Kevin Ji]'
+ '[https://www.mediawiki.org/wiki/User:Kevin.ji Kevin Ji]'
),
'descriptionmsg' => 'hierarchybuilder-desc',
'url' => 'https://www.mediawiki.org/wiki/Extension:HierarchyBuilder'
);
+$wgExensionMessagesFiles['HierarchyBuilder'] = __DIR__ .
'/HierarchyBuilder.i18n.php';
$wgHooks['ParserFirstCallInit'][] = 'efHierarchyBuilderSetup';
$wgAutoloadClasses['HierarchyBuilder'] = __DIR__ .
'/HierarchyBuilder.class.php';
@@ -191,6 +192,25 @@
// optional args (just link=none)
$optionalParams = array_slice( $params, 4 );
$optionalParams = parseParams( $optionalParams );
+ // look for the template parameter
+ if ( isset( $optionalParams[HierarchyBuilder::TEMPLATE] ) ) {
+ $template = $optionalParams[HierarchyBuilder::TEMPLATE];
+ } else {
+ $template = '';
+ }
+ // look for the introtemplate parameter
+ if ( isset( $optionalParams[HierarchyBuilder::INTROTEMPLATE] )
) {
+ $introTemplate =
$optionalParams[HierarchyBuilder::INTROTEMPLATE];
+ } else {
+ $introTemplate = '';
+ }
+ // look for the outrotemplate parameter
+ if ( isset( $optionalParams[HierarchyBuilder::OUTROTEMPLATE] )
) {
+ $outroTemplate =
$optionalParams[HierarchyBuilder::OUTROTEMPLATE];
+ } else {
+ $outroTemplate = '';
+ }
+ // look for the link parameter
if ( isset( $optionalParams[HierarchyBuilder::LINK] ) ) {
$link = $optionalParams[HierarchyBuilder::LINK];
} else {
@@ -203,10 +223,20 @@
// format the parent for return according to the optional arg
if ( $parent != '' ) {
- $parent = $link == 'none' ? $parent : "[[$parent]]";
+ if ( $template != '' ) {
+ $intro = $introTemplate != '' ?
"{{{$introTemplate}}}\n" : '';
+ $outro = $outroTemplate != '' ?
"\n{{{$outroTemplate}}}" : '';
+ if ( $link == 'none' ) {
+ $parent = "{{" . $template .
"|$parent}}";
+ } else {
+ $parent = "{{" . $template .
"|[[$parent]]}}";
+ }
+ $output = $intro . $parent . $outro;
+ } else {
+ $output = $link == 'none' ? $parent :
"[[$parent]]";
+ }
}
-
- $output = $parser->recursiveTagParse( $parent );
+ $output = $parser->recursiveTagParse( $output );
}
return $parser->insertStripItem( $output, $parser->mStripState );
}
@@ -265,7 +295,7 @@
$template = '';
}
// look for the introtemplate parameter
- if ( isset( $optionalParams[HierarchyBuilder::OUTROTEMPLATE] )
) {
+ if ( isset( $optionalParams[HierarchyBuilder::INTROTEMPLATE] )
) {
$introTemplate =
$optionalParams[HierarchyBuilder::INTROTEMPLATE];
} else {
$introTemplate = '';
@@ -319,7 +349,6 @@
),
"$delimiter\n"
);
-
$output = $intro . $templateChildrenString .
$outro;
} else {
$childrenString = implode(
@@ -335,7 +364,6 @@
$output = $childrenString;
}
}
-
$output = $parser->recursiveTagParse( $output );
}
return $parser->insertStripItem( $output, $parser->mStripState );
@@ -430,3 +458,7 @@
}
return $paramArray;
}
+
+function wikiLog($className, $methodName, $message) {
+ wfErrorLog("[".date("c")."]"."[".$className."][".$methodName."] " .
$message . "\n", '/home/kji/hierarchyBuilder.log');
+}
--
To view, visit https://gerrit.wikimedia.org/r/172323
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If1be8b033718305b0ce6360cde8709ad4261ebba
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/HierarchyBuilder
Gerrit-Branch: master
Gerrit-Owner: Kji <[email protected]>
Gerrit-Reviewer: Kji <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits