r64964 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64963‎ | r64964 | r64965 >
Date:17:15, 12 April 2010
Author:than4213
Status:deferred
Tags:
Comment:
Decided to make an extension for the ParseEngine instead of rewriting the parser.
Modified paths:
  • /branches/parser-work/phase3/includes/AutoLoader.php (modified) (history)
  • /branches/parser-work/phase3/includes/DefaultSettings.php (modified) (history)
  • /branches/parser-work/phase3/includes/parser/ParseEngine.php (modified) (history)
  • /branches/parser-work/phase3/includes/parser/Parser.php (modified) (history)
  • /branches/parser-work/phase3/includes/parser/WikiTextGrammar.xml (modified) (history)

Diff [purge]

Index: branches/parser-work/phase3/includes/parser/Parser.php
@@ -2788,17 +2788,6 @@
27892789 $this->addTrackingCategory( "$limitationType-category" );
27902790 }
27912791
2792 - function transformParseDom($inNode) {
2793 - if ($inNode->nodeName == "newLine") {
2794 - $inNode->setAttribute("tag", "\n");
2795 - }
2796 - foreach ($inNode->childNodes as $child) {
2797 - if ($child instanceof DOMElement) {
2798 - $this->transformParseDom($child);
2799 - }
2800 - }
2801 - }
2802 -
28032792 /**
28042793 * Return the text of a template, after recursively
28052794 * replacing any variables or templates within the template.
@@ -3976,19 +3965,23 @@
39773966 * @param Title &$title the Title object for the current article
39783967 * @param User $user the User object describing the current user
39793968 * @param ParserOptions $options parsing options
 3969+ * @param bool $clearState whether to clear the parser state first
39803970 * @return string the altered wiki markup
39813971 * @public
39823972 */
3983 - function preSaveTransform( $text, Title $title, $user, $options ) {
 3973+ function preSaveTransform( $text, Title $title, $user, $options, $clearState = true ) {
39843974 $this->mOptions = $options;
39853975 $this->setTitle( $title );
39863976 $this->setOutputType( self::OT_WIKI );
3987 - $this->clearState();
39883977
3989 - $parser = new ParseEngine("includes/parser/WikiTextGrammar.xml");
3990 - $dom = $parser->parse($text);
3991 - $this->transformParseDom($dom->documentElement);
3992 - $text = ParseEngine::unparse($dom->documentElement);
 3978+ if ( $clearState ) {
 3979+ $this->clearState();
 3980+ }
 3981+
 3982+ $pairs = array(
 3983+ "\r\n" => "\n",
 3984+ );
 3985+ $text = str_replace( array_keys( $pairs ), array_values( $pairs ), $text );
39933986 $text = $this->pstPass2( $text, $user );
39943987 $text = $this->mStripState->unstripBoth( $text );
39953988 return $text;
Index: branches/parser-work/phase3/includes/parser/ParseEngine.php
@@ -43,13 +43,13 @@
4444 return $doc;
4545 }
4646
47 - static function unparse($inNode) {
48 - $retStr = "" . $inNode->getAttribute("tag");
49 - foreach ($inNode->childNodes as $child) {
 47+ static function unparse($inNodes) {
 48+ $retStr = "";
 49+ foreach ($inNodes as $child) {
5050 if ($child instanceof DOMText) {
5151 $retStr .= $child->data;
5252 } else {
53 - $retStr .= self::unparse($child);
 53+ $retStr .= $child->getAttribute("tag") . self::unparse($child->childNodes);
5454 }
5555 }
5656 return $retStr;
Index: branches/parser-work/phase3/includes/parser/WikiTextGrammar.xml
@@ -27,6 +27,11 @@
2828 <Assignment tagName="template" tag="{{">
2929 <Sequence>
3030 <Reference name="name" />
 31+ <Choice failSafe="true">
 32+ <Assignment tagName="name2" tag=":">
 33+ <Reference name="main" />
 34+ </Assignment>
 35+ </Choice>
3136 <Reference name="partList" />
3237 <Assignment tagName="endTag" tag="}}" />
3338 </Sequence>
Index: branches/parser-work/phase3/includes/AutoLoader.php
@@ -463,7 +463,6 @@
464464 'PPNode_Hash_Tree' => 'includes/parser/Preprocessor_Hash.php',
465465 'PPTemplateFrame_DOM' => 'includes/parser/Preprocessor_DOM.php',
466466 'PPTemplateFrame_Hash' => 'includes/parser/Preprocessor_Hash.php',
467 - 'ParseEngine' => 'includes/parser/ParseEngine.php',
468467 'Parser' => 'includes/parser/Parser.php',
469468 'ParserCache' => 'includes/parser/ParserCache.php',
470469 'ParserOptions' => 'includes/parser/ParserOptions.php',
Index: branches/parser-work/phase3/includes/DefaultSettings.php
@@ -1229,11 +1229,6 @@
12301230 $wgDebugPrintHttpHeaders = true;
12311231
12321232 /**
1233 - * Log file for debugging the parser, if not set log won't be created
1234 - */
1235 -$wgDebugParserLog = '';
1236 -
1237 -/**
12381233 * Show the contents of $wgHooks in Special:Version
12391234 */
12401235 $wgSpecialVersionShowHooks = false;

Status & tagging log