Index: trunk/phase3/maintenance/parserTests.inc |
— | — | @@ -442,11 +442,6 @@ |
443 | 443 | $user = new User(); |
444 | 444 | $options = ParserOptions::newFromUser( $user ); |
445 | 445 | |
446 | | - if ( isset( $opts['math'] ) ) { |
447 | | - # XXX this should probably be done by the ParserOptions |
448 | | - $options->setUseTex(true); |
449 | | - } |
450 | | - |
451 | 446 | $m = array(); |
452 | 447 | if (isset( $opts['title'] ) ) { |
453 | 448 | $titleText = $opts['title']; |
— | — | @@ -641,7 +636,8 @@ |
642 | 637 | 'wgNoFollowDomainExceptions' => array(), |
643 | 638 | 'wgThumbnailScriptPath' => false, |
644 | 639 | 'wgUseImageResize' => false, |
645 | | - 'wgUseTeX' => false, |
| 640 | + 'wgUseTeX' => isset( $opts['math'] ), |
| 641 | + 'wgMathDirectory' => $this->uploadDir . '/math', |
646 | 642 | 'wgLocaltimezone' => 'UTC', |
647 | 643 | 'wgAllowExternalImages' => true, |
648 | 644 | 'wgUseTidy' => false, |
— | — | @@ -689,8 +685,6 @@ |
690 | 686 | $GLOBALS['wgMemc'] = new FakeMemCachedClient; |
691 | 687 | $GLOBALS['wgOut'] = new OutputPage; |
692 | 688 | |
693 | | - //$GLOBALS['wgMessageCache'] = new MessageCache( new BagOStuff(), false, 0, $GLOBALS['wgDBname'] ); |
694 | | - |
695 | 689 | MagicWord::clearCache(); |
696 | 690 | |
697 | 691 | global $wgUser; |
— | — | @@ -848,6 +842,10 @@ |
849 | 843 | |
850 | 844 | # Reinitialise the LocalisationCache to match the database state |
851 | 845 | Language::getLocalisationCache()->unloadAll(); |
| 846 | + |
| 847 | + # Make a new message cache |
| 848 | + global $wgMessageCache, $wgMemc; |
| 849 | + $wgMessageCache = new MessageCache( $wgMemc, true, 3600, '' ); |
852 | 850 | } |
853 | 851 | |
854 | 852 | /** |
— | — | @@ -954,6 +952,8 @@ |
955 | 953 | "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg", |
956 | 954 | |
957 | 955 | "$dir/0/09/Bad.jpg", |
| 956 | + |
| 957 | + "$dir/math/f/a/5/fa50b8b616463173474302ca3e63586b.png", |
958 | 958 | ) |
959 | 959 | ); |
960 | 960 | |
— | — | @@ -969,8 +969,11 @@ |
970 | 970 | |
971 | 971 | "$dir/0/09/", |
972 | 972 | "$dir/0/", |
973 | | - |
974 | 973 | "$dir/thumb", |
| 974 | + "$dir/math/f/a/5", |
| 975 | + "$dir/math/f/a", |
| 976 | + "$dir/math/f", |
| 977 | + "$dir/math", |
975 | 978 | "$dir", |
976 | 979 | ) |
977 | 980 | ); |
— | — | @@ -1122,7 +1125,6 @@ |
1123 | 1126 | * @param int $line the input line number, for reporting errors |
1124 | 1127 | */ |
1125 | 1128 | private function addArticle($name, $text, $line) { |
1126 | | - global $wgMessageCache; |
1127 | 1129 | $this->setupGlobals(); |
1128 | 1130 | $title = Title::newFromText( $name ); |
1129 | 1131 | if ( is_null($title) ) { |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -129,7 +129,7 @@ |
130 | 130 | $this->mFunctionHooks = array(); |
131 | 131 | $this->mFunctionTagHooks = array(); |
132 | 132 | $this->mFunctionSynonyms = array( 0 => array(), 1 => array() ); |
133 | | - $this->mDefaultStripList = $this->mStripList = array( 'nowiki', 'gallery' ); |
| 133 | + $this->mDefaultStripList = $this->mStripList = array(); |
134 | 134 | $this->mUrlProtocols = wfUrlProtocols(); |
135 | 135 | $this->mExtLinkBracketedRegex = '/\[(\b(' . wfUrlProtocols() . ')'. |
136 | 136 | '[^][<>"\\x00-\\x20\\x7F]+) *([^\]\\x0a\\x0d]*?)\]/S'; |
— | — | @@ -172,8 +172,8 @@ |
173 | 173 | |
174 | 174 | wfProfileIn( __METHOD__ ); |
175 | 175 | |
176 | | - $this->setHook( 'pre', array( $this, 'renderPreTag' ) ); |
177 | 176 | CoreParserFunctions::register( $this ); |
| 177 | + CoreTagHooks::register( $this ); |
178 | 178 | $this->initialiseVariables(); |
179 | 179 | |
180 | 180 | wfRunHooks( 'ParserFirstCallInit', array( &$this ) ); |
— | — | @@ -614,15 +614,7 @@ |
615 | 615 | * Get a list of strippable XML-like elements |
616 | 616 | */ |
617 | 617 | function getStripList() { |
618 | | - global $wgRawHtml; |
619 | | - $elements = $this->mStripList; |
620 | | - if( $wgRawHtml ) { |
621 | | - $elements[] = 'html'; |
622 | | - } |
623 | | - if( $this->mOptions->getUseTeX() ) { |
624 | | - $elements[] = 'math'; |
625 | | - } |
626 | | - return $elements; |
| 618 | + return $this->mStripList; |
627 | 619 | } |
628 | 620 | |
629 | 621 | /** |
— | — | @@ -3282,59 +3274,48 @@ |
3283 | 3275 | $name = $frame->expand( $params['name'] ); |
3284 | 3276 | $attrText = !isset( $params['attr'] ) ? null : $frame->expand( $params['attr'] ); |
3285 | 3277 | $content = !isset( $params['inner'] ) ? null : $frame->expand( $params['inner'] ); |
3286 | | - |
3287 | 3278 | $marker = "{$this->mUniqPrefix}-$name-" . sprintf('%08X', $this->mMarkerIndex++) . self::MARKER_SUFFIX; |
3288 | 3279 | |
3289 | 3280 | $isFunctionTag = isset( $this->mFunctionTagHooks[strtolower($name)] ) && |
3290 | 3281 | ( $this->ot['html'] || $this->ot['pre'] ); |
| 3282 | + if ( $isFunctionTag ) { |
| 3283 | + $markerType = 'none'; |
| 3284 | + } else { |
| 3285 | + $markerType = 'general'; |
| 3286 | + } |
3291 | 3287 | if ( $this->ot['html'] || $isFunctionTag ) { |
3292 | 3288 | $name = strtolower( $name ); |
3293 | 3289 | $attributes = Sanitizer::decodeTagAttributes( $attrText ); |
3294 | 3290 | if ( isset( $params['attributes'] ) ) { |
3295 | 3291 | $attributes = $attributes + $params['attributes']; |
3296 | 3292 | } |
3297 | | - switch ( $name ) { |
3298 | | - case 'html': |
3299 | | - if( $wgRawHtml ) { |
3300 | | - $output = $content; |
3301 | | - break; |
3302 | | - } else { |
3303 | | - throw new MWException( '<html> extension tag encountered unexpectedly' ); |
3304 | | - } |
3305 | | - case 'nowiki': |
3306 | | - $content = strtr($content, array('-{' => '-{', '}-' => '}-')); |
3307 | | - $output = Xml::escapeTagsOnly( $content ); |
3308 | | - break; |
3309 | | - case 'gallery': |
3310 | | - $output = $this->renderImageGallery( $content, $attributes ); |
3311 | | - break; |
3312 | | - case 'math': |
3313 | | - if ( $this->mOptions->getUseTeX() ) { |
3314 | | - $output = $wgContLang->armourMath( |
3315 | | - MathRenderer::renderMath( $content, $attributes ) ); |
3316 | | - break; |
3317 | | - } |
3318 | | - /* else let a tag hook handle it (bug 21222) */ |
3319 | | - default: |
3320 | | - if( isset( $this->mTagHooks[$name] ) ) { |
3321 | | - # Workaround for PHP bug 35229 and similar |
3322 | | - if ( !is_callable( $this->mTagHooks[$name] ) ) { |
3323 | | - throw new MWException( "Tag hook for $name is not callable\n" ); |
3324 | | - } |
3325 | | - $output = call_user_func_array( $this->mTagHooks[$name], |
3326 | | - array( $content, $attributes, $this, $frame ) ); |
3327 | | - } elseif( isset( $this->mFunctionTagHooks[$name] ) ) { |
3328 | | - list( $callback, $flags ) = $this->mFunctionTagHooks[$name]; |
3329 | | - if( !is_callable( $callback ) ) |
3330 | | - throw new MWException( "Tag hook for $name is not callable\n" ); |
3331 | 3293 | |
3332 | | - $output = call_user_func_array( $callback, |
3333 | | - array( &$this, $frame, $content, $attributes ) ); |
3334 | | - } else { |
3335 | | - $output = '<span class="error">Invalid tag extension name: ' . |
3336 | | - htmlspecialchars( $name ) . '</span>'; |
3337 | | - } |
| 3294 | + if( isset( $this->mTagHooks[$name] ) ) { |
| 3295 | + # Workaround for PHP bug 35229 and similar |
| 3296 | + if ( !is_callable( $this->mTagHooks[$name] ) ) { |
| 3297 | + throw new MWException( "Tag hook for $name is not callable\n" ); |
| 3298 | + } |
| 3299 | + $output = call_user_func_array( $this->mTagHooks[$name], |
| 3300 | + array( $content, $attributes, $this, $frame ) ); |
| 3301 | + } elseif( isset( $this->mFunctionTagHooks[$name] ) ) { |
| 3302 | + list( $callback, $flags ) = $this->mFunctionTagHooks[$name]; |
| 3303 | + if( !is_callable( $callback ) ) |
| 3304 | + throw new MWException( "Tag hook for $name is not callable\n" ); |
| 3305 | + |
| 3306 | + $output = call_user_func_array( $callback, |
| 3307 | + array( &$this, $frame, $content, $attributes ) ); |
| 3308 | + } else { |
| 3309 | + $output = '<span class="error">Invalid tag extension name: ' . |
| 3310 | + htmlspecialchars( $name ) . '</span>'; |
3338 | 3311 | } |
| 3312 | + |
| 3313 | + if ( is_array( $output ) ) { |
| 3314 | + // Extract flags to local scope (to override $markerType) |
| 3315 | + $flags = $output; |
| 3316 | + $output = $flags[0]; |
| 3317 | + unset( $flags[0] ); |
| 3318 | + extract( $flags ); |
| 3319 | + } |
3339 | 3320 | } else { |
3340 | 3321 | if ( is_null( $attrText ) ) { |
3341 | 3322 | $attrText = ''; |
— | — | @@ -3353,12 +3334,14 @@ |
3354 | 3335 | } |
3355 | 3336 | } |
3356 | 3337 | |
3357 | | - if( $isFunctionTag ) { |
| 3338 | + if( $markerType === 'none' ) { |
3358 | 3339 | return $output; |
3359 | | - } elseif ( $name === 'html' || $name === 'nowiki' ) { |
| 3340 | + } elseif ( $markerType === 'nowiki' ) { |
3360 | 3341 | $this->mStripState->nowiki->setPair( $marker, $output ); |
3361 | | - } else { |
| 3342 | + } elseif ( $markerType === 'general' ) { |
3362 | 3343 | $this->mStripState->general->setPair( $marker, $output ); |
| 3344 | + } else { |
| 3345 | + throw new MWException( __METHOD__.': invalid marker type' ); |
3363 | 3346 | } |
3364 | 3347 | return $marker; |
3365 | 3348 | } |
— | — | @@ -4342,19 +4325,6 @@ |
4343 | 4326 | } |
4344 | 4327 | |
4345 | 4328 | /** |
4346 | | - * Tag hook handler for 'pre'. |
4347 | | - */ |
4348 | | - function renderPreTag( $text, $attribs ) { |
4349 | | - // Backwards-compatibility hack |
4350 | | - $content = StringUtils::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' ); |
4351 | | - |
4352 | | - $attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' ); |
4353 | | - return Xml::openElement( 'pre', $attribs ) . |
4354 | | - Xml::escapeTagsOnly( $content ) . |
4355 | | - '</pre>'; |
4356 | | - } |
4357 | | - |
4358 | | - /** |
4359 | 4329 | * Renders an image gallery from a text with one line per image. |
4360 | 4330 | * text labels may be given by using |-style alternative text. E.g. |
4361 | 4331 | * Image:one.jpg|The number "1" |
Index: trunk/phase3/includes/parser/CoreTagHooks.php |
— | — | @@ -0,0 +1,49 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class CoreTagHooks { |
| 5 | + static function register( $parser ) { |
| 6 | + global $wgRawHtml, $wgUseTeX; |
| 7 | + $parser->setHook( 'pre', array( __CLASS__, 'pre' ) ); |
| 8 | + $parser->setHook( 'nowiki', array( __CLASS__, 'nowiki' ) ); |
| 9 | + $parser->setHook( 'gallery', array( __CLASS__, 'gallery' ) ); |
| 10 | + if ( $wgRawHtml ) { |
| 11 | + $parser->setHook( 'html', array( __CLASS__, 'html' ) ); |
| 12 | + } |
| 13 | + if ( $wgUseTeX ) { |
| 14 | + $parser->setHook( 'math', array( __CLASS__, 'math' ) ); |
| 15 | + } |
| 16 | + } |
| 17 | + |
| 18 | + static function pre( $text, $attribs, $parser ) { |
| 19 | + // Backwards-compatibility hack |
| 20 | + $content = StringUtils::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' ); |
| 21 | + |
| 22 | + $attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' ); |
| 23 | + return Xml::openElement( 'pre', $attribs ) . |
| 24 | + Xml::escapeTagsOnly( $content ) . |
| 25 | + '</pre>'; |
| 26 | + } |
| 27 | + |
| 28 | + static function html( $content, $attributes, $parser ) { |
| 29 | + global $wgRawHtml; |
| 30 | + if( $wgRawHtml ) { |
| 31 | + return array( $content, 'markerType' => 'nowiki' ); |
| 32 | + } else { |
| 33 | + throw new MWException( '<html> extension tag encountered unexpectedly' ); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + static function nowiki( $content, $attributes, $parser ) { |
| 38 | + $content = strtr( $content, array( '-{' => '-{', '}-' => '}-' ) ); |
| 39 | + return array( Xml::escapeTagsOnly( $content ), 'markerType' => 'nowiki' ); |
| 40 | + } |
| 41 | + |
| 42 | + static function math( $content, $attributes, $parser ) { |
| 43 | + global $wgContLang; |
| 44 | + return $output = $wgContLang->armourMath( MathRenderer::renderMath( $content, $attributes ) ); |
| 45 | + } |
| 46 | + |
| 47 | + static function gallery( $content, $attributes, $parser ) { |
| 48 | + return $parser->renderImageGallery( $content, $attributes ); |
| 49 | + } |
| 50 | +} |
Property changes on: trunk/phase3/includes/parser/CoreTagHooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 51 | + native |
Index: trunk/phase3/includes/parser/ParserOptions.php |
— | — | @@ -7,7 +7,6 @@ |
8 | 8 | */ |
9 | 9 | class ParserOptions { |
10 | 10 | # All variables are supposed to be private in theory, although in practise this is not the case. |
11 | | - var $mUseTeX; # Use texvc to expand <math> tags |
12 | 11 | var $mUseDynamicDates; # Use DateFormatter to format dates |
13 | 12 | var $mInterwikiMagic; # Interlanguage links are removed and returned in an array |
14 | 13 | var $mAllowExternalImages; # Allow external images inline |
— | — | @@ -36,7 +35,6 @@ |
37 | 36 | var $mIsSectionPreview; # Parsing the page for a "preview" operation on a single section |
38 | 37 | var $mIsPrintable; # Parsing the printable version of the page |
39 | 38 | |
40 | | - function getUseTeX() { return $this->mUseTeX; } |
41 | 39 | function getUseDynamicDates() { return $this->mUseDynamicDates; } |
42 | 40 | function getInterwikiMagic() { return $this->mInterwikiMagic; } |
43 | 41 | function getAllowExternalImages() { return $this->mAllowExternalImages; } |
— | — | @@ -81,7 +79,6 @@ |
82 | 80 | return $this->mTimestamp; |
83 | 81 | } |
84 | 82 | |
85 | | - function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); } |
86 | 83 | function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); } |
87 | 84 | function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic, $x ); } |
88 | 85 | function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages, $x ); } |
— | — | @@ -122,7 +119,7 @@ |
123 | 120 | |
124 | 121 | /** Get user options */ |
125 | 122 | function initialiseFromUser( $userInput ) { |
126 | | - global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages; |
| 123 | + global $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages; |
127 | 124 | global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize; |
128 | 125 | global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures; |
129 | 126 | global $wgExternalLinkTarget; |
— | — | @@ -142,7 +139,6 @@ |
143 | 140 | |
144 | 141 | $this->mUser = $user; |
145 | 142 | |
146 | | - $this->mUseTeX = $wgUseTeX; |
147 | 143 | $this->mUseDynamicDates = $wgUseDynamicDates; |
148 | 144 | $this->mInterwikiMagic = $wgInterwikiMagic; |
149 | 145 | $this->mAllowExternalImages = $wgAllowExternalImages; |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -436,6 +436,7 @@ |
437 | 437 | # includes/parser |
438 | 438 | 'CoreLinkFunctions' => 'includes/parser/CoreLinkFunctions.php', |
439 | 439 | 'CoreParserFunctions' => 'includes/parser/CoreParserFunctions.php', |
| 440 | + 'CoreTagHooks' => 'includes/parser/CoreTagHooks.php', |
440 | 441 | 'DateFormatter' => 'includes/parser/DateFormatter.php', |
441 | 442 | 'LinkHolderArray' => 'includes/parser/LinkHolderArray.php', |
442 | 443 | 'LinkMarkerReplacer' => 'includes/parser/Parser_LinkHooks.php', |