r95343 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95342‎ | r95343 | r95344 >
Date:22:14, 23 August 2011
Author:johnduhart
Status:ok (Comments)
Tags:
Comment:
(bug 24037) Allow transclusion from the beginning of the page to a certain section. Patch by Beau
Modified paths:
  • /trunk/extensions/LabeledSectionTransclusion/lst.php (modified) (history)
  • /trunk/extensions/LabeledSectionTransclusion/lstParserTests.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/LabeledSectionTransclusion/lstParserTests.txt
@@ -391,3 +391,45 @@
392392 <p>junk
393393 </p>
394394 !!end
 395+
 396+!!article
 397+fromsection
 398+!!text
 399+Before...
 400+<section begin="A"/>SectionA<section end="A"/>
 401+<section begin="B"/>SectionB<section end="B"/>
 402+<section begin="C"/>SectionC<section end="C"/>
 403+...After
 404+!!endarticle
 405+!!test
 406+LST: inclusion starting at a specified section till the end of article
 407+!!options
 408+!!input
 409+{{#lst:fromsection|B|}}
 410+!!result
 411+<p>SectionB
 412+SectionC
 413+...After
 414+</p>
 415+!!end
 416+
 417+!!article
 418+tosection
 419+!!text
 420+Before...
 421+<section begin="A"/>SectionA<section end="A"/>
 422+<section begin="B"/>SectionB<section end="B"/>
 423+<section begin="C"/>SectionC<section end="C"/>
 424+...After
 425+!!endarticle
 426+!!test
 427+LST: inclusion from beginning of article to a specified section
 428+!!options
 429+!!input
 430+{{#lst:tosection||B}}
 431+!!result
 432+<p>Before...
 433+SectionA
 434+SectionB
 435+</p>
 436+!!end
Index: trunk/extensions/LabeledSectionTransclusion/lst.php
@@ -322,7 +322,7 @@
323323 $endAttr = self::getAttrPattern_( $end, 'end' );
324324 $endRegex = "/^$endAttr$/s";
325325
326 - return compact( 'dom', 'root', 'newFrame', 'repl', 'beginRegex', 'endRegex' );
 326+ return compact( 'dom', 'root', 'newFrame', 'repl', 'beginRegex', 'begin', 'endRegex' );
327327 }
328328
329329 /**
@@ -359,24 +359,28 @@
360360 $text = '';
361361 $node = $root->getFirstChild();
362362 while ( $node ) {
363 - // Find the begin node
364 - $found = false;
365 - for ( ; $node; $node = $node->getNextSibling() ) {
366 - if ( $node->getName() != 'ext' ) {
367 - continue;
368 - }
369 - $parts = $node->splitExt();
370 - $parts = array_map( array( $newFrame, 'expand' ), $parts );
371 - if ( self::isSection( $parts['name'] ) ) {
372 - if ( preg_match( $beginRegex, $parts['attr'] ) ) {
373 - $found = true;
374 - break;
 363+ // If name of begin node was specified find it
 364+ // otherwise transclude everything from the beginning of the page
 365+ if ( $begin != '' ) {
 366+ // Find the begin node
 367+ $found = false;
 368+ for ( ; $node; $node = $node->getNextSibling() ) {
 369+ if ( $node->getName() != 'ext' ) {
 370+ continue;
375371 }
 372+ $parts = $node->splitExt();
 373+ $parts = array_map( array( $newFrame, 'expand' ), $parts );
 374+ if ( self::isSection( $parts['name'] ) ) {
 375+ if ( preg_match( $beginRegex, $parts['attr'] ) ) {
 376+ $found = true;
 377+ break;
 378+ }
 379+ }
376380 }
 381+ if ( !$found || !$node ) {
 382+ break;
 383+ }
377384 }
378 - if ( !$found || !$node ) {
379 - break;
380 - }
381385
382386 // Write the text out while looking for the end node
383387 $found = false;
@@ -399,7 +403,13 @@
400404 }
401405 if ( !$found ) {
402406 break;
 407+ } else if ( $begin == '' ) {
 408+ // When end node was found and
 409+ // text is transcluded from the beginning of the page
 410+ // finish the transclusion
 411+ break;
403412 }
 413+
404414 $node = $node->getNextSibling();
405415 }
406416 return $text;

Follow-up revisions

RevisionCommit summaryAuthorDate
r95345Follow-up r95343, else if->elseifjohnduhart22:24, 23 August 2011
r107784Fix comments from r95343tstarling22:31, 1 January 2012
r112183release-notes-1.19...krinkle02:43, 23 February 2012

Comments

#Comment by Catrope (talk | contribs)   20:56, 5 September 2011

Bug number seems to be wrong.

#Comment by Tim Starling (talk | contribs)   22:33, 1 January 2012

It's actually bug 23407.

Status & tagging log