$wgContentHandlerTextFallback
authorDaniel Kinzler <daniel.kinzler@wikimedia.de>
Fri, 23 Mar 2012 15:44:49 +0000 (15:44 +0000)
committerDaniel Kinzler <daniel.kinzler@wikimedia.de>
Wed, 4 Apr 2012 17:58:59 +0000 (19:58 +0200)
includes/ContentHandler.php
includes/DefaultSettings.php

index d784a7c..67bc812 100644 (file)
 abstract class ContentHandler {
 
     public static function getContentText( Content $content = null ) {
+        global $wgContentHandlerTextFallback;
+
         if ( !$content ) return '';
 
         if ( $content instanceof TextContent ) {
-            #XXX: or check by model name?
-            #XXX: or define $content->allowRawData()?
-            #XXX: or define $content->getDefaultWikiText()?
             return $content->getNativeData();
         }
 
-        #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
+        if ( $wgContentHandlerTextFallback == 'fail' ) throw new MWException( "Attempt to get text from Content with model " . $content->getModelName() );
+        if ( $wgContentHandlerTextFallback == 'serialize' ) return $content->serialize();
 
-        #TODO: log this incident!
         return null;
     }
 
index 9536258..1e5edbf 100644 (file)
@@ -5750,6 +5750,22 @@ $wgSeleniumConfigFile = null;
 $wgDBtestuser = ''; //db user that has permission to create and drop the test databases only
 $wgDBtestpassword = '';
 
+/**
+ * Associative array mapping namespace IDs to the name of the content model pages in that namespace should have by
+ * default (use the CONTENT_MODEL_XXX constants). If no special content type is defined for a given namespace,
+ * pages in that namespace will  use the CONTENT_MODEL_WIKITEXT (except for the special case of JS and CS pages).
+ */
+$wgNamespaceContentModels = array();
+
+/**
+ * How to react if a plain text version of a non-text Content object is requested using ContentHandler::getContentText():
+ *
+ * * 'ignore': return null
+ * * 'fail': throw an MWException
+ * * 'serialize': serialize to default format
+ */
+$wgContentHandlerTextFallback = 'ignore';
+
 /**
  * For really cool vim folding this needs to be at the end:
  * vim: foldmarker=@{,@} foldmethod=marker