From: daniel Date: Tue, 6 Nov 2012 13:05:30 +0000 (+0100) Subject: (Bug 41706) preload to convert content as needed. X-Git-Tag: 1.31.0-rc.0~21655 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=bcea63957d27300c73a60cd88331b6a571a454e4;p=lhc%2Fweb%2Fwiklou.git (Bug 41706) preload to convert content as needed. 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 --- diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index 16d842bc1b..654525e50c 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -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 diff --git a/includes/EditPage.php b/includes/EditPage.php index 21a100f0aa..89daf521c7 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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 ); }