r81218 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81217‎ | r81218 | r81219 >
Date:22:25, 30 January 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Do not throw away, make all info available to handle parser functions and tag extensions separately, and have the option to just not care about the difference
Modified paths:
  • /trunk/extensions/Validator/Validator.php (modified) (history)
  • /trunk/extensions/Validator/includes/ParserHook.php (modified) (history)
  • /trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/Validator.php
@@ -24,7 +24,7 @@
2525 die( 'Not an entry point.' );
2626 }
2727
28 -define( 'Validator_VERSION', '0.4.3.1' );
 28+define( 'Validator_VERSION', '0.4.4 alpha' );
2929
3030 // Register the internationalization file.
3131 $wgExtensionMessagesFiles['Validator'] = dirname( __FILE__ ) . '/Validator.i18n.php';
Index: trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php
@@ -106,17 +106,8 @@
107107 }
108108 }
109109
110 - // Parse the wikitext to HTML.
111 - $output = $this->parser->parse(
112 - implode( "\n\n", $parts ),
113 - $this->parser->mTitle,
114 - $this->parser->mOptions,
115 - true,
116 - false
117 - );
118 -
119110 // This str_replace is a hack to allow for placing <pre>s into <pre>s, without breaking the outer ones.
120 - return str_replace( 'pre!&gt;', 'pre&gt;', $output->getText() );
 111+ return str_replace( 'pre!&gt;', 'pre&gt;', $this->parseWikitext( implode( "\n\n", $parts ) ) );
121112 }
122113
123114 /**
@@ -455,4 +446,4 @@
456447 return wfMsg( 'validator-describe-description' );
457448 }
458449
459 -}
\ No newline at end of file
 450+}
Index: trunk/extensions/Validator/includes/ParserHook.php
@@ -64,6 +64,20 @@
6565 protected $parser;
6666
6767 /**
 68+ * @since 0.4.4
 69+ *
 70+ * @var PPFrame
 71+ */
 72+ protected $frame;
 73+
 74+ /**
 75+ * @since 0.4.4
 76+ *
 77+ * @var ParserHook::TYPE_ enum item
 78+ */
 79+ protected $currentType;
 80+
 81+ /**
6882 * @since 0.4
6983 *
7084 * @var boolean
@@ -190,12 +204,13 @@
191205 * @param minxed $input string or null
192206 * @param array $args
193207 * @param Parser $parser
194 - * @param PPFrame $frame Available from 1.16 - commented out for bc for now
 208+ * @param PPFrame $frame Available from 1.16
195209 *
196210 * @return string
197211 */
198 - public function renderTag( $input, array $args, Parser $parser /*, PPFrame $frame*/ ) {
 212+ public function renderTag( $input, array $args, Parser $parser, PPFrame $frame = null ) {
199213 $this->parser = $parser;
 214+ $this->frame = $frame;
200215
201216 $defaultParam = array_shift( $this->getDefaultParameters( self::TYPE_TAG ) );
202217
@@ -409,6 +424,57 @@
410425 return false;
411426 }
412427
 428+ /**
 429+ * Returns if the current render request is comming from a tag extension.
 430+ *
 431+ * @since 0.4.4
 432+ *
 433+ * @return boolean
 434+ */
 435+ protected function isTag() {
 436+ return $this->currentType == self::TYPE_TAG;
 437+ }
 438+
 439+ /**
 440+ * Returns if the current render request is comming from a parser function.
 441+ *
 442+ * @since 0.4.4
 443+ *
 444+ * @return boolean
 445+ */
 446+ protected function isFunction() {
 447+ return $this->currentType == self::TYPE_FUNCTION;
 448+ }
 449+
 450+ /**
 451+ * Utility function to parse wikitext without having to care
 452+ * about handling a tag extension or parser function.
 453+ *
 454+ * @since 0.4.4
 455+ *
 456+ * @param string $text The wikitext to be parsed
 457+ *
 458+ * @return string the parsed output
 459+ */
 460+ protected function parseWikitext( $text ) {
 461+ // Parse the wikitext to HTML.
 462+ if ( $this->isFunction() ) {
 463+ return $this->parser->parse(
 464+ text,
 465+ $this->parser->mTitle,
 466+ $this->parser->mOptions,
 467+ true,
 468+ false
 469+ )->getText();
 470+ }
 471+ else {
 472+ return $this->parser->recursiveTagParse(
 473+ $text,
 474+ $this->frame
 475+ );
 476+ }
 477+ }
 478+
413479 }
414480
415481 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r81219Follow up to r81218jeroendedauw22:25, 30 January 2011

Status & tagging log