Index: branches/conrad/phase3/maintenance/parserTests.inc |
— | — | @@ -366,6 +366,8 @@ |
367 | 367 | } elseif( isset( $opts['comment'] ) ) { |
368 | 368 | $linker = $user->getSkin(); |
369 | 369 | $out = $linker->formatComment( $input, $title, $local ); |
| 370 | + } elseif( isset( $opts['preload'] ) ) { |
| 371 | + $out = $parser->getpreloadText( $input, $title, $options ); |
370 | 372 | } else { |
371 | 373 | $output = $parser->parse( $input, $title, $options, true, true, 1337 ); |
372 | 374 | $out = $output->getText(); |
— | — | @@ -1716,4 +1718,4 @@ |
1717 | 1719 | } |
1718 | 1720 | return false; |
1719 | 1721 | } |
1720 | | -} |
\ No newline at end of file |
| 1722 | +} |
Index: branches/conrad/phase3/maintenance/parserTests.txt |
— | — | @@ -7879,7 +7879,46 @@ |
7880 | 7880 | </p> |
7881 | 7881 | !! end |
7882 | 7882 | |
| 7883 | +!! test |
| 7884 | +preload: check <noinclude> and <includeonly> |
| 7885 | +!! options |
| 7886 | +preload |
| 7887 | +!! input |
| 7888 | +Hello <noinclude>cruel</noinclude><includeonly>kind</includeonly> world. |
| 7889 | +!! result |
| 7890 | +Hello kind world. |
| 7891 | +!! end |
7883 | 7892 | |
| 7893 | +!! test |
| 7894 | +preload: check <onlyinclude> |
| 7895 | +!! options |
| 7896 | +preload |
| 7897 | +!! input |
| 7898 | +Goodbye <onlyinclude>Hello world</onlyinclude> |
| 7899 | +!! result |
| 7900 | +Hello world |
| 7901 | +!! end |
| 7902 | + |
| 7903 | +!! test |
| 7904 | +preload: can pass tags through if we want to |
| 7905 | +!! options |
| 7906 | +preload |
| 7907 | +!! input |
| 7908 | +<includeonly><</includeonly>includeonly>Hello world<includeonly><</includeonly>/includeonly> |
| 7909 | +!! result |
| 7910 | +<includeonly>Hello world</includeonly> |
| 7911 | +!! end |
| 7912 | + |
| 7913 | +!! test |
| 7914 | +preload: check that it doesn't try to do tricks |
| 7915 | +!! options |
| 7916 | +preload |
| 7917 | +!! input |
| 7918 | +* <!-- Hello --> ''{{world}}'' {{<includeonly>subst:</includeonly>How are you}}{{ {{{|safesubst:}}} #if:1|2|3}} |
| 7919 | +!! result |
| 7920 | +* <!-- Hello --> ''{{world}}'' {{subst:How are you}}{{ {{{|safesubst:}}} #if:1|2|3}} |
| 7921 | +!! end |
| 7922 | + |
7884 | 7923 | TODO: |
7885 | 7924 | more images |
7886 | 7925 | more tables |
Index: branches/conrad/phase3/includes/Defines.php |
— | — | @@ -209,8 +209,7 @@ |
210 | 210 | define( 'OT_WIKI', 2 ); |
211 | 211 | define( 'OT_PREPROCESS', 3 ); |
212 | 212 | define( 'OT_MSG' , 3 ); // b/c alias for OT_PREPROCESS |
213 | | -define( 'OT_INCLUDES', 4); |
214 | | -define( 'OT_EXTRACT', 5); |
| 213 | +define( 'OT_PLAIN', 4); |
215 | 214 | |
216 | 215 | # Flags for Parser::setFunctionHook |
217 | 216 | define( 'SFH_NO_HASH', 1 ); |
Index: branches/conrad/phase3/includes/parser/Parser.php |
— | — | @@ -26,8 +26,8 @@ |
27 | 27 | * Cleans a signature before saving it to preferences |
28 | 28 | * extractSections() |
29 | 29 | * Extracts sections from an article for section editing |
30 | | - * getTransclusionText() |
31 | | - * Extracts the text of a template with only <includeonly>, etc., parsed |
| 30 | + * getPreloadText() |
| 31 | + * Removes <noinclude> sections, and <includeonly> tags. |
32 | 32 | * |
33 | 33 | * Globals used: |
34 | 34 | * objects: $wgLang, $wgContLang |
— | — | @@ -84,10 +84,8 @@ |
85 | 85 | const OT_WIKI = 2; // like preSaveTransform() |
86 | 86 | const OT_PREPROCESS = 3; // like preprocess() |
87 | 87 | const OT_MSG = 3; |
| 88 | + const OT_PLAIN = 4; // like extractSections() - portions of the original are returned unchanged. |
88 | 89 | |
89 | | - const OT_INCLUDES = 4; // like getTransclusionText() - actually a NO-OP all features use the preprocessor flags |
90 | | - const OT_EXTRACT = 5; // like extractSections() - should behaviour be needed later on, these flags will then work. |
91 | | - |
92 | 90 | // Marker Suffix needs to be accessible staticly. |
93 | 91 | const MARKER_SUFFIX = "-QINU\x7f"; |
94 | 92 | |
— | — | @@ -254,8 +252,7 @@ |
255 | 253 | 'html' => $ot == self::OT_HTML, |
256 | 254 | 'wiki' => $ot == self::OT_WIKI, |
257 | 255 | 'pre' => $ot == self::OT_PREPROCESS, |
258 | | - 'includes' => $ot == self::OT_INCLUDES, |
259 | | - 'extract' => $ot == self::OT_EXTRACT, |
| 256 | + 'plain' => $ot == self::OT_PLAIN, |
260 | 257 | ); |
261 | 258 | } |
262 | 259 | |
— | — | @@ -502,23 +499,21 @@ |
503 | 500 | } |
504 | 501 | |
505 | 502 | /** |
506 | | - * Get the wikitext of a page as though it was transcluded. |
| 503 | + * Process the wikitext for the ?preload= feature. (bug 5210) |
507 | 504 | * |
508 | | - * Specifically <includeonly> etc. are parsed, redirects are followed, comments |
509 | | - * are removed, but templates arguments and parser functions are untouched. |
510 | | - * |
511 | | - * This is not called by the parser itself, see braceSubstitution for its transclusion. |
| 505 | + * <noinclude>, <includeonly> etc. are parsed as for template transclusion, |
| 506 | + * comments, templates, arguments, tags hooks and parser functions are untouched. |
512 | 507 | */ |
513 | | - public function getTransclusionText( $title, $options ) { |
514 | | - // Must initialize first |
| 508 | + public function getPreloadText( $text, $title, $options ) { |
| 509 | + // Parser (re)initialisation |
515 | 510 | $this->clearState(); |
516 | | - $this->setOutputType( self::OT_INCLUDES ); |
| 511 | + $this->setOutputType( self::OT_PLAIN ); |
517 | 512 | $this->mOptions = $options; |
518 | | - $this->setTitle( new FakeTitle ); |
| 513 | + $this->setTitle( $title ); |
519 | 514 | |
520 | | - list( $text, $title ) = $this->getTemplateDom( $title ); |
521 | 515 | $flags = PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES; |
522 | | - return $this->getPreprocessor()->newFrame()->expand( $text, $flags ); |
| 516 | + $dom = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION ); |
| 517 | + return $this->getPreprocessor()->newFrame()->expand( $dom, $flags ); |
523 | 518 | } |
524 | 519 | |
525 | 520 | /** |
— | — | @@ -4808,10 +4803,11 @@ |
4809 | 4804 | * for "replace", the whole page with the section replaced. |
4810 | 4805 | */ |
4811 | 4806 | private function extractSections( $text, $section, $mode, $newText='' ) { |
| 4807 | + global $wgTitle; |
4812 | 4808 | $this->clearState(); |
4813 | | - $this->setTitle( new FakeTitle ); |
| 4809 | + $this->setTitle( $wgTitle ); // just a placeholder. |
4814 | 4810 | $this->mOptions = new ParserOptions; |
4815 | | - $this->setOutputType( self::OT_EXTRACT ); |
| 4811 | + $this->setOutputType( self::OT_PLAIN ); |
4816 | 4812 | $outText = ''; |
4817 | 4813 | $frame = $this->getPreprocessor()->newFrame(); |
4818 | 4814 | |
Index: branches/conrad/phase3/includes/EditPage.php |
— | — | @@ -231,11 +231,22 @@ |
232 | 232 | if ( !empty( $this->mPreloadText ) ) { |
233 | 233 | return $this->mPreloadText; |
234 | 234 | } else { |
235 | | - $preloadTitle = Title::newFromText( $preload ); |
236 | | - if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) { |
237 | | - return $wgParser->getTransclusionText( $preloadTitle, ParserOptions::newFromUser( $wgUser ) ); |
| 235 | + $title = Title::newFromText( $preload ); |
| 236 | + # Check for existence to avoid getting MediaWiki:Noarticletext |
| 237 | + if ( isset( $title ) && $title->exists() && $title->userCanRead() ) { |
| 238 | + $article = new Article( $title ); |
| 239 | + |
| 240 | + if ( $article->isRedirect() ) { |
| 241 | + $title = Title::newFromRedirectRecurse( $article->getContent() ); |
| 242 | + if ( $title->exists() && $title->userCanRead() ) { |
| 243 | + $article = new Article( $title ); |
| 244 | + } |
| 245 | + } |
| 246 | + $parserOptions = ParserOptions::newFromUser( $wgUser ); |
| 247 | + return $wgParser->getPreloadText( $article->getContent(), $title, $parserOptions ); |
238 | 248 | } |
239 | 249 | } |
| 250 | + return ""; |
240 | 251 | } |
241 | 252 | |
242 | 253 | /** |