bug 5210 - add getTransclusionText() to the Parser to remove the horrible (and
[lhc/web/wiklou.git] / includes / EditPage.php
index 85506fe..7cf8abf 100644 (file)
@@ -121,6 +121,7 @@ class EditPage {
 
        /**
         * Fetch initial editing page content.
+        * @returns mixed string on success, $def_text for invalid sections
         * @private
         */
        function getContent( $def_text = '' ) {
@@ -204,6 +205,7 @@ class EditPage {
                                if ( $section == 'new' ) {
                                        $text = $this->getPreloadedText( $preload );
                                } else {
+                                       // Get section edit text (returns $def_text for invalid sections)
                                        $text = $wgParser->getSection( $text, $section, $def_text );
                                }
                        }
@@ -225,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 );
                        }
                }
        }
@@ -403,7 +396,7 @@ class EditPage {
                $permErrors = $this->getEditPermissionErrors();
                if ( $permErrors ) {
                        wfDebug( __METHOD__ . ": User can't edit\n" );
-                       $this->readOnlyPage( $this->getContent(), true, $permErrors, 'edit' );
+                       $this->readOnlyPage( $this->getContent( false ), true, $permErrors, 'edit' );
                        wfProfileOut( __METHOD__ );
                        return;
                } else {
@@ -1183,6 +1176,7 @@ class EditPage {
        /**
         * Initialise form fields in the object
         * Called on the first invocation, e.g. when a user clicks an edit link
+        * @returns bool -- if the requested section is valid
         */
        function initialiseForm() {
                global $wgUser;
@@ -1341,6 +1335,8 @@ HTML
                $autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary );
                $wgOut->addHTML( Xml::hidden( 'wpAutoSummary', $autosumm ) );
 
+               $wgOut->addHTML( Xml::hidden( 'oldid', $this->mArticle->getOldID() ) );
+
                if ( $this->section == 'new' ) {
                        $this->showSummaryInput( true, $this->summary );
                        $wgOut->addHTML( $this->getSummaryPreview( true, $this->summary ) );
@@ -1399,7 +1395,7 @@ HTML
        }
        
        protected function showHeader() {
-               global $wgOut, $wgParser, $wgUser, $wgTitle, $wgMaxArticleSize, $wgLang;
+               global $wgOut, $wgUser, $wgTitle, $wgMaxArticleSize, $wgLang;
                if ( $this->isConflict ) {
                        $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1</div>", 'explainconflict' );
                        $this->edittime = $this->mArticle->getTimestamp();
@@ -1546,7 +1542,7 @@ HTML
                $inputAttrs = ( is_array($inputAttrs) ? $inputAttrs : array() ) + array(
                        'id' => 'wpSummary',
                        'maxlength' => '200',
-                       'tabindex' => '1',
+                       'tabindex' => '2',
                        'size' => 60,
                        'spellcheck' => 'true',
                );
@@ -2442,11 +2438,12 @@ INPUTS
 
        public function getCancelLink() {
                global $wgUser, $wgTitle;
+
                $cancelParams = array();
-               if ( !$this->isConflict && isset( $this->mArticle ) &&
-                       isset( $this->mArticle->mRevision ) &&
-                       !$this->mArticle->mRevision->isCurrent() )
-                               $cancelParams['oldid'] = $this->mArticle->mRevision->getId();
+               if ( !$this->isConflict && $this->mArticle->getOldID() > 0 ) {
+                       $cancelParams['oldid'] = $this->mArticle->getOldID();
+               }
+
                return $wgUser->getSkin()->link(
                        $wgTitle,
                        wfMsgExt( 'cancel', array( 'parseinline' ) ),