create Article, EditPage and ExternalEdit via ContentHandler
authorDaniel Kinzler <daniel.kinzler@wikimedia.de>
Fri, 9 Mar 2012 17:23:05 +0000 (17:23 +0000)
committerDaniel Kinzler <daniel.kinzler@wikimedia.de>
Wed, 4 Apr 2012 17:55:20 +0000 (19:55 +0200)
includes/Article.php
includes/Content.php
includes/ContentHandler.php
includes/actions/EditAction.php
includes/api/ApiEditPage.php

index 628cc1c..9a0fb80 100644 (file)
@@ -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();
index 05ada53..6a3ecdb 100644 (file)
@@ -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 {
index 7bfe03e..138c641 100644 (file)
@@ -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!
 }
 
 
index 08a33f4..2888d24 100644 (file)
@@ -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();
                        }
                }
index cd07e30..3b74dac 100644 (file)
@@ -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 );