Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -220,30 +220,39 @@ |
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | | - * Get the contents of a page from its title and remove includeonly tags |
| 224 | + * Get the contents to be preloaded into the box, either set by |
| 225 | + * an earlier setPreloadText() or by loading the given page. |
225 | 226 | * |
226 | | - * @param $preload String: the title of the page. |
227 | | - * @return string The contents of the page. |
| 227 | + * @param $preload String: representing the title to preload from. |
| 228 | + * @return String |
228 | 229 | */ |
229 | 230 | protected function getPreloadedText( $preload ) { |
| 231 | + global $wgUser, $wgParser; |
230 | 232 | if ( !empty( $this->mPreloadText ) ) { |
231 | 233 | return $this->mPreloadText; |
232 | | - } elseif ( $preload === '' ) { |
233 | | - return ''; |
234 | | - } else { |
235 | | - $preloadTitle = Title::newFromText( $preload ); |
236 | | - if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) { |
237 | | - $rev = Revision::newFromTitle( $preloadTitle ); |
238 | | - if ( is_object( $rev ) ) { |
239 | | - $text = $rev->getText(); |
240 | | - // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing |
241 | | - // its own mini-parser! -ævar |
242 | | - $text = preg_replace( '~</?includeonly>~', '', $text ); |
243 | | - return $text; |
244 | | - } else |
245 | | - return ''; |
| 234 | + } elseif ( $preload !== '' ) { |
| 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 | + # Redirects to missing titles are displayed, to hidden pages are followed |
| 243 | + # Copying observed behaviour from ?action=view |
| 244 | + if ( $title->exists() ) { |
| 245 | + if ($title->userCanRead() ) { |
| 246 | + $article = new Article( $title ); |
| 247 | + } else { |
| 248 | + return ""; |
| 249 | + } |
| 250 | + } |
| 251 | + } |
| 252 | + $parserOptions = ParserOptions::newFromUser( $wgUser ); |
| 253 | + return $wgParser->getPreloadText( $article->getContent(), $title, $parserOptions ); |
246 | 254 | } |
247 | 255 | } |
| 256 | + return ''; |
248 | 257 | } |
249 | 258 | |
250 | 259 | /* |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -26,6 +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 | + * getPreloadText() |
| 31 | + * Removes <noinclude> sections, and <includeonly> tags. |
30 | 32 | * |
31 | 33 | * Globals used: |
32 | 34 | * objects: $wgLang, $wgContLang |
— | — | @@ -78,10 +80,11 @@ |
79 | 81 | |
80 | 82 | // Allowed values for $this->mOutputType |
81 | 83 | // Parameter to startExternalParse(). |
82 | | - const OT_HTML = 1; |
83 | | - const OT_WIKI = 2; |
84 | | - const OT_PREPROCESS = 3; |
| 84 | + const OT_HTML = 1; // like parse() |
| 85 | + const OT_WIKI = 2; // like preSaveTransform() |
| 86 | + const OT_PREPROCESS = 3; // like preprocess() |
85 | 87 | const OT_MSG = 3; |
| 88 | + const OT_PLAIN = 4; // like extractSections() - portions of the original are returned unchanged. |
86 | 89 | |
87 | 90 | // Marker Suffix needs to be accessible staticly. |
88 | 91 | const MARKER_SUFFIX = "-QINU\x7f"; |
— | — | @@ -249,6 +252,7 @@ |
250 | 253 | 'html' => $ot == self::OT_HTML, |
251 | 254 | 'wiki' => $ot == self::OT_WIKI, |
252 | 255 | 'pre' => $ot == self::OT_PREPROCESS, |
| 256 | + 'plain' => $ot == self::OT_PLAIN, |
253 | 257 | ); |
254 | 258 | } |
255 | 259 | |
— | — | @@ -489,6 +493,24 @@ |
490 | 494 | } |
491 | 495 | |
492 | 496 | /** |
| 497 | + * Process the wikitext for the ?preload= feature. (bug 5210) |
| 498 | + * |
| 499 | + * <noinclude>, <includeonly> etc. are parsed as for template transclusion, |
| 500 | + * comments, templates, arguments, tags hooks and parser functions are untouched. |
| 501 | + */ |
| 502 | + public function getPreloadText( $text, $title, $options ) { |
| 503 | + // Parser (re)initialisation |
| 504 | + $this->clearState(); |
| 505 | + $this->setOutputType( self::OT_PLAIN ); |
| 506 | + $this->mOptions = $options; |
| 507 | + $this->setTitle( $title ); |
| 508 | + |
| 509 | + $flags = PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES; |
| 510 | + $dom = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION ); |
| 511 | + return $this->getPreprocessor()->newFrame()->expand( $dom, $flags ); |
| 512 | + } |
| 513 | + |
| 514 | + /** |
493 | 515 | * Get a random string |
494 | 516 | * |
495 | 517 | * @private |
— | — | @@ -4741,7 +4763,7 @@ |
4742 | 4764 | $this->clearState(); |
4743 | 4765 | $this->setTitle( $wgTitle ); // not generally used but removes an ugly failure mode |
4744 | 4766 | $this->mOptions = new ParserOptions; |
4745 | | - $this->setOutputType( self::OT_WIKI ); |
| 4767 | + $this->setOutputType( self::OT_PLAIN ); |
4746 | 4768 | $outText = ''; |
4747 | 4769 | $frame = $this->getPreprocessor()->newFrame(); |
4748 | 4770 | |
Index: trunk/phase3/includes/Defines.php |
— | — | @@ -209,6 +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_PLAIN', 4 ); |
213 | 214 | |
214 | 215 | # Flags for Parser::setFunctionHook |
215 | 216 | define( 'SFH_NO_HASH', 1 ); |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -30,6 +30,7 @@ |
31 | 31 | * (bug 22606) The body of e-mail address confirmation message is now different |
32 | 32 | when the address changed |
33 | 33 | * (bug 22664) Special:Userrights now accepts '0' as a valid user name |
| 34 | +* (bug 5210) preload parser now parses <noinclude>, <includeonly> and redirects |
34 | 35 | |
35 | 36 | == API changes in 1.17 == |
36 | 37 | |
Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -7731,8 +7731,47 @@ |
7732 | 7732 | <p>this is not the the title |
7733 | 7733 | </p> |
7734 | 7734 | !! end |
| 7735 | + |
| 7736 | +!! test |
| 7737 | +preload: check <noinclude> and <includeonly> |
| 7738 | +!! options |
| 7739 | +preload |
| 7740 | +!! input |
| 7741 | +Hello <noinclude>cruel</noinclude><includeonly>kind</includeonly> world. |
| 7742 | +!! result |
| 7743 | +Hello kind world. |
| 7744 | +!! end |
| 7745 | + |
| 7746 | +!! test |
| 7747 | +preload: check <onlyinclude> |
| 7748 | +!! options |
| 7749 | +preload |
| 7750 | +!! input |
| 7751 | +Goodbye <onlyinclude>Hello world</onlyinclude> |
| 7752 | +!! result |
| 7753 | +Hello world |
| 7754 | +!! end |
7735 | 7755 | |
| 7756 | +!! test |
| 7757 | +preload: can pass tags through if we want to |
| 7758 | +!! options |
| 7759 | +preload |
| 7760 | +!! input |
| 7761 | +<includeonly><</includeonly>includeonly>Hello world<includeonly><</includeonly>/includeonly> |
| 7762 | +!! result |
| 7763 | +<includeonly>Hello world</includeonly> |
| 7764 | +!! end |
7736 | 7765 | |
| 7766 | +!! test |
| 7767 | +preload: check that it doesn't try to do tricks |
| 7768 | +!! options |
| 7769 | +preload |
| 7770 | +!! input |
| 7771 | +* <!-- Hello --> ''{{world}}'' {{<includeonly>subst:</includeonly>How are you}}{{ {{{|safesubst:}}} #if:1|2|3}} |
| 7772 | +!! result |
| 7773 | +* <!-- Hello --> ''{{world}}'' {{subst:How are you}}{{ {{{|safesubst:}}} #if:1|2|3}} |
| 7774 | +!! end |
| 7775 | + |
7737 | 7776 | TODO: |
7738 | 7777 | more images |
7739 | 7778 | more tables |
Index: trunk/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 | +} |