https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113485

Revision: 113485
Author:   daniel
Date:     2012-03-09 17:23:05 +0000 (Fri, 09 Mar 2012)
Log Message:
-----------
create Article, EditPage and ExternalEdit via ContentHandler

Modified Paths:
--------------
    branches/Wikidata/phase3/includes/Article.php
    branches/Wikidata/phase3/includes/Content.php
    branches/Wikidata/phase3/includes/ContentHandler.php
    branches/Wikidata/phase3/includes/actions/EditAction.php
    branches/Wikidata/phase3/includes/api/ApiEditPage.php

Modified: branches/Wikidata/phase3/includes/Article.php
===================================================================
--- branches/Wikidata/phase3/includes/Article.php       2012-03-09 17:10:51 UTC 
(rev 113484)
+++ branches/Wikidata/phase3/includes/Article.php       2012-03-09 17:23:05 UTC 
(rev 113485)
@@ -113,13 +113,14 @@
                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 @@
         * 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();

Modified: branches/Wikidata/phase3/includes/Content.php
===================================================================
--- branches/Wikidata/phase3/includes/Content.php       2012-03-09 17:10:51 UTC 
(rev 113484)
+++ branches/Wikidata/phase3/includes/Content.php       2012-03-09 17:23:05 UTC 
(rev 113485)
@@ -52,6 +52,21 @@
     }
 
     #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 {

Modified: branches/Wikidata/phase3/includes/ContentHandler.php
===================================================================
--- branches/Wikidata/phase3/includes/ContentHandler.php        2012-03-09 
17:10:51 UTC (rev 113484)
+++ branches/Wikidata/phase3/includes/ContentHandler.php        2012-03-09 
17:23:05 UTC (rev 113485)
@@ -19,9 +19,13 @@
         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 @@
 
     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 @@
 
     /**
      * 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,17 +166,28 @@
     /**
      * 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 @@
     }
 
     #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!
 }
 
 

Modified: branches/Wikidata/phase3/includes/actions/EditAction.php
===================================================================
--- branches/Wikidata/phase3/includes/actions/EditAction.php    2012-03-09 
17:10:51 UTC (rev 113484)
+++ branches/Wikidata/phase3/includes/actions/EditAction.php    2012-03-09 
17:23:05 UTC (rev 113485)
@@ -40,14 +40,16 @@
                $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();
                        }
                }

Modified: branches/Wikidata/phase3/includes/api/ApiEditPage.php
===================================================================
--- branches/Wikidata/phase3/includes/api/ApiEditPage.php       2012-03-09 
17:10:51 UTC (rev 113484)
+++ branches/Wikidata/phase3/includes/api/ApiEditPage.php       2012-03-09 
17:23:05 UTC (rev 113485)
@@ -240,7 +240,9 @@
                // 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 );
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to