r62864 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62863‎ | r62864 | r62865 >
Date:02:58, 23 February 2010
Author:conrad
Status:deferred
Tags:
Comment:
Improve changes to ?preload= thanks to feedback from Tim.

getTransclusionText -> getPreloadText
remove usage of FakeTitle
pass text not title to parser (so can be, and is now, tested)
merge the new OT_SECTIONS and OT_EXTRACT into OT_PLAIN - they are both no-ops atm.
Modified paths:
  • /branches/conrad/phase3/includes/Defines.php (modified) (history)
  • /branches/conrad/phase3/includes/EditPage.php (modified) (history)
  • /branches/conrad/phase3/includes/parser/Parser.php (modified) (history)
  • /branches/conrad/phase3/maintenance/parserTests.inc (modified) (history)
  • /branches/conrad/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: branches/conrad/phase3/maintenance/parserTests.inc
@@ -366,6 +366,8 @@
367367 } elseif( isset( $opts['comment'] ) ) {
368368 $linker = $user->getSkin();
369369 $out = $linker->formatComment( $input, $title, $local );
 370+ } elseif( isset( $opts['preload'] ) ) {
 371+ $out = $parser->getpreloadText( $input, $title, $options );
370372 } else {
371373 $output = $parser->parse( $input, $title, $options, true, true, 1337 );
372374 $out = $output->getText();
@@ -1716,4 +1718,4 @@
17171719 }
17181720 return false;
17191721 }
1720 -}
\ No newline at end of file
 1722+}
Index: branches/conrad/phase3/maintenance/parserTests.txt
@@ -7879,7 +7879,46 @@
78807880 </p>
78817881 !! end
78827882
 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
78837892
 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+
78847923 TODO:
78857924 more images
78867925 more tables
Index: branches/conrad/phase3/includes/Defines.php
@@ -209,8 +209,7 @@
210210 define( 'OT_WIKI', 2 );
211211 define( 'OT_PREPROCESS', 3 );
212212 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);
215214
216215 # Flags for Parser::setFunctionHook
217216 define( 'SFH_NO_HASH', 1 );
Index: branches/conrad/phase3/includes/parser/Parser.php
@@ -26,8 +26,8 @@
2727 * Cleans a signature before saving it to preferences
2828 * extractSections()
2929 * 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.
3232 *
3333 * Globals used:
3434 * objects: $wgLang, $wgContLang
@@ -84,10 +84,8 @@
8585 const OT_WIKI = 2; // like preSaveTransform()
8686 const OT_PREPROCESS = 3; // like preprocess()
8787 const OT_MSG = 3;
 88+ const OT_PLAIN = 4; // like extractSections() - portions of the original are returned unchanged.
8889
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 -
9290 // Marker Suffix needs to be accessible staticly.
9391 const MARKER_SUFFIX = "-QINU\x7f";
9492
@@ -254,8 +252,7 @@
255253 'html' => $ot == self::OT_HTML,
256254 'wiki' => $ot == self::OT_WIKI,
257255 'pre' => $ot == self::OT_PREPROCESS,
258 - 'includes' => $ot == self::OT_INCLUDES,
259 - 'extract' => $ot == self::OT_EXTRACT,
 256+ 'plain' => $ot == self::OT_PLAIN,
260257 );
261258 }
262259
@@ -502,23 +499,21 @@
503500 }
504501
505502 /**
506 - * Get the wikitext of a page as though it was transcluded.
 503+ * Process the wikitext for the ?preload= feature. (bug 5210)
507504 *
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.
512507 */
513 - public function getTransclusionText( $title, $options ) {
514 - // Must initialize first
 508+ public function getPreloadText( $text, $title, $options ) {
 509+ // Parser (re)initialisation
515510 $this->clearState();
516 - $this->setOutputType( self::OT_INCLUDES );
 511+ $this->setOutputType( self::OT_PLAIN );
517512 $this->mOptions = $options;
518 - $this->setTitle( new FakeTitle );
 513+ $this->setTitle( $title );
519514
520 - list( $text, $title ) = $this->getTemplateDom( $title );
521515 $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 );
523518 }
524519
525520 /**
@@ -4808,10 +4803,11 @@
48094804 * for "replace", the whole page with the section replaced.
48104805 */
48114806 private function extractSections( $text, $section, $mode, $newText='' ) {
 4807+ global $wgTitle;
48124808 $this->clearState();
4813 - $this->setTitle( new FakeTitle );
 4809+ $this->setTitle( $wgTitle ); // just a placeholder.
48144810 $this->mOptions = new ParserOptions;
4815 - $this->setOutputType( self::OT_EXTRACT );
 4811+ $this->setOutputType( self::OT_PLAIN );
48164812 $outText = '';
48174813 $frame = $this->getPreprocessor()->newFrame();
48184814
Index: branches/conrad/phase3/includes/EditPage.php
@@ -231,11 +231,22 @@
232232 if ( !empty( $this->mPreloadText ) ) {
233233 return $this->mPreloadText;
234234 } 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 );
238248 }
239249 }
 250+ return "";
240251 }
241252
242253 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r63194Merge fixes to ?preload= from /branches/conrad/ (cf. bug 5210, r62864, r62035)conrad02:41, 3 March 2010

Status & tagging log