r61710 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61709‎ | r61710 | r61711 >
Date:11:58, 30 January 2010
Author:conrad
Status:deferred (Comments)
Tags:
Comment:
bug 22297 - "syntax for substitution that doesn't break transclusion"
Adds "safesubst:$1" that works similarly to "subst:$1"
(relevant to bug 5453, bug 16714, bug 4484)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/MagicWord.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -91,9 +91,9 @@
9292 */
9393 # Persistent:
9494 var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables,
95 - $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex, $mPreprocessor,
96 - $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList, $mVarCache, $mConf,
97 - $mFunctionTagHooks;
 95+ $mSubsts, $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex,
 96+ $mPreprocessor, $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList,
 97+ $mVarCache, $mConf, $mFunctionTagHooks;
9898
9999
100100 # Cleared with clearState():
@@ -2617,15 +2617,17 @@
26182618 }
26192619
26202620 /**
2621 - * initialise the magic variables (like CURRENTMONTHNAME)
 2621+ * initialise the magic variables (like CURRENTMONTHNAME) and substitution modifiers
26222622 *
26232623 * @private
26242624 */
26252625 function initialiseVariables() {
26262626 wfProfileIn( __METHOD__ );
26272627 $variableIDs = MagicWord::getVariableIDs();
 2628+ $substIDs = MagicWord::getSubstIDs();
26282629
26292630 $this->mVariables = new MagicWordArray( $variableIDs );
 2631+ $this->mSubsts = new MagicWordArray( $substIDs );
26302632 wfProfileOut( __METHOD__ );
26312633 }
26322634
@@ -2796,12 +2798,19 @@
27972799 # SUBST
27982800 wfProfileIn( __METHOD__.'-modifiers' );
27992801 if ( !$found ) {
2800 - $mwSubst = MagicWord::get( 'subst' );
2801 - if ( $mwSubst->matchStartAndRemove( $part1 ) xor $this->ot['wiki'] ) {
2802 - # One of two possibilities is true:
2803 - # 1) Found SUBST but not in the PST phase
2804 - # 2) Didn't find SUBST and in the PST phase
2805 - # In either case, return without further processing
 2802+
 2803+ $substMatch = $this->mSubsts->matchVariableStartToEnd( $part1 );
 2804+
 2805+ # Possibilities for substMatch[0]: "subst", "safesubst" or FALSE
 2806+ # Whether to include depends also on whether we are in the pre-save-transform
 2807+ #
 2808+ # safesubst || (subst && PST) => transclude (handled by if)
 2809+ # (false && PST) || (subst && !PST) => return input (handled by else if)
 2810+ # false && !PST => transclude (no handling needed here)
 2811+ if ( $substMatch[0] && ( $this->ot['wiki'] || $substMatch[0] == 'safesubst' ) ) {
 2812+ $part1 = $substMatch[1];
 2813+
 2814+ } else if ( $substMatch[0] xor $this->ot['wiki'] ) {
28062815 $text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args );
28072816 $isLocalObj = true;
28082817 $found = true;
Index: trunk/phase3/includes/MagicWord.php
@@ -165,6 +165,10 @@
166166 'nocontentconvert',
167167 );
168168
 169+ static public $mSubstIDs = array(
 170+ 'subst',
 171+ 'safesubst',
 172+ );
169173
170174 static public $mObjects = array();
171175 static public $mDoubleUnderscoreArray = null;
@@ -216,6 +220,13 @@
217221 return self::$mVariableIDs;
218222 }
219223
 224+ /**
 225+ * Get an array of parser substitution modifier IDs
 226+ */
 227+ static function getSubstIDs() {
 228+ return self::$mSubstIDs;
 229+ }
 230+
220231 /* Allow external reads of TTL array */
221232 static function getCacheTTL($id) {
222233 if (array_key_exists($id,self::$mCacheTTLs)) {
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -264,7 +264,8 @@
265265 'subjectpagename' => array( 1, 'SUBJECTPAGENAME', 'ARTICLEPAGENAME' ),
266266 'subjectpagenamee' => array( 1, 'SUBJECTPAGENAMEE', 'ARTICLEPAGENAMEE' ),
267267 'msg' => array( 0, 'MSG:' ),
268 - 'subst' => array( 0, 'SUBST:' ),
 268+ 'subst' => array( 0, 'SUBST:$1' ),
 269+ 'safesubst' => array( 0, 'SAFESUBST:$1' ),
269270 'msgnw' => array( 0, 'MSGNW:' ),
270271 'img_thumbnail' => array( 1, 'thumbnail', 'thumb' ),
271272 'img_manualthumb' => array( 1, 'thumbnail=$1', 'thumb=$1'),
Index: trunk/phase3/RELEASE-NOTES
@@ -809,6 +809,7 @@
810810 * (bug 22248) Output extension URLs in meta=siteinfo&siprop=extensions
811811 * Support key-params arrays in 'descriptionmsg' in meta=siteinfo&siprop=extensions
812812 * (bug 21922) YAML output should quote asterisk when used as key
 813+* (bug 22297) safesubst: to allow substitution without breaking transclusion
813814
814815 === Languages updated in 1.16 ===
815816

Follow-up revisions

RevisionCommit summaryAuthorDate
r61713Fix for r61710. Changing subst: to subst:$1 would cause huge problems with lo...conrad12:46, 30 January 2010
r61858Parser tests for behaviour of subst: and safesubst: after r61710conrad15:24, 2 February 2010
r62069Allow pipe trick to work after PST....conrad15:00, 6 February 2010
r62505clean r61713 (and r61710) per code reviewconrad09:34, 15 February 2010

Comments

#Comment by Tim Starling (talk | contribs)   03:13, 15 February 2010

Review is at r61713.

Status & tagging log