r113485 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113484‎ | r113485 | r113486 >
Date:17:23, 9 March 2012
Author:daniel
Status:deferred
Tags:
Comment:
create Article, EditPage and ExternalEdit via ContentHandler
Modified paths:
  • /branches/Wikidata/phase3/includes/Article.php (modified) (history)
  • /branches/Wikidata/phase3/includes/Content.php (modified) (history)
  • /branches/Wikidata/phase3/includes/ContentHandler.php (modified) (history)
  • /branches/Wikidata/phase3/includes/actions/EditAction.php (modified) (history)
  • /branches/Wikidata/phase3/includes/api/ApiEditPage.php (modified) (history)

Diff [purge]

Index: branches/Wikidata/phase3/includes/Content.php
@@ -52,6 +52,21 @@
5353 }
5454
5555 #XXX: is the native model for wikitext a string or the parser output? parse early or parse late?
 56+
 57+
 58+ # TODO: EditPage::mergeChanges( Content $a, Content $b )
 59+ # TODO: Wikipage::isCountable(Content $a)
 60+ # TODO: Title::newFromRedirectRecurse( $this->getRawText() );
 61+
 62+ # TODO: isCacheable( )
 63+ # TODO: getSize( )
 64+
 65+ # TODO: WikiPage::getUndoText( Revision $undo, Revision $undoafter = null )
 66+ # TODO: WikiPage::replaceSection( $section, $text, $sectionTitle = '', $edittime = null )
 67+ # TODO: WikiPage::getAutosummary( $oldtext, $text, $flags )
 68+
 69+ # TODO: EditPage::getPreloadedText( $preload ) // $wgParser->getPreloadText
 70+
5671 }
5772
5873 class TextContent extends Content {
Index: branches/Wikidata/phase3/includes/api/ApiEditPage.php
@@ -240,7 +240,9 @@
241241 // TODO: Make them not or check if they still do
242242 $wgTitle = $titleObj;
243243
244 - $ep = new EditPage( $articleObj );
 244+ $handler = ContentHandler::getForTitle( $titleObj );
 245+ $ep = $handler->createEditPage( $articleObj );
 246+
245247 $ep->setContextTitle( $titleObj );
246248 $ep->importFormData( $req );
247249
Index: branches/Wikidata/phase3/includes/ContentHandler.php
@@ -19,9 +19,13 @@
2020 if ( $content instanceof TextContent ) {
2121 #XXX: or check by model name?
2222 #XXX: or define $content->allowRawData()?
 23+ #XXX: or define $content->getDefaultWikiText()?
2324 return $content->getRawData();
2425 }
2526
 27+ #XXX: this must not be used for editing, otherwise we may loose data:
 28+ #XXX: e.g. if this returns the "main" text from a multipart page, all attachments would be lost
 29+
2630 return null;
2731 }
2832
@@ -90,12 +94,12 @@
9195
9296 public static function getForTitle( Title $title ) {
9397 $modelName = $title->getContentModelName();
94 - return ContenteHandler::getForModelName( $modelName );
 98+ return ContentHandler::getForModelName( $modelName );
9599 }
96100
97101 public static function getForContent( Content $content ) {
98102 $modelName = $content->getModelName();
99 - return ContenteHandler::getForModelName( $modelName );
 103+ return ContentHandler::getForModelName( $modelName );
100104 }
101105
102106 public static function getForModelName( $modelName ) {
@@ -145,13 +149,16 @@
146150
147151 /**
148152 * Return an Article object suitable for viewing the given object
149 - *
 153+ *
 154+ * NOTE: does *not* do special handling for Image and Category pages!
 155+ * Use Article::newFromTitle() for that!
 156+ *
150157 * @param type $title
151 - * @param type $obj
152 - * @return \Article
 158+ * @return \Article
153159 * @todo Article is being refactored into an action class, keep track of that
154160 */
155 - public function createArticle( Title $title, $obj ) { #TODO: use this!
 161+ public function createArticle( Title $title ) {
 162+ #XXX: assert that $title->getContentModelName() == $this->getModelname()?
156163 $article = new Article($title);
157164 return $article;
158165 }
@@ -159,17 +166,28 @@
160167 /**
161168 * Return an EditPage object suitable for editing the given object
162169 *
163 - * @param type $title
164 - * @param type $obj
165170 * @param type $article
166171 * @return \EditPage
167172 */
168 - public function createEditPage( Title $title, $obj, Article $article ) { #TODO: use this!
169 - $editPage = new EditPage($article);
 173+ public function createEditPage( Article $article ) {
 174+ #XXX: assert that $article->getContentObject()->getModelName() == $this->getModelname()?
 175+ $editPage = new EditPage( $article );
170176 return $editPage;
171177 }
172178
173179 /**
 180+ * Return an ExternalEdit object suitable for editing the given object
 181+ *
 182+ * @param type $article
 183+ * @return \ExternalEdit
 184+ */
 185+ public function createExternalEdit( IContextSource $context ) {
 186+ #XXX: assert that $article->getContentObject()->getModelName() == $this->getModelname()?
 187+ $externalEdit = new ExternalEdit( $context );
 188+ return $externalEdit;
 189+ }
 190+
 191+ /**
174192 public function updatePage( $title, $obj ) {
175193 }
176194 **/
@@ -187,6 +205,9 @@
188206 }
189207
190208 #XXX: is the native model for wikitext a string or the parser output? parse early or parse late?
 209+
 210+ #TODO: how to handle extra message for JS/CSS previews??
 211+ #TODO: Article::showCssOrJsPage ---> specialized classes!
191212 }
192213
193214
Index: branches/Wikidata/phase3/includes/actions/EditAction.php
@@ -40,14 +40,16 @@
4141 $context = $this->getContext();
4242
4343 if ( wfRunHooks( 'CustomEditor', array( $page, $user ) ) ) {
 44+ $handler = ContentHandler::getForTitle( $page->getTitle() );
 45+
4446 if ( ExternalEdit::useExternalEngine( $context, 'edit' )
4547 && $this->getName() == 'edit' && !$request->getVal( 'section' )
4648 && !$request->getVal( 'oldid' ) )
4749 {
48 - $extedit = new ExternalEdit( $context );
 50+ $extedit = $handler->createExternalEdit( $context );
4951 $extedit->execute();
5052 } else {
51 - $editor = new EditPage( $page );
 53+ $editor = $handler->createEditPage( $page );
5254 $editor->edit();
5355 }
5456 }
Index: branches/Wikidata/phase3/includes/Article.php
@@ -113,13 +113,14 @@
114114 if ( !$page ) {
115115 switch( $title->getNamespace() ) {
116116 case NS_FILE:
117 - $page = new ImagePage( $title );
 117+ $page = new ImagePage( $title ); #FIXME: teach ImagePage to use ContentHandler
118118 break;
119119 case NS_CATEGORY:
120 - $page = new CategoryPage( $title );
 120+ $page = new CategoryPage( $title ); #FIXME: teach ImagePage to use ContentHandler
121121 break;
122122 default:
123 - $page = new Article( $title );
 123+ $handler = ContentHandler::getForTitle( $title );
 124+ $page = $handler->createArticle( $title );
124125 }
125126 }
126127 $page->setContext( $context );
@@ -742,7 +743,7 @@
743744 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
744745 * page views.
745746 */
746 - protected function showCssOrJsPage() { #FIXME: move this to handler!
 747+ protected function showCssOrJsPage() { #FIXME: move this to ContentHandler!
747748 global $wgOut;
748749
749750 $dir = $this->getContext()->getLanguage()->getDir();

Status & tagging log