r63194 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63193‎ | r63194 | r63195 >
Date:02:41, 3 March 2010
Author:conrad
Status:ok
Tags:
Comment:
Merge fixes to ?preload= from /branches/conrad/ (cf. bug 5210, r62864, r62035)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Defines.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.inc (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -220,30 +220,39 @@
221221 }
222222
223223 /**
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.
225226 *
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
228229 */
229230 protected function getPreloadedText( $preload ) {
 231+ global $wgUser, $wgParser;
230232 if ( !empty( $this->mPreloadText ) ) {
231233 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 );
246254 }
247255 }
 256+ return '';
248257 }
249258
250259 /*
Index: trunk/phase3/includes/parser/Parser.php
@@ -26,6 +26,8 @@
2727 * Cleans a signature before saving it to preferences
2828 * extractSections()
2929 * Extracts sections from an article for section editing
 30+ * getPreloadText()
 31+ * Removes <noinclude> sections, and <includeonly> tags.
3032 *
3133 * Globals used:
3234 * objects: $wgLang, $wgContLang
@@ -78,10 +80,11 @@
7981
8082 // Allowed values for $this->mOutputType
8183 // 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()
8587 const OT_MSG = 3;
 88+ const OT_PLAIN = 4; // like extractSections() - portions of the original are returned unchanged.
8689
8790 // Marker Suffix needs to be accessible staticly.
8891 const MARKER_SUFFIX = "-QINU\x7f";
@@ -249,6 +252,7 @@
250253 'html' => $ot == self::OT_HTML,
251254 'wiki' => $ot == self::OT_WIKI,
252255 'pre' => $ot == self::OT_PREPROCESS,
 256+ 'plain' => $ot == self::OT_PLAIN,
253257 );
254258 }
255259
@@ -489,6 +493,24 @@
490494 }
491495
492496 /**
 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+ /**
493515 * Get a random string
494516 *
495517 * @private
@@ -4741,7 +4763,7 @@
47424764 $this->clearState();
47434765 $this->setTitle( $wgTitle ); // not generally used but removes an ugly failure mode
47444766 $this->mOptions = new ParserOptions;
4745 - $this->setOutputType( self::OT_WIKI );
 4767+ $this->setOutputType( self::OT_PLAIN );
47464768 $outText = '';
47474769 $frame = $this->getPreprocessor()->newFrame();
47484770
Index: trunk/phase3/includes/Defines.php
@@ -209,6 +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_PLAIN', 4 );
213214
214215 # Flags for Parser::setFunctionHook
215216 define( 'SFH_NO_HASH', 1 );
Index: trunk/phase3/RELEASE-NOTES
@@ -30,6 +30,7 @@
3131 * (bug 22606) The body of e-mail address confirmation message is now different
3232 when the address changed
3333 * (bug 22664) Special:Userrights now accepts '0' as a valid user name
 34+* (bug 5210) preload parser now parses <noinclude>, <includeonly> and redirects
3435
3536 == API changes in 1.17 ==
3637
Index: trunk/phase3/maintenance/parserTests.txt
@@ -7731,8 +7731,47 @@
77327732 <p>this is not the the title
77337733 </p>
77347734 !! 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
77357755
 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
77367765
 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+
77377776 TODO:
77387777 more images
77397778 more tables
Index: trunk/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+}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r62035bug 5210 - add getTransclusionText() to the Parser to remove the horrible (and...conrad16:49, 5 February 2010
r62194Pretty sure that...reedy20:46, 9 February 2010
r62864Improve changes to ?preload= thanks to feedback from Tim....conrad02:58, 23 February 2010

Status & tagging log