r36671 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36670‎ | r36671 | r36672 >
Date:13:08, 26 June 2008
Author:daniel
Status:old
Tags:
Comment:
factoring out variable replacement logic. tweaked output for some cases.
Modified paths:
  • /trunk/extensions/News/NewsRenderer.php (modified) (history)

Diff [purge]

Index: trunk/extensions/News/NewsRenderer.php
@@ -444,7 +444,7 @@
445445
446446 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title ); //XXX: this is redundant, we already have a title object in renderRow. But no good way to pass it :(
447447
448 - if ($this->publication) {
 448+ if ( $this->publication || $row->rc_new ) {
449449 $name = $title->getPrefixedText();
450450 }
451451 else {
@@ -541,18 +541,38 @@
542542 // and extension tags from templates are stripped properly
543543 // this doesn't work though: $t = $this->templateparser->preprocess( $t, $this->title, new ParserOptions() );
544544 //TODO: avoid magic categories, interwiki-links, etc
545 - $params['content'] = NewsRenderer::sanitizeWikiText( $t );
 545+ $params['content'] = NewsRenderer::sanitizeWikiText( $t, $this->templateparser );
546546
547547 if ( stripos($templatetext, '{{{head}}}')!==false ) {
548548 $params['head'] = NewsRenderer::extractHead( $params['content'], $title );
549549 }
550550 }
551551
552 - $text = $this->templateparser->replaceVariables( $templatetext, $params );
 552+ $text = NewsRenderer::replaceVariables( $this->templateparser, $templatetext, $params, $this->title );
553553 return $text;
554554 }
555555 }
556556
 557+ static function replaceVariables($parser, $text, $params = NULL, $title = NULL) {
 558+ global $wgVersion;
 559+
 560+ if ( $params === NULL ) $params = array();
 561+ $text = $parser->replaceVariables( $text, $params );
 562+
 563+ /*
 564+ if ( version_compare( $wgVersion, "1.12", '<' ) ) {
 565+ }
 566+ else {
 567+ $parser = $GLOBALS['wgParser'];
 568+
 569+ $frame = $parser->getPreprocessor()->newCustomFrame($params);
 570+ $text = $parser->replaceVariables( $text, $frame );
 571+ }
 572+ */
 573+
 574+ return $text;
 575+ }
 576+
557577 /*
558578 function renderFeedMetaLink( $format ) {
559579 $format = strtolower(trim($format));
@@ -594,7 +614,7 @@
595615
596616 static function renderFeedLink( $text, $argv, &$parser ) {
597617 $t = @$argv['feed'];
598 - if ($t) $t = $parser->replaceVariables($t, array());
 618+ if ($t) $t = NewsRenderer::replaceVariables( $parser, $t );
599619
600620 $title = $t === NULL ? NULL : Title::newFromText($t);
601621 if (!$title) $title = $GLOBALS['wgTitle'];
@@ -628,7 +648,7 @@
629649 $url = NewsRenderer::getFeedURL($title, $format);
630650
631651 $ttl = @$argv['title'];
632 - if ($ttl) $ttl = $parser->replaceVariables($ttl, array());
 652+ if ($ttl) $ttl = NewsRenderer::replaceVariables( $parser, $ttl );
633653
634654 $s = '';
635655 if ($text) {
@@ -664,14 +684,14 @@
665685 return $row[0];
666686 }
667687
668 - static function sanitizeWikiText( $text ) {
669 - global $wgParser;
 688+ static function sanitizeWikiText( $text, $parser = NULL ) {
 689+ if ( !$parser ) $parser = $GLOBALS['wgParser'];
670690
671 - $elements = array_keys( $wgParser->mTagHooks );
 691+ $elements = array_keys( $parser->mTagHooks );
672692 $uniq_prefix = "\x07NR-UNIQ";
673693
674694 $matches = array();
675 - $text = Parser::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix );
 695+ $text = $parser->extractTagsAndParams( $elements, $text, $matches, $uniq_prefix );
676696
677697 foreach( $matches as $marker => $data ) {
678698 list( $element, $content, $params, $tag ) = $data;

Status & tagging log