Index: trunk/extensions/LabeledSectionTransclusion/lsth.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | * A parser extension that further extends labeled section transclusion, |
9 | 9 | * adding a function, #lsth for transcluding marked sections of text, |
10 | 10 | * |
11 | | - * This calls internal functions from lst.php. It will not work if that |
| 11 | + * This calls internal functions from lst.php. It will not work if that |
12 | 12 | * extension is not enabled, and may not work if the two files are not in |
13 | 13 | * sync. |
14 | 14 | * |
— | — | @@ -23,9 +23,9 @@ |
24 | 24 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
25 | 25 | */ |
26 | 26 | |
27 | | -# # |
| 27 | +## |
28 | 28 | # Standard initialisation code |
29 | | -# # |
| 29 | +## |
30 | 30 | |
31 | 31 | $wgExtensionFunctions[] = "wfLabeledSectionTransclusionHeading"; |
32 | 32 | $wgHooks['LanguageGetMagic'][] = 'wfLabeledSectionTransclusionHeadingMagic'; |
— | — | @@ -33,76 +33,76 @@ |
34 | 34 | |
35 | 35 | function wfLabeledSectionTransclusionHeading() |
36 | 36 | { |
37 | | - global $wgParser; |
38 | | - $wgParser->setFunctionHook( 'lsth', 'wfLstIncludeHeading' ); |
| 37 | + global $wgParser; |
| 38 | + $wgParser->setFunctionHook( 'lsth', 'wfLstIncludeHeading' ); |
39 | 39 | } |
40 | 40 | |
41 | 41 | function wfLabeledSectionTransclusionHeadingMagic( &$magicWords, $langCode ) { |
42 | | - // Add the magic words |
43 | | - $magicWords['lsth'] = array( 0, 'lsth', 'section-h' ); |
44 | | - return true; |
| 42 | + // Add the magic words |
| 43 | + $magicWords['lsth'] = array( 0, 'lsth', 'section-h' ); |
| 44 | + return true; |
45 | 45 | } |
46 | 46 | |
47 | 47 | /// section inclusion - include all matching sections |
48 | 48 | function wfLstIncludeHeading( $parser, $page = '', $sec = '', $to = '' ) |
49 | 49 | { |
50 | | - if ( LabeledSectionTransclusion::getTemplateText_( $parser, $page, $title, $text ) == false ) |
51 | | - return $text; |
| 50 | + if ( LabeledSectionTransclusion::getTemplateText_( $parser, $page, $title, $text ) == false ) |
| 51 | + return $text; |
52 | 52 | |
53 | | - // Generate a regex to match the === classical heading section(s) === we're |
54 | | - // interested in. |
55 | | - if ( $sec == '' ) { |
56 | | - $begin_off = 0; |
57 | | - $head_len = 6; |
58 | | - } else { |
59 | | - $pat = '^(={1,6})\s*' . preg_quote( $sec, '/' ) . '\s*\1\s*($)' ; |
60 | | - if ( preg_match( "/$pat/im", $text, $m, PREG_OFFSET_CAPTURE ) ) { |
61 | | - $begin_off = $m[2][1]; |
62 | | - $head_len = strlen( $m[1][0] ); |
63 | | - // wfDebug( "LSTH: offset is $begin_off" ); |
64 | | - } else { |
65 | | - // wfDebug( "LSTH: match failed: '$pat'" ); |
66 | | - return ''; |
67 | | - } |
| 53 | + // Generate a regex to match the === classical heading section(s) === we're |
| 54 | + // interested in. |
| 55 | + if ( $sec == '' ) { |
| 56 | + $begin_off = 0; |
| 57 | + $head_len = 6; |
| 58 | + } else { |
| 59 | + $pat = '^(={1,6})\s*' . preg_quote( $sec, '/' ) . '\s*\1\s*($)' ; |
| 60 | + if ( preg_match( "/$pat/im", $text, $m, PREG_OFFSET_CAPTURE ) ) { |
| 61 | + $begin_off = $m[2][1]; |
| 62 | + $head_len = strlen( $m[1][0] ); |
| 63 | + // wfDebug( "LSTH: offset is $begin_off" ); |
| 64 | + } else { |
| 65 | + // wfDebug( "LSTH: match failed: '$pat'" ); |
| 66 | + return ''; |
| 67 | + } |
68 | 68 | |
69 | | - } |
| 69 | + } |
70 | 70 | |
71 | | - if ( $to != '' ) { |
72 | | - // if $to is supplied, try and match it. If we don't match, just |
73 | | - // ignore it. |
74 | | - $pat = '^(={1,6})\s*' . preg_quote( $to, '/' ) . '\s*\1\s*$'; |
75 | | - if ( preg_match( "/$pat/im", $text, $m, PREG_OFFSET_CAPTURE, $begin_off ) ) |
76 | | - $end_off = $m[0][1] -1; |
77 | | - } |
| 71 | + if ( $to != '' ) { |
| 72 | + // if $to is supplied, try and match it. If we don't match, just |
| 73 | + // ignore it. |
| 74 | + $pat = '^(={1,6})\s*' . preg_quote( $to, '/' ) . '\s*\1\s*$'; |
| 75 | + if ( preg_match( "/$pat/im", $text, $m, PREG_OFFSET_CAPTURE, $begin_off ) ) |
| 76 | + $end_off = $m[0][1] -1; |
| 77 | + } |
78 | 78 | |
79 | 79 | |
80 | | - if ( ! isset( $end_off ) ) { |
81 | | - $pat = '^(={1,' . $head_len . '})(?!=).*?\1\s*$'; |
82 | | - if ( preg_match( "/$pat/im", $text, $m, PREG_OFFSET_CAPTURE, $begin_off ) ) |
83 | | - $end_off = $m[0][1] -1; |
84 | | - else |
85 | | - wfDebug( "LSTH: fail end match: '$pat'" ); |
| 80 | + if ( ! isset( $end_off ) ) { |
| 81 | + $pat = '^(={1,' . $head_len . '})(?!=).*?\1\s*$'; |
| 82 | + if ( preg_match( "/$pat/im", $text, $m, PREG_OFFSET_CAPTURE, $begin_off ) ) |
| 83 | + $end_off = $m[0][1] -1; |
| 84 | + else |
| 85 | + wfDebug( "LSTH: fail end match: '$pat'" ); |
86 | 86 | |
87 | | - // wfDebug("LSTH:head len is $head_len, pat is $pat, head is '.$m[1][0]'"; |
88 | | - } |
| 87 | + // wfDebug("LSTH:head len is $head_len, pat is $pat, head is '.$m[1][0]'"; |
| 88 | + } |
89 | 89 | |
90 | | - $nhead = LabeledSectionTransclusion::countHeadings_( $text, $begin_off ); |
91 | | - wfDebug( "LSTH: head offset = $nhead" ); |
| 90 | + $nhead = LabeledSectionTransclusion::countHeadings_( $text, $begin_off ); |
| 91 | + wfDebug( "LSTH: head offset = $nhead" ); |
92 | 92 | |
93 | | - if ( isset( $end_off ) ) |
94 | | - $result = substr( $text, $begin_off, $end_off - $begin_off ); |
95 | | - else |
96 | | - $result = substr( $text, $begin_off ); |
| 93 | + if ( isset( $end_off ) ) |
| 94 | + $result = substr( $text, $begin_off, $end_off - $begin_off ); |
| 95 | + else |
| 96 | + $result = substr( $text, $begin_off ); |
97 | 97 | |
98 | 98 | |
99 | | - if ( method_exists( $parser, 'getPreprocessor' ) ) |
100 | | - { |
101 | | - $frame = $parser->getPreprocessor()->newFrame(); |
102 | | - $dom = $parser->preprocessToDom( $result ); |
103 | | - $result = $frame->expand( $dom ); |
104 | | - } |
| 99 | + if ( method_exists( $parser, 'getPreprocessor' ) ) |
| 100 | + { |
| 101 | + $frame = $parser->getPreprocessor()->newFrame(); |
| 102 | + $dom = $parser->preprocessToDom( $result ); |
| 103 | + $result = $frame->expand( $dom ); |
| 104 | + } |
105 | 105 | |
106 | 106 | |
107 | | - return LabeledSectionTransclusion::parse_( $parser, $title, $result, "#lsth:${page}|${sec}", $nhead ); |
| 107 | + return LabeledSectionTransclusion::parse_( $parser, $title, $result, "#lsth:${page}|${sec}", $nhead ); |
108 | 108 | } |
109 | 109 | |
Index: trunk/extensions/LabeledSectionTransclusion/lst.php |
— | — | @@ -29,7 +29,6 @@ |
30 | 30 | 'name' => 'LabeledSectionTransclusion', |
31 | 31 | 'author' => 'Steve Sanbeg', |
32 | 32 | 'url' => 'http://www.mediawiki.org/wiki/Extension:Labeled_Section_Transclusion', |
33 | | - 'descriptionmsg' => 'lst-desc', |
34 | 33 | ); |
35 | 34 | $wgParserTestFiles[] = dirname( __FILE__ ) . "/lstParserTests.txt"; |
36 | 35 | $wgExtensionMessagesFiles['LabeledSectionTransclusion'] = dirname( __FILE__ ) . '/lst.i18n.php'; |
— | — | @@ -40,488 +39,488 @@ |
41 | 40 | |
42 | 41 | class LabeledSectionTransclusion { |
43 | 42 | |
44 | | - static function setup( $parser ) |
45 | | - { |
46 | | - $parser->setHook( 'section', array( __CLASS__, 'noop' ) ); |
47 | | - if ( defined( get_class( $parser ) . '::SFH_OBJECT_ARGS' ) ) { |
48 | | - $parser->setFunctionHook( 'lst', array( __CLASS__, 'pfuncIncludeObj' ), SFH_OBJECT_ARGS ); |
49 | | - $parser->setFunctionHook( 'lstx', array( __CLASS__, 'pfuncExcludeObj' ), SFH_OBJECT_ARGS ); |
50 | | - } else { |
51 | | - $parser->setFunctionHook( 'lst', array( __CLASS__, 'pfuncInclude' ) ); |
52 | | - $parser->setFunctionHook( 'lstx', array( __CLASS__, 'pfuncExclude' ) ); |
53 | | - } |
54 | | - } |
| 43 | + static function setup( $parser ) |
| 44 | + { |
| 45 | + $parser->setHook( 'section', array( __CLASS__, 'noop' ) ); |
| 46 | + if ( defined( get_class( $parser ) . '::SFH_OBJECT_ARGS' ) ) { |
| 47 | + $parser->setFunctionHook( 'lst', array( __CLASS__, 'pfuncIncludeObj' ), SFH_OBJECT_ARGS ); |
| 48 | + $parser->setFunctionHook( 'lstx', array( __CLASS__, 'pfuncExcludeObj' ), SFH_OBJECT_ARGS ); |
| 49 | + } else { |
| 50 | + $parser->setFunctionHook( 'lst', array( __CLASS__, 'pfuncInclude' ) ); |
| 51 | + $parser->setFunctionHook( 'lstx', array( __CLASS__, 'pfuncExclude' ) ); |
| 52 | + } |
| 53 | + } |
55 | 54 | |
56 | | - // / Add the magic words - possibly with more readable aliases |
57 | | - static function setupMagic( &$magicWords, $langCode ) { |
58 | | - global $wgParser, $wgLstLocal; |
| 55 | + // / Add the magic words - possibly with more readable aliases |
| 56 | + static function setupMagic( &$magicWords, $langCode ) { |
| 57 | + global $wgParser, $wgLstLocal; |
59 | 58 | |
60 | | - switch( $langCode ) { |
61 | | - case 'de': |
62 | | - $include = 'Abschnitt'; |
63 | | - $exclude = 'Abschnitt-x'; |
64 | | - $wgLstLocal = array( 'section' => 'Abschnitt', 'begin' => 'Anfang', 'end' => 'Ende' ) ; |
65 | | - break; |
66 | | - case 'he': |
67 | | - $include = 'קטע'; |
68 | | - $exclude = 'בלי קטע'; |
69 | | - $wgLstLocal = array( 'section' => 'קטע', 'begin' => 'התחלה', 'end' => 'סוף' ) ; |
70 | | - break; |
71 | | - case 'pt': |
72 | | - $include = 'trecho'; |
73 | | - $exclude = 'trecho-x'; |
74 | | - $wgLstLocal = array( 'section' => 'trecho', 'begin' => 'começo', 'end' => 'fim' ); |
75 | | - break; |
76 | | - } |
| 59 | + switch( $langCode ) { |
| 60 | + case 'de': |
| 61 | + $include = 'Abschnitt'; |
| 62 | + $exclude = 'Abschnitt-x'; |
| 63 | + $wgLstLocal = array( 'section' => 'Abschnitt', 'begin' => 'Anfang', 'end' => 'Ende' ) ; |
| 64 | + break; |
| 65 | + case 'he': |
| 66 | + $include = 'קטע'; |
| 67 | + $exclude = 'בלי קטע'; |
| 68 | + $wgLstLocal = array( 'section' => 'קטע', 'begin' => 'התחלה', 'end' => 'סוף' ) ; |
| 69 | + break; |
| 70 | + case 'pt': |
| 71 | + $include = 'trecho'; |
| 72 | + $exclude = 'trecho-x'; |
| 73 | + $wgLstLocal = array( 'section' => 'trecho', 'begin' => 'começo', 'end' => 'fim' ); |
| 74 | + break; |
| 75 | + } |
77 | 76 | |
78 | | - if ( isset( $include ) ) { |
79 | | - $magicWords['lst'] = array( 0, 'lst', 'section', $include ); |
80 | | - $magicWords['lstx'] = array( 0, 'lstx', 'section-x', $exclude ); |
81 | | - $wgParser->setHook( $include, array( __CLASS__, 'noop' ) ); |
82 | | - } else { |
83 | | - $magicWords['lst'] = array( 0, 'lst', 'section' ); |
84 | | - $magicWords['lstx'] = array( 0, 'lstx', 'section-x' ); |
85 | | - } |
| 77 | + if ( isset( $include ) ) { |
| 78 | + $magicWords['lst'] = array( 0, 'lst', 'section', $include ); |
| 79 | + $magicWords['lstx'] = array( 0, 'lstx', 'section-x', $exclude ); |
| 80 | + $wgParser->setHook( $include, array( __CLASS__, 'noop' ) ); |
| 81 | + } else { |
| 82 | + $magicWords['lst'] = array( 0, 'lst', 'section' ); |
| 83 | + $magicWords['lstx'] = array( 0, 'lstx', 'section-x' ); |
| 84 | + } |
86 | 85 | |
87 | | - return true; |
88 | | - } |
| 86 | + return true; |
| 87 | + } |
89 | 88 | |
90 | | - ############################################################## |
91 | | - # To do transclusion from an extension, we need to interact with the parser |
92 | | - # at a low level. This is the general transclusion functionality |
93 | | - ############################################################## |
| 89 | + ############################################################## |
| 90 | + # To do transclusion from an extension, we need to interact with the parser |
| 91 | + # at a low level. This is the general transclusion functionality |
| 92 | + ############################################################## |
94 | 93 | |
95 | | - /// Register what we're working on in the parser, so we don't fall into a trap. |
96 | | - static function open_( $parser, $part1 ) |
97 | | - { |
98 | | - // Infinite loop test |
99 | | - if ( isset( $parser->mTemplatePath[$part1] ) ) { |
100 | | - wfDebug( __METHOD__ . ": template loop broken at '$part1'\n" ); |
101 | | - return false; |
102 | | - } else { |
103 | | - $parser->mTemplatePath[$part1] = 1; |
104 | | - return true; |
105 | | - } |
| 94 | + /// Register what we're working on in the parser, so we don't fall into a trap. |
| 95 | + static function open_( $parser, $part1 ) |
| 96 | + { |
| 97 | + // Infinite loop test |
| 98 | + if ( isset( $parser->mTemplatePath[$part1] ) ) { |
| 99 | + wfDebug( __METHOD__ . ": template loop broken at '$part1'\n" ); |
| 100 | + return false; |
| 101 | + } else { |
| 102 | + $parser->mTemplatePath[$part1] = 1; |
| 103 | + return true; |
| 104 | + } |
106 | 105 | |
107 | | - } |
| 106 | + } |
108 | 107 | |
109 | | - /// Finish processing the function. |
110 | | - static function close_( $parser, $part1 ) |
111 | | - { |
112 | | - // Infinite loop test |
113 | | - if ( isset( $parser->mTemplatePath[$part1] ) ) { |
114 | | - unset( $parser->mTemplatePath[$part1] ); |
115 | | - } else { |
116 | | - wfDebug( __METHOD__ . ": close unopened template loop at '$part1'\n" ); |
117 | | - } |
118 | | - } |
| 108 | + /// Finish processing the function. |
| 109 | + static function close_( $parser, $part1 ) |
| 110 | + { |
| 111 | + // Infinite loop test |
| 112 | + if ( isset( $parser->mTemplatePath[$part1] ) ) { |
| 113 | + unset( $parser->mTemplatePath[$part1] ); |
| 114 | + } else { |
| 115 | + wfDebug( __METHOD__ . ": close unopened template loop at '$part1'\n" ); |
| 116 | + } |
| 117 | + } |
119 | 118 | |
120 | | - /** |
121 | | - * Handle recursive substitution here, so we can break cycles, and set up |
122 | | - * return values so that edit sections will resolve correctly. |
123 | | - * @param Parser $parser |
124 | | - * @param Title $title of target page |
125 | | - * @param string $text |
126 | | - * @param string $part1 Key for cycle detection |
127 | | - * @param int $skiphead Number of source string headers to skip for numbering |
128 | | - * @return mixed string or magic array of bits |
129 | | - * @todo handle mixed-case </section> |
130 | | - * @private |
131 | | - */ |
132 | | - static function parse_( $parser, $title, $text, $part1, $skiphead = 0 ) |
133 | | - { |
134 | | - // if someone tries something like<section begin=blah>lst only</section> |
135 | | - // text, may as well do the right thing. |
136 | | - $text = str_replace( '</section>', '', $text ); |
| 119 | + /** |
| 120 | + * Handle recursive substitution here, so we can break cycles, and set up |
| 121 | + * return values so that edit sections will resolve correctly. |
| 122 | + * @param Parser $parser |
| 123 | + * @param Title $title of target page |
| 124 | + * @param string $text |
| 125 | + * @param string $part1 Key for cycle detection |
| 126 | + * @param int $skiphead Number of source string headers to skip for numbering |
| 127 | + * @return mixed string or magic array of bits |
| 128 | + * @todo handle mixed-case </section> |
| 129 | + * @private |
| 130 | + */ |
| 131 | + static function parse_( $parser, $title, $text, $part1, $skiphead = 0 ) |
| 132 | + { |
| 133 | + // if someone tries something like<section begin=blah>lst only</section> |
| 134 | + // text, may as well do the right thing. |
| 135 | + $text = str_replace( '</section>', '', $text ); |
137 | 136 | |
138 | | - if ( self::open_( $parser, $part1 ) ) { |
139 | | - // Try to get edit sections correct by munging around the parser's guts. |
140 | | - return array( $text, 'title' => $title, 'replaceHeadings' => true, |
141 | | - 'headingOffset' => $skiphead, 'noparse' => false, 'noargs' => false ); |
142 | | - } else { |
143 | | - return "[[" . $title->getPrefixedText() . "]]" . |
144 | | - "<!-- WARNING: LST loop detected -->"; |
145 | | - } |
| 137 | + if ( self::open_( $parser, $part1 ) ) { |
| 138 | + // Try to get edit sections correct by munging around the parser's guts. |
| 139 | + return array( $text, 'title' => $title, 'replaceHeadings' => true, |
| 140 | + 'headingOffset' => $skiphead, 'noparse' => false, 'noargs' => false ); |
| 141 | + } else { |
| 142 | + return "[[" . $title->getPrefixedText() . "]]" . |
| 143 | + "<!-- WARNING: LST loop detected -->"; |
| 144 | + } |
146 | 145 | |
147 | | - } |
| 146 | + } |
148 | 147 | |
149 | | - ############################################################## |
150 | | - # And now, the labeled section transclusion |
151 | | - ############################################################## |
| 148 | + ############################################################## |
| 149 | + # And now, the labeled section transclusion |
| 150 | + ############################################################## |
152 | 151 | |
153 | | - /** |
154 | | - * Parser tag hook for <section>. |
155 | | - * The section markers aren't paired, so we only need to remove them. |
156 | | - * |
157 | | - * @param string $in |
158 | | - * @param array $assocArgs |
159 | | - * @param Parser $parser |
160 | | - * @return string HTML output |
161 | | - */ |
162 | | - static function noop( $in, $assocArgs = array(), $parser = null ) { |
163 | | - return ''; |
164 | | - } |
| 152 | + /** |
| 153 | + * Parser tag hook for <section>. |
| 154 | + * The section markers aren't paired, so we only need to remove them. |
| 155 | + * |
| 156 | + * @param string $in |
| 157 | + * @param array $assocArgs |
| 158 | + * @param Parser $parser |
| 159 | + * @return string HTML output |
| 160 | + */ |
| 161 | + static function noop( $in, $assocArgs = array(), $parser = null ) { |
| 162 | + return ''; |
| 163 | + } |
165 | 164 | |
166 | | - /** |
167 | | - * Generate a regex to match the section(s) we're interested in. |
168 | | - * @param string $sec Name of target section |
169 | | - * @param string $to Optional name of section to end with, if transcluding |
170 | | - * multiple sections in sequence. If blank, will assume |
171 | | - * same section name as started with. |
172 | | - * @return string regex |
173 | | - * @private |
174 | | - */ |
175 | | - static function getPattern_( $sec, $to ) |
176 | | - { |
177 | | - global $wgLstLocal; |
| 165 | + /** |
| 166 | + * Generate a regex to match the section(s) we're interested in. |
| 167 | + * @param string $sec Name of target section |
| 168 | + * @param string $to Optional name of section to end with, if transcluding |
| 169 | + * multiple sections in sequence. If blank, will assume |
| 170 | + * same section name as started with. |
| 171 | + * @return string regex |
| 172 | + * @private |
| 173 | + */ |
| 174 | + static function getPattern_( $sec, $to ) |
| 175 | + { |
| 176 | + global $wgLstLocal; |
178 | 177 | |
179 | | - $beginAttr = self::getAttrPattern_( $sec, 'begin' ); |
180 | | - if ( $to == '' ) { |
181 | | - $endAttr = self::getAttrPattern_( $sec, 'end' ); |
182 | | - } else { |
183 | | - $endAttr = self::getAttrPattern_( $to, 'end' ); |
184 | | - } |
| 178 | + $beginAttr = self::getAttrPattern_( $sec, 'begin' ); |
| 179 | + if ( $to == '' ) { |
| 180 | + $endAttr = self::getAttrPattern_( $sec, 'end' ); |
| 181 | + } else { |
| 182 | + $endAttr = self::getAttrPattern_( $to, 'end' ); |
| 183 | + } |
185 | 184 | |
186 | | - $to_sec = ( $to == '' ) ? $sec : $to; |
187 | | - $sec = preg_quote( $sec, '/' ); |
188 | | - $to_sec = preg_quote( $to_sec, '/' ); |
189 | | - if ( isset( $wgLstLocal ) ) { |
190 | | - $section_re = "(?i:section|$wgLstLocal[section])"; |
191 | | - } else { |
192 | | - $section_re = "(?i:section)"; |
193 | | - } |
| 185 | + $to_sec = ( $to == '' ) ? $sec : $to; |
| 186 | + $sec = preg_quote( $sec, '/' ); |
| 187 | + $to_sec = preg_quote( $to_sec, '/' ); |
| 188 | + if ( isset( $wgLstLocal ) ) { |
| 189 | + $section_re = "(?i:section|$wgLstLocal[section])"; |
| 190 | + } else { |
| 191 | + $section_re = "(?i:section)"; |
| 192 | + } |
194 | 193 | |
195 | | - return "/<$section_re$beginAttr\/?>(.*?)\n?<$section_re$endAttr\/?>/s"; |
196 | | - } |
| 194 | + return "/<$section_re$beginAttr\/?>(.*?)\n?<$section_re$endAttr\/?>/s"; |
| 195 | + } |
197 | 196 | |
198 | | - /** |
199 | | - * Generate a regex fragment matching the attribute portion of a section tag |
200 | | - * @param string $sec Name of the target section |
201 | | - * @param string $type Either "begin" or "end" depending on the type of section tag to be matched |
202 | | - */ |
203 | | - static function getAttrPattern_( $sec, $type ) { |
204 | | - global $wgLstLocal; |
205 | | - $sec = preg_quote( $sec, '/' ); |
206 | | - $ws = "(?:\s+[^>]*)?"; // was like $ws="\s*" |
207 | | - if ( isset( $wgLstLocal ) ) { |
208 | | - if ( $type == 'begin' ) { |
209 | | - $attrName = "(?i:begin|{$wgLstLocal['begin']})"; |
210 | | - } else { |
211 | | - $attrName = "(?i:end|{$wgLstLocal['end']})"; |
212 | | - } |
213 | | - } else { |
214 | | - if ( $type == 'begin' ) { |
215 | | - $attrName = "(?i:begin)"; |
216 | | - } else { |
217 | | - $attrName = "(?i:end)"; |
218 | | - } |
219 | | - } |
220 | | - return "$ws\s+$attrName=(?:$sec|\"$sec\"|'$sec')$ws"; |
221 | | - } |
| 197 | + /** |
| 198 | + * Generate a regex fragment matching the attribute portion of a section tag |
| 199 | + * @param string $sec Name of the target section |
| 200 | + * @param string $type Either "begin" or "end" depending on the type of section tag to be matched |
| 201 | + */ |
| 202 | + static function getAttrPattern_( $sec, $type ) { |
| 203 | + global $wgLstLocal; |
| 204 | + $sec = preg_quote( $sec, '/' ); |
| 205 | + $ws = "(?:\s+[^>]*)?"; // was like $ws="\s*" |
| 206 | + if ( isset( $wgLstLocal ) ) { |
| 207 | + if ( $type == 'begin' ) { |
| 208 | + $attrName = "(?i:begin|{$wgLstLocal['begin']})"; |
| 209 | + } else { |
| 210 | + $attrName = "(?i:end|{$wgLstLocal['end']})"; |
| 211 | + } |
| 212 | + } else { |
| 213 | + if ( $type == 'begin' ) { |
| 214 | + $attrName = "(?i:begin)"; |
| 215 | + } else { |
| 216 | + $attrName = "(?i:end)"; |
| 217 | + } |
| 218 | + } |
| 219 | + return "$ws\s+$attrName=(?:$sec|\"$sec\"|'$sec')$ws"; |
| 220 | + } |
222 | 221 | |
223 | | - /** |
224 | | - * Count headings in skipped text. |
225 | | - * |
226 | | - * Count skipped headings, so parser (as of r18218) can skip them, to |
227 | | - * prevent wrong heading links (see bug 6563). |
228 | | - * |
229 | | - * @param string $text |
230 | | - * @param int $limit Cutoff point in the text to stop searching |
231 | | - * @return int Number of matches |
232 | | - * @private |
233 | | - */ |
234 | | - static function countHeadings_( $text, $limit ) |
235 | | - { |
236 | | - $pat = '^(={1,6}).+\1\s*$()'; |
| 222 | + /** |
| 223 | + * Count headings in skipped text. |
| 224 | + * |
| 225 | + * Count skipped headings, so parser (as of r18218) can skip them, to |
| 226 | + * prevent wrong heading links (see bug 6563). |
| 227 | + * |
| 228 | + * @param string $text |
| 229 | + * @param int $limit Cutoff point in the text to stop searching |
| 230 | + * @return int Number of matches |
| 231 | + * @private |
| 232 | + */ |
| 233 | + static function countHeadings_( $text, $limit ) |
| 234 | + { |
| 235 | + $pat = '^(={1,6}).+\1\s*$()'; |
237 | 236 | |
238 | | - // return preg_match_all( "/$pat/im", substr($text,0,$limit), $m); |
| 237 | + // return preg_match_all( "/$pat/im", substr($text,0,$limit), $m); |
239 | 238 | |
240 | | - $count = 0; |
241 | | - $offset = 0; |
242 | | - while ( preg_match( "/$pat/im", $text, $m, PREG_OFFSET_CAPTURE, $offset ) ) { |
243 | | - if ( $m[2][1] > $limit ) |
244 | | - break; |
| 239 | + $count = 0; |
| 240 | + $offset = 0; |
| 241 | + while ( preg_match( "/$pat/im", $text, $m, PREG_OFFSET_CAPTURE, $offset ) ) { |
| 242 | + if ( $m[2][1] > $limit ) |
| 243 | + break; |
245 | 244 | |
246 | | - $count++; |
247 | | - $offset = $m[2][1]; |
248 | | - } |
| 245 | + $count++; |
| 246 | + $offset = $m[2][1]; |
| 247 | + } |
249 | 248 | |
250 | | - return $count; |
251 | | - } |
| 249 | + return $count; |
| 250 | + } |
252 | 251 | |
253 | | - /** |
254 | | - * Fetches content of target page if valid and found, otherwise |
255 | | - * produces wikitext of a link to the target page. |
256 | | - * |
257 | | - * @param Parser $parser |
258 | | - * @param string $page title text of target page |
259 | | - * @param (out) Title $title normalized title object |
260 | | - * @param (out) string $text wikitext output |
261 | | - * @return string bool true if returning text, false if target not found |
262 | | - * @private |
263 | | - */ |
264 | | - static function getTemplateText_( $parser, $page, &$title, &$text ) |
265 | | - { |
266 | | - $title = Title::newFromText( $page ); |
| 252 | + /** |
| 253 | + * Fetches content of target page if valid and found, otherwise |
| 254 | + * produces wikitext of a link to the target page. |
| 255 | + * |
| 256 | + * @param Parser $parser |
| 257 | + * @param string $page title text of target page |
| 258 | + * @param (out) Title $title normalized title object |
| 259 | + * @param (out) string $text wikitext output |
| 260 | + * @return string bool true if returning text, false if target not found |
| 261 | + * @private |
| 262 | + */ |
| 263 | + static function getTemplateText_( $parser, $page, &$title, &$text ) |
| 264 | + { |
| 265 | + $title = Title::newFromText( $page ); |
267 | 266 | |
268 | | - if ( is_null( $title ) ) { |
269 | | - $text = ''; |
270 | | - return true; |
271 | | - } else { |
272 | | - if ( method_exists( $parser, 'fetchTemplateAndTitle' ) ) { |
273 | | - list( $text, $title ) = $parser->fetchTemplateAndTitle( $title ); |
274 | | - } else { |
275 | | - $text = $parser->fetchTemplate( $title ); |
276 | | - } |
277 | | - } |
| 267 | + if ( is_null( $title ) ) { |
| 268 | + $text = ''; |
| 269 | + return true; |
| 270 | + } else { |
| 271 | + if ( method_exists( $parser, 'fetchTemplateAndTitle' ) ) { |
| 272 | + list( $text, $title ) = $parser->fetchTemplateAndTitle( $title ); |
| 273 | + } else { |
| 274 | + $text = $parser->fetchTemplate( $title ); |
| 275 | + } |
| 276 | + } |
278 | 277 | |
279 | | - // if article doesn't exist, return a red link. |
280 | | - if ( $text == false ) { |
281 | | - $text = "[[" . $title->getPrefixedText() . "]]"; |
282 | | - return false; |
283 | | - } else { |
284 | | - return true; |
285 | | - } |
286 | | - } |
| 278 | + // if article doesn't exist, return a red link. |
| 279 | + if ( $text == false ) { |
| 280 | + $text = "[[" . $title->getPrefixedText() . "]]"; |
| 281 | + return false; |
| 282 | + } else { |
| 283 | + return true; |
| 284 | + } |
| 285 | + } |
287 | 286 | |
288 | | - /** |
289 | | - * Parser function hook for '#lst:' |
290 | | - * section inclusion - include all matching sections |
291 | | - * |
292 | | - * @param Parser $parser |
293 | | - * @param string $page Title text of target page |
294 | | - * @param string $sec Named section to transclude |
295 | | - * @param string $to Optional named section to end at |
296 | | - * @return mixed wikitext output |
297 | | - */ |
298 | | - function pfuncInclude( $parser, $page = '', $sec = '', $to = '' ) |
299 | | - { |
300 | | - if ( self::getTemplateText_( $parser, $page, $title, $text ) == false ) |
301 | | - return $text; |
302 | | - $pat = self::getPattern_( $sec, $to ); |
| 287 | + /** |
| 288 | + * Parser function hook for '#lst:' |
| 289 | + * section inclusion - include all matching sections |
| 290 | + * |
| 291 | + * @param Parser $parser |
| 292 | + * @param string $page Title text of target page |
| 293 | + * @param string $sec Named section to transclude |
| 294 | + * @param string $to Optional named section to end at |
| 295 | + * @return mixed wikitext output |
| 296 | + */ |
| 297 | + function pfuncInclude( $parser, $page = '', $sec = '', $to = '' ) |
| 298 | + { |
| 299 | + if ( self::getTemplateText_( $parser, $page, $title, $text ) == false ) |
| 300 | + return $text; |
| 301 | + $pat = self::getPattern_( $sec, $to ); |
303 | 302 | |
304 | | - if ( preg_match_all( $pat, $text, $m, PREG_OFFSET_CAPTURE ) ) { |
305 | | - $headings = self::countHeadings_( $text, $m[0][0][1] ); |
306 | | - } else { |
307 | | - $headings = 0; |
308 | | - } |
| 303 | + if ( preg_match_all( $pat, $text, $m, PREG_OFFSET_CAPTURE ) ) { |
| 304 | + $headings = self::countHeadings_( $text, $m[0][0][1] ); |
| 305 | + } else { |
| 306 | + $headings = 0; |
| 307 | + } |
309 | 308 | |
310 | | - $text = ''; |
311 | | - foreach ( $m[1] as $piece ) { |
312 | | - $text .= $piece[0]; |
313 | | - } |
| 309 | + $text = ''; |
| 310 | + foreach ( $m[1] as $piece ) { |
| 311 | + $text .= $piece[0]; |
| 312 | + } |
314 | 313 | |
315 | | - // wfDebug(__METHOD__.": skip $headings headings"); |
316 | | - return self::parse_( $parser, $title, $text, "#lst:${page}|${sec}", $headings ); |
317 | | - } |
| 314 | + // wfDebug(__METHOD__.": skip $headings headings"); |
| 315 | + return self::parse_( $parser, $title, $text, "#lst:${page}|${sec}", $headings ); |
| 316 | + } |
318 | 317 | |
319 | | - /** |
320 | | - * Set up some variables for MW-1.12 parser functions |
321 | | - */ |
322 | | - static function setupPfunc12( $parser, $frame, $args, $func = 'lst' ) { |
323 | | - if ( !count( $args ) ) { |
324 | | - return ''; |
325 | | - } |
| 318 | + /** |
| 319 | + * Set up some variables for MW-1.12 parser functions |
| 320 | + */ |
| 321 | + static function setupPfunc12( $parser, $frame, $args, $func = 'lst' ) { |
| 322 | + if ( !count( $args ) ) { |
| 323 | + return ''; |
| 324 | + } |
326 | 325 | |
327 | | - $title = Title::newFromText( trim( $frame->expand( array_shift( $args ) ) ) ); |
328 | | - if ( !$title ) { |
329 | | - return ''; |
330 | | - } |
331 | | - if ( !$frame->loopCheck( $title ) ) { |
332 | | - return "[[" . $title->getPrefixedText() . "]]" . |
333 | | - "<!-- WARNING: LST loop detected -->"; |
334 | | - } |
| 326 | + $title = Title::newFromText( trim( $frame->expand( array_shift( $args ) ) ) ); |
| 327 | + if ( !$title ) { |
| 328 | + return ''; |
| 329 | + } |
| 330 | + if ( !$frame->loopCheck( $title ) ) { |
| 331 | + return "[[" . $title->getPrefixedText() . "]]" . |
| 332 | + "<!-- WARNING: LST loop detected -->"; |
| 333 | + } |
335 | 334 | |
336 | | - list( $root, $finalTitle ) = $parser->getTemplateDom( $title ); |
| 335 | + list( $root, $finalTitle ) = $parser->getTemplateDom( $title ); |
337 | 336 | |
338 | | - // if article doesn't exist, return a red link. |
339 | | - if ( $root === false ) { |
340 | | - return "[[" . $title->getPrefixedText() . "]]"; |
341 | | - } |
| 337 | + // if article doesn't exist, return a red link. |
| 338 | + if ( $root === false ) { |
| 339 | + return "[[" . $title->getPrefixedText() . "]]"; |
| 340 | + } |
342 | 341 | |
343 | | - $newFrame = $frame->newChild( false, $finalTitle ); |
344 | | - if ( !count( $args ) ) { |
345 | | - return $newFrame->expand( $root ); |
346 | | - } |
| 342 | + $newFrame = $frame->newChild( false, $finalTitle ); |
| 343 | + if ( !count( $args ) ) { |
| 344 | + return $newFrame->expand( $root ); |
| 345 | + } |
347 | 346 | |
348 | | - $begin = trim( $frame->expand( array_shift( $args ) ) ); |
| 347 | + $begin = trim( $frame->expand( array_shift( $args ) ) ); |
349 | 348 | |
350 | | - if ( $func == 'lstx' ) { |
351 | | - if ( !count( $args ) ) { |
352 | | - $repl = ''; |
353 | | - } else { |
354 | | - $repl = trim( $frame->expand( array_shift( $args ) ) ); |
355 | | - } |
356 | | - } |
| 349 | + if ( $func == 'lstx' ) { |
| 350 | + if ( !count( $args ) ) { |
| 351 | + $repl = ''; |
| 352 | + } else { |
| 353 | + $repl = trim( $frame->expand( array_shift( $args ) ) ); |
| 354 | + } |
| 355 | + } |
357 | 356 | |
358 | | - if ( !count( $args ) ) { |
359 | | - $end = $begin; |
360 | | - } else { |
361 | | - $end = trim( $frame->expand( array_shift( $args ) ) ); |
362 | | - } |
| 357 | + if ( !count( $args ) ) { |
| 358 | + $end = $begin; |
| 359 | + } else { |
| 360 | + $end = trim( $frame->expand( array_shift( $args ) ) ); |
| 361 | + } |
363 | 362 | |
364 | | - $beginAttr = self::getAttrPattern_( $begin, 'begin' ); |
365 | | - $beginRegex = "/^$beginAttr$/s"; |
366 | | - $endAttr = self::getAttrPattern_( $end, 'end' ); |
367 | | - $endRegex = "/^$endAttr$/s"; |
| 363 | + $beginAttr = self::getAttrPattern_( $begin, 'begin' ); |
| 364 | + $beginRegex = "/^$beginAttr$/s"; |
| 365 | + $endAttr = self::getAttrPattern_( $end, 'end' ); |
| 366 | + $endRegex = "/^$endAttr$/s"; |
368 | 367 | |
369 | | - return compact( 'dom', 'root', 'newFrame', 'repl', 'beginRegex', 'endRegex' ); |
370 | | - } |
| 368 | + return compact( 'dom', 'root', 'newFrame', 'repl', 'beginRegex', 'endRegex' ); |
| 369 | + } |
371 | 370 | |
372 | | - /** |
373 | | - * Returns true if the given extension name is "section" |
374 | | - */ |
375 | | - static function isSection( $name ) { |
376 | | - global $wgLstLocal; |
377 | | - $name = strtolower( $name ); |
378 | | - return $name == 'section' |
379 | | - || ( isset( $wgLstLocal['section'] ) && strtolower( $wgLstLocal['section'] ) == $name ); |
380 | | - } |
| 371 | + /** |
| 372 | + * Returns true if the given extension name is "section" |
| 373 | + */ |
| 374 | + static function isSection( $name ) { |
| 375 | + global $wgLstLocal; |
| 376 | + $name = strtolower( $name ); |
| 377 | + return $name == 'section' |
| 378 | + || ( isset( $wgLstLocal['section'] ) && strtolower( $wgLstLocal['section'] ) == $name ); |
| 379 | + } |
381 | 380 | |
382 | | - /** |
383 | | - * Returns the text for the inside of a split <section> node |
384 | | - */ |
385 | | - static function expandSectionNode( $parser, $frame, $parts ) { |
386 | | - if ( isset( $parts['inner'] ) ) { |
387 | | - return $parser->replaceVariables( $parts['inner'], $frame ); |
388 | | - } else { |
389 | | - return ''; |
390 | | - } |
391 | | - } |
| 381 | + /** |
| 382 | + * Returns the text for the inside of a split <section> node |
| 383 | + */ |
| 384 | + static function expandSectionNode( $parser, $frame, $parts ) { |
| 385 | + if ( isset( $parts['inner'] ) ) { |
| 386 | + return $parser->replaceVariables( $parts['inner'], $frame ); |
| 387 | + } else { |
| 388 | + return ''; |
| 389 | + } |
| 390 | + } |
392 | 391 | |
393 | | - /** |
394 | | - * MW 1.12 version of #lst |
395 | | - */ |
396 | | - static function pfuncIncludeObj( $parser, $frame, $args ) { |
397 | | - $setup = self::setupPfunc12( $parser, $frame, $args, 'lst' ); |
398 | | - if ( !is_array( $setup ) ) { |
399 | | - return $setup; |
400 | | - } |
401 | | - extract( $setup ); |
| 392 | + /** |
| 393 | + * MW 1.12 version of #lst |
| 394 | + */ |
| 395 | + static function pfuncIncludeObj( $parser, $frame, $args ) { |
| 396 | + $setup = self::setupPfunc12( $parser, $frame, $args, 'lst' ); |
| 397 | + if ( !is_array( $setup ) ) { |
| 398 | + return $setup; |
| 399 | + } |
| 400 | + extract( $setup ); |
402 | 401 | |
403 | | - $text = ''; |
404 | | - $node = $root->getFirstChild(); |
405 | | - while ( $node ) { |
406 | | - // Find the begin node |
407 | | - $found = false; |
408 | | - for ( ; $node; $node = $node->getNextSibling() ) { |
409 | | - if ( $node->getName() != 'ext' ) { |
410 | | - continue; |
411 | | - } |
412 | | - $parts = $node->splitExt(); |
413 | | - $parts = array_map( array( $newFrame, 'expand' ), $parts ); |
414 | | - if ( self::isSection( $parts['name'] ) ) { |
415 | | - if ( preg_match( $beginRegex, $parts['attr'] ) ) { |
416 | | - $found = true; |
417 | | - break; |
418 | | - } |
419 | | - } |
420 | | - } |
421 | | - if ( !$found || !$node ) { |
422 | | - break; |
423 | | - } |
| 402 | + $text = ''; |
| 403 | + $node = $root->getFirstChild(); |
| 404 | + while ( $node ) { |
| 405 | + // Find the begin node |
| 406 | + $found = false; |
| 407 | + for ( ; $node; $node = $node->getNextSibling() ) { |
| 408 | + if ( $node->getName() != 'ext' ) { |
| 409 | + continue; |
| 410 | + } |
| 411 | + $parts = $node->splitExt(); |
| 412 | + $parts = array_map( array( $newFrame, 'expand' ), $parts ); |
| 413 | + if ( self::isSection( $parts['name'] ) ) { |
| 414 | + if ( preg_match( $beginRegex, $parts['attr'] ) ) { |
| 415 | + $found = true; |
| 416 | + break; |
| 417 | + } |
| 418 | + } |
| 419 | + } |
| 420 | + if ( !$found || !$node ) { |
| 421 | + break; |
| 422 | + } |
424 | 423 | |
425 | | - // Write the text out while looking for the end node |
426 | | - $found = false; |
427 | | - for ( ; $node; $node = $node->getNextSibling() ) { |
428 | | - if ( $node->getName() === 'ext' ) { |
429 | | - $parts = $node->splitExt(); |
430 | | - $parts = array_map( array( $newFrame, 'expand' ), $parts ); |
431 | | - if ( self::isSection( $parts['name'] ) ) { |
432 | | - if ( preg_match( $endRegex, $parts['attr'] ) ) { |
433 | | - $found = true; |
434 | | - break; |
435 | | - } |
436 | | - $text .= self::expandSectionNode( $parser, $newFrame, $parts ); |
437 | | - } else { |
438 | | - $text .= $newFrame->expand( $node ); |
439 | | - } |
440 | | - } else { |
441 | | - $text .= $newFrame->expand( $node ); |
442 | | - } |
443 | | - } |
444 | | - if ( !$found ) { |
445 | | - break; |
446 | | - } |
447 | | - $node = $node->getNextSibling(); |
448 | | - } |
449 | | - return $text; |
450 | | - } |
| 424 | + // Write the text out while looking for the end node |
| 425 | + $found = false; |
| 426 | + for ( ; $node; $node = $node->getNextSibling() ) { |
| 427 | + if ( $node->getName() === 'ext' ) { |
| 428 | + $parts = $node->splitExt(); |
| 429 | + $parts = array_map( array( $newFrame, 'expand' ), $parts ); |
| 430 | + if ( self::isSection( $parts['name'] ) ) { |
| 431 | + if ( preg_match( $endRegex, $parts['attr'] ) ) { |
| 432 | + $found = true; |
| 433 | + break; |
| 434 | + } |
| 435 | + $text .= self::expandSectionNode( $parser, $newFrame, $parts ); |
| 436 | + } else { |
| 437 | + $text .= $newFrame->expand( $node ); |
| 438 | + } |
| 439 | + } else { |
| 440 | + $text .= $newFrame->expand( $node ); |
| 441 | + } |
| 442 | + } |
| 443 | + if ( !$found ) { |
| 444 | + break; |
| 445 | + } |
| 446 | + $node = $node->getNextSibling(); |
| 447 | + } |
| 448 | + return $text; |
| 449 | + } |
451 | 450 | |
452 | | - /** |
453 | | - * Parser function hook for '#lstx:' |
454 | | - * section exclusion, with optional replacement |
455 | | - * |
456 | | - * @param Parser $parser |
457 | | - * @param string $page Title text of target page |
458 | | - * @param string $sec Named section to transclude |
459 | | - * @param string $repl Optional wikitext to use to fill in the excluded section |
460 | | - * @param string $to Optional named section to end at |
461 | | - * @return mixed wikitext output |
462 | | - */ |
463 | | - static function pfuncExclude( $parser, $page = '', $sec = '', $repl = '', $to = '' ) |
464 | | - { |
465 | | - if ( self::getTemplateText_( $parser, $page, $title, $text ) == false ) |
466 | | - return $text; |
467 | | - $pat = self::getPattern_( $sec, $to ); |
468 | | - $text = preg_replace( $pat, $repl, $text ); |
469 | | - return self::parse_( $parser, $title, $text, "#lstx:$page|$sec" ); |
470 | | - } |
| 451 | + /** |
| 452 | + * Parser function hook for '#lstx:' |
| 453 | + * section exclusion, with optional replacement |
| 454 | + * |
| 455 | + * @param Parser $parser |
| 456 | + * @param string $page Title text of target page |
| 457 | + * @param string $sec Named section to transclude |
| 458 | + * @param string $repl Optional wikitext to use to fill in the excluded section |
| 459 | + * @param string $to Optional named section to end at |
| 460 | + * @return mixed wikitext output |
| 461 | + */ |
| 462 | + static function pfuncExclude( $parser, $page = '', $sec = '', $repl = '', $to = '' ) |
| 463 | + { |
| 464 | + if ( self::getTemplateText_( $parser, $page, $title, $text ) == false ) |
| 465 | + return $text; |
| 466 | + $pat = self::getPattern_( $sec, $to ); |
| 467 | + $text = preg_replace( $pat, $repl, $text ); |
| 468 | + return self::parse_( $parser, $title, $text, "#lstx:$page|$sec" ); |
| 469 | + } |
471 | 470 | |
472 | | - /** |
473 | | - * MW 1.12 version of #lstx |
474 | | - */ |
475 | | - static function pfuncExcludeObj( $parser, $frame, $args ) { |
476 | | - $setup = self::setupPfunc12( $parser, $frame, $args, 'lstx' ); |
477 | | - if ( !is_array( $setup ) ) { |
478 | | - return $setup; |
479 | | - } |
480 | | - extract( $setup ); |
| 471 | + /** |
| 472 | + * MW 1.12 version of #lstx |
| 473 | + */ |
| 474 | + static function pfuncExcludeObj( $parser, $frame, $args ) { |
| 475 | + $setup = self::setupPfunc12( $parser, $frame, $args, 'lstx' ); |
| 476 | + if ( !is_array( $setup ) ) { |
| 477 | + return $setup; |
| 478 | + } |
| 479 | + extract( $setup ); |
481 | 480 | |
482 | | - $text = ''; |
483 | | - for ( $node = $root->getFirstChild(); $node; $node = $node ? $node->getNextSibling() : false ) { |
484 | | - // Search for the start tag |
485 | | - $found = false; |
486 | | - for ( ; $node; $node = $node->getNextSibling() ) { |
487 | | - if ( $node->getName() == 'ext' ) { |
488 | | - $parts = $node->splitExt(); |
489 | | - $parts = array_map( array( $newFrame, 'expand' ), $parts ); |
490 | | - if ( self::isSection( $parts['name'] ) ) { |
491 | | - if ( preg_match( $beginRegex, $parts['attr'] ) ) { |
492 | | - $found = true; |
493 | | - break; |
494 | | - } |
495 | | - $text .= self::expandSectionNode( $parser, $newFrame, $parts ); |
496 | | - } else { |
497 | | - $text .= $newFrame->expand( $node ); |
498 | | - } |
499 | | - } else { |
500 | | - $text .= $newFrame->expand( $node ); |
501 | | - } |
502 | | - } |
| 481 | + $text = ''; |
| 482 | + for ( $node = $root->getFirstChild(); $node; $node = $node ? $node->getNextSibling() : false ) { |
| 483 | + // Search for the start tag |
| 484 | + $found = false; |
| 485 | + for ( ; $node; $node = $node->getNextSibling() ) { |
| 486 | + if ( $node->getName() == 'ext' ) { |
| 487 | + $parts = $node->splitExt(); |
| 488 | + $parts = array_map( array( $newFrame, 'expand' ), $parts ); |
| 489 | + if ( self::isSection( $parts['name'] ) ) { |
| 490 | + if ( preg_match( $beginRegex, $parts['attr'] ) ) { |
| 491 | + $found = true; |
| 492 | + break; |
| 493 | + } |
| 494 | + $text .= self::expandSectionNode( $parser, $newFrame, $parts ); |
| 495 | + } else { |
| 496 | + $text .= $newFrame->expand( $node ); |
| 497 | + } |
| 498 | + } else { |
| 499 | + $text .= $newFrame->expand( $node ); |
| 500 | + } |
| 501 | + } |
503 | 502 | |
504 | | - if ( !$found ) { |
505 | | - break; |
506 | | - } |
| 503 | + if ( !$found ) { |
| 504 | + break; |
| 505 | + } |
507 | 506 | |
508 | | - // Append replacement text |
509 | | - $text .= $repl; |
| 507 | + // Append replacement text |
| 508 | + $text .= $repl; |
510 | 509 | |
511 | | - // Search for the end tag |
512 | | - for ( ; $node; $node = $node->getNextSibling() ) { |
513 | | - if ( $node->getName() == 'ext' ) { |
514 | | - $parts = $node->splitExt( $node ); |
515 | | - $parts = array_map( array( $newFrame, 'expand' ), $parts ); |
516 | | - if ( self::isSection( $parts['name'] ) ) { |
517 | | - if ( preg_match( $endRegex, $parts['attr'] ) ) { |
518 | | - $text .= self::expandSectionNode( $parser, $newFrame, $parts ); |
519 | | - break; |
520 | | - } |
521 | | - } |
522 | | - } |
523 | | - } |
524 | | - } |
525 | | - return $text; |
526 | | - } |
| 510 | + // Search for the end tag |
| 511 | + for ( ; $node; $node = $node->getNextSibling() ) { |
| 512 | + if ( $node->getName() == 'ext' ) { |
| 513 | + $parts = $node->splitExt( $node ); |
| 514 | + $parts = array_map( array( $newFrame, 'expand' ), $parts ); |
| 515 | + if ( self::isSection( $parts['name'] ) ) { |
| 516 | + if ( preg_match( $endRegex, $parts['attr'] ) ) { |
| 517 | + $text .= self::expandSectionNode( $parser, $newFrame, $parts ); |
| 518 | + break; |
| 519 | + } |
| 520 | + } |
| 521 | + } |
| 522 | + } |
| 523 | + } |
| 524 | + return $text; |
| 525 | + } |
527 | 526 | } |
528 | 527 | # vim: sw=2 sts=2 et : |
Index: trunk/extensions/LabeledSectionTransclusion/compat.php |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | /** |
5 | 5 | |
6 | 6 | This file contains compatability functions for other extensions which may |
7 | | -have called them, primarily DynamicPageList2. This file is not used by the |
| 7 | +have called them, primarily DynamicPageList2. This file is not used by the |
8 | 8 | Labeled Section Transclusion extension, but is provided to insulate other |
9 | 9 | extensions from code refactoring. |
10 | 10 | |
— | — | @@ -12,17 +12,17 @@ |
13 | 13 | /// Fetch the page to be transcluded from the database. |
14 | 14 | function wfLst_fetch_( $parser, $page, $ns = NS_MAIN ) |
15 | 15 | { |
16 | | - $title = Title::newFromText( $page, $ns ); |
17 | | - if ( !is_null( $title ) ) { |
18 | | - $text = $parser->fetchTemplate( $title ); |
19 | | - } |
20 | | - return $text; |
| 16 | + $title = Title::newFromText( $page, $ns ); |
| 17 | + if ( !is_null( $title ) ) { |
| 18 | + $text = $parser->fetchTemplate( $title ); |
| 19 | + } |
| 20 | + return $text; |
21 | 21 | } |
22 | 22 | |
23 | 23 | |
24 | 24 | function wfLstIncludeHeading2( $parser, $page = '', $sec = '', $to = '' ) |
25 | 25 | { |
26 | | - return wfLstIncludeHeading( $parser, $page, $sec, $to ); |
| 26 | + return wfLstIncludeHeading( $parser, $page, $sec, $to ); |
27 | 27 | } |
28 | 28 | |
29 | 29 | |