(Bug 41706) preload to convert content as needed.
authordaniel <daniel.kinzler@wikimedia.de>
Tue, 6 Nov 2012 13:05:30 +0000 (14:05 +0100)
committerdaniel <daniel.kinzler@wikimedia.de>
Mon, 12 Nov 2012 16:45:29 +0000 (17:45 +0100)
Use the new Content::convert function to convert preloaded content
if the page being edited uses a different content model. This allows
e.g. a page like User:Foo/bar to be preloaded when creating
User:Foo/common.css. This currently fails, because it is not possible
to use wikitext to pre-fill a CSS page.

Change-Id: I70656b41bd203e5722528e889a242fa54cbfbf62

RELEASE-NOTES-1.21
includes/EditPage.php

index 16d842b..654525e 100644 (file)
@@ -65,6 +65,7 @@ production.
   protocol-relative) URLs.
 * (bug 41990) Fix regression: API edit with redirect=true and lacking
   starttimestamp and basetimestamp should not cause an edit conflict.
+* (Bug 41706) preload to convert content as needed.
 
 === API changes in 1.21 ===
 * prop=revisions can now report the contentmodel and contentformat, see docs/contenthandler.txt
index 21a100f..89daf52 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 );
        }