bug 5210 - add getTransclusionText() to the Parser to remove the horrible (and
authorConrad Irwin <conrad@users.mediawiki.org>
Fri, 5 Feb 2010 16:49:21 +0000 (16:49 +0000)
committerConrad Irwin <conrad@users.mediawiki.org>
Fri, 5 Feb 2010 16:49:21 +0000 (16:49 +0000)
           very broken) attempt to reimplement bits of the preprocessor in
           EditPage.php.

RELEASE-NOTES
includes/EditPage.php
includes/parser/Parser.php

index 30ff67c..1aa4a25 100644 (file)
@@ -825,6 +825,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 18758) API read of watchlist's wl_notificationtimestamp
 * (bug 20809) Expose EditFormPreloadText via the API
 * (bug 18427) Comment (edit summary) parser option for API
+* (bug 5210)  preload parser should parse <noinclude> (as well as <includeonly>)
 
 === Languages updated in 1.16 ===
 
index ad9c993..7cf8abf 100644 (file)
@@ -227,22 +227,13 @@ class EditPage {
         * @return string The contents of the page.
         */
        protected function getPreloadedText( $preload ) {
+               global $wgParser;
                if ( !empty( $this->mPreloadText ) ) {
                        return $this->mPreloadText;
-               } elseif ( $preload === '' ) {
-                       return '';
                } else {
                        $preloadTitle = Title::newFromText( $preload );
                        if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
-                               $rev = Revision::newFromTitle( $preloadTitle );
-                               if ( is_object( $rev ) ) {
-                                       $text = $rev->getText();
-                                       // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
-                                       // its own mini-parser! -ævar
-                                       $text = preg_replace( '~</?includeonly>~', '', $text );
-                                       return $text;
-                               } else
-                                       return '';
+                               return $wgParser->getTransclusionText( $preloadTitle );
                        }
                }
        }
index a26b49f..dbbe93e 100644 (file)
@@ -492,6 +492,22 @@ class Parser
                return $text;
        }
 
+       /**
+        * Get the wikitext of a page as though it was transcluded.
+        *
+        * Specifically <includeonly> etc. are parsed, redirects are followed, comments
+        * are removed, but templates arguments and parser functions are untouched.
+        *
+        * This is not called by the parser itself, see braceSubstitution for its transclusion. 
+        *
+        * @public
+        */
+       function getTransclusionText( $title ) {
+               list($text, $title) = $this->getTemplateDom( $title );
+               $flags = PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES;
+               return $this->getPreprocessor()->newFrame()->expand( $text, $flags );
+       }
+
        /**
         * Get a random string
         *