Merge "Base class for objects accessign databases."
[lhc/web/wiklou.git] / includes / EditPage.php
index 21a100f..5ab5adc 100644 (file)
@@ -1063,6 +1063,7 @@ class EditPage {
                $title = Title::newFromText( $preload );
                # Check for existence to avoid getting MediaWiki:Noarticletext
                if ( $title === null || !$title->exists() || !$title->userCan( 'read', $wgUser ) ) {
+                       //TODO: somehow show a warning to the user!
                        return $handler->makeEmptyContent();
                }
 
@@ -1071,6 +1072,7 @@ class EditPage {
                        $title = $page->getRedirectTarget();
                        # Same as before
                        if ( $title === null || !$title->exists() || !$title->userCan( 'read', $wgUser ) ) {
+                               //TODO: somehow show a warning to the user!
                                return $handler->makeEmptyContent();
                        }
                        $page = WikiPage::factory( $title );
@@ -1080,9 +1082,25 @@ class EditPage {
                $content = $page->getContent( Revision::RAW );
 
                if ( !$content ) {
+                       //TODO: somehow show a warning to the user!
                        return $handler->makeEmptyContent();
                }
 
+               if ( $content->getModel() !== $handler->getModelID() ) {
+                       $converted = $content->convert( $handler->getModelID() );
+
+                       if ( !$converted ) {
+                               //TODO: somehow show a warning to the user!
+                               wfDebug( "Attempt to preload incompatible content: "
+                                               . "can't convert " . $content->getModel()
+                                               . " to " . $handler->getModelID() );
+
+                               return $handler->makeEmptyContent();
+                       }
+
+                       $content = $converted;
+               }
+
                return $content->preloadTransform( $title, $parserOptions );
        }
 
@@ -2762,7 +2780,9 @@ HTML
                        wfMessage( 'newwindow' )->parse();
                $wgOut->addHTML( "      <span class='cancelLink'>{$cancel}</span>\n" );
                $wgOut->addHTML( "      <span class='editHelp'>{$edithelp}</span>\n" );
-               $wgOut->addHTML( "</div><!-- editButtons -->\n</div><!-- editOptions -->\n" );
+               $wgOut->addHTML( "</div><!-- editButtons -->\n" );
+               wfRunHooks( 'EditPage::showStandardInputs:options', array( $this, $wgOut, &$tabindex ) );
+               $wgOut->addHTML( "</div><!-- editOptions -->\n" );
        }
 
        /**
@@ -2912,6 +2932,12 @@ HTML
                try {
                        $content = $this->toEditContent( $this->textbox1 );
 
+                       $previewHTML = '';
+                       if ( !wfRunHooks( 'AlternateEditPreview', array( $this, &$content, &$previewHTML, &$this->mParserOutput ) ) ) {
+                               wfProfileOut( __METHOD__ );
+                               return $previewHTML;
+                       }
+
                        if ( $this->mTriedSave && !$this->mTokenOk ) {
                                if ( $this->mTokenOkExceptSuffix ) {
                                        $note = wfMessage( 'token_suffix_mismatch' )->plain() ;