From: Daniel Kinzler Date: Fri, 9 Mar 2012 17:23:05 +0000 (+0000) Subject: create Article, EditPage and ExternalEdit via ContentHandler X-Git-Tag: 1.31.0-rc.0~22097^2^2~296 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22upgrade%22%2C%22reinstall=non%22%29%20.%20%22?a=commitdiff_plain;h=9a42110b784f54f51ce08541f7695a60f3ef2a22;p=lhc%2Fweb%2Fwiklou.git create Article, EditPage and ExternalEdit via ContentHandler --- diff --git a/includes/Article.php b/includes/Article.php index 628cc1c35d..9a0fb806dd 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -113,13 +113,14 @@ class Article extends Page { if ( !$page ) { switch( $title->getNamespace() ) { case NS_FILE: - $page = new ImagePage( $title ); + $page = new ImagePage( $title ); #FIXME: teach ImagePage to use ContentHandler break; case NS_CATEGORY: - $page = new CategoryPage( $title ); + $page = new CategoryPage( $title ); #FIXME: teach ImagePage to use ContentHandler break; default: - $page = new Article( $title ); + $handler = ContentHandler::getForTitle( $title ); + $page = $handler->createArticle( $title ); } } $page->setContext( $context ); @@ -742,7 +743,7 @@ class Article extends Page { * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these * page views. */ - protected function showCssOrJsPage() { #FIXME: move this to handler! + protected function showCssOrJsPage() { #FIXME: move this to ContentHandler! global $wgOut; $dir = $this->getContext()->getLanguage()->getDir(); diff --git a/includes/Content.php b/includes/Content.php index 05ada53312..6a3ecdb57f 100644 --- a/includes/Content.php +++ b/includes/Content.php @@ -52,6 +52,21 @@ abstract class Content { } #XXX: is the native model for wikitext a string or the parser output? parse early or parse late? + + + # TODO: EditPage::mergeChanges( Content $a, Content $b ) + # TODO: Wikipage::isCountable(Content $a) + # TODO: Title::newFromRedirectRecurse( $this->getRawText() ); + + # TODO: isCacheable( ) + # TODO: getSize( ) + + # TODO: WikiPage::getUndoText( Revision $undo, Revision $undoafter = null ) + # TODO: WikiPage::replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) + # TODO: WikiPage::getAutosummary( $oldtext, $text, $flags ) + + # TODO: EditPage::getPreloadedText( $preload ) // $wgParser->getPreloadText + } class TextContent extends Content { diff --git a/includes/ContentHandler.php b/includes/ContentHandler.php index 7bfe03e080..138c641e32 100644 --- a/includes/ContentHandler.php +++ b/includes/ContentHandler.php @@ -19,9 +19,13 @@ abstract class ContentHandler { if ( $content instanceof TextContent ) { #XXX: or check by model name? #XXX: or define $content->allowRawData()? + #XXX: or define $content->getDefaultWikiText()? return $content->getRawData(); } + #XXX: this must not be used for editing, otherwise we may loose data: + #XXX: e.g. if this returns the "main" text from a multipart page, all attachments would be lost + return null; } @@ -90,12 +94,12 @@ abstract class ContentHandler { public static function getForTitle( Title $title ) { $modelName = $title->getContentModelName(); - return ContenteHandler::getForModelName( $modelName ); + return ContentHandler::getForModelName( $modelName ); } public static function getForContent( Content $content ) { $modelName = $content->getModelName(); - return ContenteHandler::getForModelName( $modelName ); + return ContentHandler::getForModelName( $modelName ); } public static function getForModelName( $modelName ) { @@ -145,13 +149,16 @@ abstract class ContentHandler { /** * Return an Article object suitable for viewing the given object - * + * + * NOTE: does *not* do special handling for Image and Category pages! + * Use Article::newFromTitle() for that! + * * @param type $title - * @param type $obj - * @return \Article + * @return \Article * @todo Article is being refactored into an action class, keep track of that */ - public function createArticle( Title $title, $obj ) { #TODO: use this! + public function createArticle( Title $title ) { + #XXX: assert that $title->getContentModelName() == $this->getModelname()? $article = new Article($title); return $article; } @@ -159,16 +166,27 @@ abstract class ContentHandler { /** * Return an EditPage object suitable for editing the given object * - * @param type $title - * @param type $obj * @param type $article * @return \EditPage */ - public function createEditPage( Title $title, $obj, Article $article ) { #TODO: use this! - $editPage = new EditPage($article); + public function createEditPage( Article $article ) { + #XXX: assert that $article->getContentObject()->getModelName() == $this->getModelname()? + $editPage = new EditPage( $article ); return $editPage; } + /** + * Return an ExternalEdit object suitable for editing the given object + * + * @param type $article + * @return \ExternalEdit + */ + public function createExternalEdit( IContextSource $context ) { + #XXX: assert that $article->getContentObject()->getModelName() == $this->getModelname()? + $externalEdit = new ExternalEdit( $context ); + return $externalEdit; + } + /** public function updatePage( $title, $obj ) { } @@ -187,6 +205,9 @@ abstract class ContentHandler { } #XXX: is the native model for wikitext a string or the parser output? parse early or parse late? + + #TODO: how to handle extra message for JS/CSS previews?? + #TODO: Article::showCssOrJsPage ---> specialized classes! } diff --git a/includes/actions/EditAction.php b/includes/actions/EditAction.php index 08a33f4c0d..2888d247d8 100644 --- a/includes/actions/EditAction.php +++ b/includes/actions/EditAction.php @@ -40,14 +40,16 @@ class EditAction extends FormlessAction { $context = $this->getContext(); if ( wfRunHooks( 'CustomEditor', array( $page, $user ) ) ) { + $handler = ContentHandler::getForTitle( $page->getTitle() ); + if ( ExternalEdit::useExternalEngine( $context, 'edit' ) && $this->getName() == 'edit' && !$request->getVal( 'section' ) && !$request->getVal( 'oldid' ) ) { - $extedit = new ExternalEdit( $context ); + $extedit = $handler->createExternalEdit( $context ); $extedit->execute(); } else { - $editor = new EditPage( $page ); + $editor = $handler->createEditPage( $page ); $editor->edit(); } } diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index cd07e30dd1..3b74dac846 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -240,7 +240,9 @@ class ApiEditPage extends ApiBase { // TODO: Make them not or check if they still do $wgTitle = $titleObj; - $ep = new EditPage( $articleObj ); + $handler = ContentHandler::getForTitle( $titleObj ); + $ep = $handler->createEditPage( $articleObj ); + $ep->setContextTitle( $titleObj ); $ep->importFormData( $req );