r40485 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40484‎ | r40485 | r40486 >
Date:13:35, 5 September 2008
Author:mkroetzsch
Status:old
Tags:
Comment:
Improved behaviour for generating templated output when called outside parsing (i.e. when $wgParser has no
Title set). Possible recursion is stopped after two steps in any case.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php
@@ -82,8 +82,19 @@
8383 *
8484 * For outputs SMW_OUTPUT_WIKI and SMW_OUTPUT_HTML, error messages or standard "further results" links
8585 * are directly generated and appended. For SMW_OUTPUT_FILE, only the plain generated text is returned.
 86+ *
 87+ * @note A note on recursion: some query printers may return wiki code that comes from other pages,
 88+ * e.g. from templates that are used in formatting or from embedded result pages. Both kinds of pages
 89+ * may contain \#ask queries that do again use new pages, so we must care about recursion. We do so
 90+ * by simply counting how often this method starts a subparse and stopping at depth 2. There is one
 91+ * special case: if this method is called outside parsing, and the concrete printer returns wiki text,
 92+ * and wiki text is requested, then we may return wiki text with sub-queries to the caller. If the
 93+ * caller parses this (which is likely) then this will again call us in parse-context and all recursion
 94+ * checks catch. Only the first level of parsing is done outside and thus not counted. Thus you
 95+ * effectively can get down to level 3.
8696 */
8797 public function getResult($results, $params, $outputmode) {
 98+ global $wgParser;
8899 $this->isHTML = false;
89100 $this->hasTemplates = false;
90101 $this->readParameters($params,$outputmode);
@@ -118,27 +129,37 @@
119130 }
120131 $result .= $this->getErrorString($results); // append errors
121132 if ( (!$this->isHTML) && ($this->hasTemplates) ) { // preprocess embedded templates if needed
122 - global $wgParser;
123 - SMWResultPrinter::$mRecursionDepth++;
124 - if (SMWResultPrinter::$mRecursionDepth <= 2) { // restrict recursion
125 - $result = '[[SMW::off]]' . $wgParser->replaceVariables($result) . '[[SMW::on]]';
 133+ if ( ($wgParser->getTitle() instanceof Title) && ($wgParser->getOptions() instanceof ParserOptions) ) {
 134+ SMWResultPrinter::$mRecursionDepth++;
 135+ if (SMWResultPrinter::$mRecursionDepth <= 2) { // restrict recursion
 136+ $result = '[[SMW::off]]' . $wgParser->replaceVariables($result) . '[[SMW::on]]';
 137+ } else {
 138+ $result = ''; /// TODO: explain problem (too much recursive parses)
 139+ }
 140+ SMWResultPrinter::$mRecursionDepth--;
 141+ } else { // not during parsing, no preprocessing needed, still protect the result
 142+ $result = '[[SMW::off]]' . $result . '[[SMW::on]]';
126143 }
127 - SMWResultPrinter::$mRecursionDepth--;
128144 }
129145
130146 if ( ($this->isHTML) && ($outputmode == SMW_OUTPUT_WIKI) ) {
131147 $result = array($result, 'isHTML' => true);
132148 } elseif ( (!$this->isHTML) && ($outputmode == SMW_OUTPUT_HTML) ) {
133 - global $wgParser;
 149+ SMWResultPrinter::$mRecursionDepth++;
134150 // check whether we are in an existing parse, or if we should start a new parse for $wgTitle
135 - if ( ($wgParser->getTitle() instanceof Title) && ($wgParser->getOptions() instanceof ParserOptions) ) {
136 - $result = $wgParser->recursiveTagParse($result);
 151+ if (SMWResultPrinter::$mRecursionDepth <= 2) { // retrict recursion
 152+ if ( ($wgParser->getTitle() instanceof Title) && ($wgParser->getOptions() instanceof ParserOptions) ) {
 153+ $result = $wgParser->recursiveTagParse($result);
 154+ } else {
 155+ global $wgTitle;
 156+ $popt = new ParserOptions();
 157+ $pout = $wgParser->parse($result, $wgTitle, $popt);
 158+ $result = $pout->getText();
 159+ }
137160 } else {
138 - global $wgTitle;
139 - $popt = new ParserOptions();
140 - $pout = $wgParser->parse($result, $wgTitle, $popt);
141 - $result = $pout->getText();
 161+ $result = ''; /// TODO: explain problem (too much recursive parses)
142162 }
 163+ SMWResultPrinter::$mRecursionDepth--;
143164 }
144165
145166 if ( ($this->mIntro) && ($results->getCount() > 0) ) {

Status & tagging log