Tpt has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371208 )

Change subject: Guess Page: pages content format if not given
......................................................................

Guess Page: pages content format if not given

Change-Id: Ia6082626231da5894e8164a3012f9eade7ceb3b5
---
M includes/page/PageContentHandler.php
M tests/phpunit/page/PageContentHandlerTest.php
2 files changed, 13 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage 
refs/changes/08/371208/1

diff --git a/includes/page/PageContentHandler.php 
b/includes/page/PageContentHandler.php
index d86cf58..901de41 100644
--- a/includes/page/PageContentHandler.php
+++ b/includes/page/PageContentHandler.php
@@ -6,6 +6,7 @@
 use ContentHandler;
 use FormatJson;
 use MWContentSerializationException;
+use MWException;
 use TextContentHandler;
 use Title;
 use User;
@@ -87,19 +88,28 @@
         * @see ContentHandler::unserializeContent
         */
        public function unserializeContent( $text, $format = null ) {
-               $this->checkFormat( $format );
+               if ( $format === null ) {
+                       $format = ( FormatJson::decode( $text, true ) === null )
+                               ? CONTENT_FORMAT_WIKITEXT
+                               : CONTENT_FORMAT_JSON;
+               }
 
                switch ( $format ) {
                        case CONTENT_FORMAT_JSON:
                                return $this->unserializeContentInJson( $text );
-                       default:
+                       case CONTENT_FORMAT_WIKITEXT:
                                return $this->unserializeContentInWikitext( 
$text );
+                       default:
+                               throw new MWException(
+                                       "Format ' . $format . ' is not 
supported for content model " . $this->getModelID()
+                               );
                }
        }
 
        /**
         * @param string $text
         * @return PageContent
+        * @throws MWContentSerializationException
         */
        private function unserializeContentInJson( $text ) {
                $array = FormatJson::decode( $text, true );
diff --git a/tests/phpunit/page/PageContentHandlerTest.php 
b/tests/phpunit/page/PageContentHandlerTest.php
index bd4cccb..f29eca8 100644
--- a/tests/phpunit/page/PageContentHandlerTest.php
+++ b/tests/phpunit/page/PageContentHandlerTest.php
@@ -196,7 +196,7 @@
        ) {
                $this->assertEquals(
                        PageContentTest::newContent( $header, $body, $footer, 
$level, $proofreader ),
-                       $this->handler->unserializeContent( $text, 
CONTENT_FORMAT_JSON )
+                       $this->handler->unserializeContent( $text )
                );
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/371208
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia6082626231da5894e8164a3012f9eade7ceb3b5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ProofreadPage
Gerrit-Branch: master
Gerrit-Owner: Tpt <thoma...@hotmail.fr>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to