Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1283
defaultargs.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
bzimport
Nov 21 2014, 6:54 PM
2014-11-21 18:54:05 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
defaultargs.patch
View Options
Index: Parser.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/Parser.php,v
retrieving revision 1.506
diff -u -r1.506 Parser.php
--- Parser.php 20 Sep 2005 18:15:25 -0000 1.506
+++ Parser.php 20 Sep 2005 19:30:22 -0000
@@ -1965,6 +1965,7 @@
wfProfileIn( $fname );
$titleChars = Title::legalChars();
+ $dtitleChars = "$titleChars|{}\[\]"; // [] so that {{{arg|[[foo|bar]]}} will work
# This function is called recursively. To keep track of arguments we need a stack:
array_push( $this->mArgStack, $args );
@@ -1972,9 +1973,12 @@
# Variable substitution
$text = preg_replace_callback( "/{{([$titleChars]*?)}}/", array( &$this, 'variableSubstitution' ), $text );
- if ( $this->mOutputType == OT_HTML || $this->mOutputType == OT_WIKI ) {
+ if ( $this->mOutputType == OT_WIKI ) {
# Argument substitution
- $text = preg_replace_callback( "/{{{([$titleChars]*?)}}}/", array( &$this, 'argSubstitution' ), $text );
+ $text = preg_replace_callback( "/{{{([$dtitleChars]*?)}}}/", array( &$this, 'argSubstitution' ), $text );
+ } elseif ( $this->mOutputType == OT_HTML ) {
+ # Argument substitution + default argument substitution
+ $text = preg_replace_callback( "/{{{([$dtitleChars]*?)}}}/", array( &$this, 'argSubstitutionWDefaults' ), $text );
}
# Template substitution
$regex = '/(\\n|{)?{{(['.$titleChars.']*)(\\|.*?|)}}/s';
@@ -2419,6 +2423,31 @@
if ( array_key_exists( $arg, $inputArgs ) ) {
$text = $inputArgs[$arg];
}
+
+ return $text;
+ }
+
+ /**
+ * Triple brace replacement with default arguments-- used for template arguments
+ * @access private
+ */
+ function argSubstitutionWDefaults( $matches ) {
+ $arg = trim( $matches[1] );
+
+ if ( strpos( $arg, '|' ) !== false ) {
+ list( $arg, $default ) = explode( '|', $arg, 2 );
+ $arg = rtrim( $arg );
+ $default = ltrim( $default );
+ } else
+ $default = null;
+
+ $text = $matches[0];
+ $inputArgs = end( $this->mArgStack );
+
+ if ( array_key_exists( $arg, $inputArgs ) ) {
+ $text = $inputArgs[$arg];
+ } else if ( $default !== null )
+ $text = $default;
return $text;
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1182
Default Alt Text
defaultargs.patch (2 KB)
Attached To
Mode
T2364: Optional parameters (and/or default parameter values) in templates
Attached
Detach File
Event Timeline
Log In to Comment