Harej has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/316284

Change subject: Creating basic editing interface for CollaborationHubContent.
......................................................................

Creating basic editing interface for CollaborationHubContent.

There is still more work to be done. Also, the editing interface uses OOjs UI 
because I will be added some extra features using OOjs UI so it makes more 
sense to have the form use it.

Bug: T141037
Change-Id: I25a2a13fdd3675b28da43259f543d4edecbb8d4e
---
M .gitignore
M .gitreview
M .jscsrc
M CollaborationKit.alias.php
M CollaborationKit.hooks.php
M CollaborationKit.i18n.magic.php
M Gruntfile.js
M composer.json
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/ApiEditCollaborationHub.php
A includes/CollaborationHubContentEditor.php
M includes/CollaborationListContentEditor.php
M includes/ResourceLoaderListStyleModule.php
M includes/SpecialCreateCollaborationHub.php
M includes/SpecialCreateHubFeature.php
M includes/content/CollaborationHubContent.php
M includes/content/CollaborationHubContentHandler.php
M includes/content/CollaborationHubContentSchema.php
M includes/content/CollaborationHubDiffEngine.php
M includes/content/CollaborationHubTOC.php
M includes/content/CollaborationKitIcon.php
M includes/content/CollaborationListContent.php
M includes/content/CollaborationListContentHandler.php
M includes/content/CollaborationListContentSchema.php
M modules/ext.CollaborationKit.hub.styles.less
M modules/ext.CollaborationKit.hub.subpage.styles.less
M modules/ext.CollaborationKit.list.edit.js
M modules/ext.CollaborationKit.list.styles.less
M modules/ext.CollaborationKit.mixins.less
M modules/images/blot.svg
M modules/images/icons/LICENSE
M modules/images/icons/addimage.svg
M modules/images/icons/addmapmarker.svg
M modules/images/icons/addquote.svg
M modules/images/icons/bell.svg
M modules/images/icons/book.svg
M modules/images/icons/circleline.svg
M modules/images/icons/circlestar.svg
M modules/images/icons/circletriangle.svg
M modules/images/icons/circlex.svg
M modules/images/icons/clock.svg
M modules/images/icons/community.svg
M modules/images/icons/contents.svg
M modules/images/icons/die.svg
M modules/images/icons/discussion.svg
M modules/images/icons/download.svg
M modules/images/icons/edit.svg
M modules/images/icons/editprotected.svg
M modules/images/icons/eye.svg
M modules/images/icons/flag.svg
M modules/images/icons/funnel.svg
M modules/images/icons/gallery.svg
M modules/images/icons/gear.svg
M modules/images/icons/heart.svg
M modules/images/icons/icons-full.svg
M modules/images/icons/image.svg
M modules/images/icons/journal.svg
M modules/images/icons/key.svg
M modules/images/icons/link.svg
M modules/images/icons/lock.svg
M modules/images/icons/mail.svg
M modules/images/icons/map.svg
M modules/images/icons/mapmarker.svg
M modules/images/icons/menu.svg
M modules/images/icons/message.svg
M modules/images/icons/messagenew.svg
M modules/images/icons/messagescary.svg
M modules/images/icons/move.svg
M modules/images/icons/newspaper.svg
M modules/images/icons/nowiki.svg
M modules/images/icons/ol.svg
M modules/images/icons/page.svg
M modules/images/icons/pagechecked.svg
M modules/images/icons/pageribbon.svg
M modules/images/icons/pagesearch.svg
M modules/images/icons/paperclip.svg
M modules/images/icons/print.svg
M modules/images/icons/puzzlepiece.svg
M modules/images/icons/quotes.svg
M modules/images/icons/ribbon.svg
M modules/images/icons/rocket.svg
M modules/images/icons/search.svg
M modules/images/icons/star.svg
M modules/images/icons/starmenu.svg
M modules/images/icons/sun.svg
M modules/images/icons/translate.svg
M modules/images/icons/trash.svg
M modules/images/icons/ul.svg
M modules/images/icons/user.svg
M package.json
M phpcs.xml
M tests/phpunit/CollaborationHubContentHandlerTest.php
M tests/phpunit/CollaborationHubContentTest.php
95 files changed, 404 insertions(+), 12 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CollaborationKit 
refs/changes/84/316284/1

diff --git a/.gitignore b/.gitignore
old mode 100644
new mode 100755
diff --git a/.gitreview b/.gitreview
old mode 100644
new mode 100755
diff --git a/.jscsrc b/.jscsrc
old mode 100644
new mode 100755
diff --git a/CollaborationKit.alias.php b/CollaborationKit.alias.php
old mode 100644
new mode 100755
diff --git a/CollaborationKit.hooks.php b/CollaborationKit.hooks.php
old mode 100644
new mode 100755
index e2d439e..fc28f01
--- a/CollaborationKit.hooks.php
+++ b/CollaborationKit.hooks.php
@@ -13,7 +13,7 @@
                $title = $sktemplate->getTitle();
                $request = $sktemplate->getRequest();
                if ( isset( $links['views']['edit'] ) ) {
-                       if ( $title->hasContentModel( 
'CollaborationListContent' ) ) {
+                       if ( $title->hasContentModel( 
'CollaborationListContent' ) || $title->hasContentModel( 
'CollaborationHubContent' ) ) {
                                // Edit as JSON
                                $active = in_array( $request->getVal( 'action' 
), [ 'edit', 'submit' ] )
                                        && $request->getVal( 'format' ) === 
'application/json';
@@ -29,7 +29,8 @@
                                        // Make it not be selected when editing 
json.
                                        $links['views']['edit']['class'] = 
false;
                                }
-                       } elseif ( $title->hasContentModel( 
'CollaborationHubContent' ) ) {
+                       }
+                       if ( $title->hasContentModel( 'CollaborationHubContent' 
) ) {
                                // Add feature
                                $links['actions']['addnewfeature'] = [
                                        'class' => '',
diff --git a/CollaborationKit.i18n.magic.php b/CollaborationKit.i18n.magic.php
old mode 100644
new mode 100755
diff --git a/Gruntfile.js b/Gruntfile.js
old mode 100644
new mode 100755
diff --git a/composer.json b/composer.json
old mode 100644
new mode 100755
diff --git a/extension.json b/extension.json
old mode 100644
new mode 100755
index 335ff7e..ebc1cac
--- a/extension.json
+++ b/extension.json
@@ -20,13 +20,14 @@
                "CollaborationKitHooks": "CollaborationKit.hooks.php",
                "CollaborationHubContent": 
"includes/content/CollaborationHubContent.php",
                "CollaborationHubContentHandler": 
"includes/content/CollaborationHubContentHandler.php",
+               "CollaborationHubContentEditor": 
"includes/CollaborationHubContentEditor.php",
                "CollaborationHubTOC": 
"includes/content/CollaborationHubTOC.php",
                "CollaborationKitIcon": 
"includes/content/CollaborationKitIcon.php",
                "CollaborationListContent": 
"includes/content/CollaborationListContent.php",
                "CollaborationListContentHandler": 
"includes/content/CollaborationListContentHandler.php",
+               "CollaborationListContentEditor": 
"includes/CollaborationListContentEditor.php",
                "SpecialCreateCollaborationHub": 
"includes/SpecialCreateCollaborationHub.php",
                "SpecialCreateHubFeature": 
"includes/SpecialCreateHubFeature.php",
-               "CollaborationListContentEditor": 
"includes/CollaborationListContentEditor.php",
                "ResourceLoaderListStyleModule": 
"includes/ResourceLoaderListStyleModule.php"
        },
        "ContentHandlers": {
@@ -63,7 +64,8 @@
                        "CollaborationListContent::onArticleViewHeader"
                ],
                "CustomEditor": [
-                       "CollaborationListContent::onCustomEditor"
+                       "CollaborationListContent::onCustomEditor",
+                       "CollaborationHubContent::onCustomEditor"
                ],
                "OutputPageBeforeHTML": [
                        "CollaborationKitHooks::onOutputPageBeforeHTML"
diff --git a/i18n/en.json b/i18n/en.json
old mode 100644
new mode 100755
index 806b387..2e9f509
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -61,6 +61,12 @@
        "collaborationkit-list-newitem-description": "Description (optional)",
        "collaborationkit-listedit-description": "Description",
        "collaborationkit-listedit-list": "List items",
+       "collaborationkit-hubedit-displayname": "Name to display",
+       "collaborationkit-hubedit-introduction": "Introduction",
+       "collaborationkit-hubedit-footer": "Footer",
+       "collaborationkit-hubedit-image": "Hub image",
+       "collaborationkit-hubedit-colour": "Color",
+       "collaborationkit-hubedit-content": "Features",
        "collaborationkit-editjsontab": "Edit as JSON",
        "collaborationkit-hub-announcements-initial": "A new collaboration hub 
has been set up!",
        "collaborationkit-hub-members-description": "Our members are below. 
Those who have not edited in over a month are moved to the inactive section.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
old mode 100644
new mode 100755
index 5fb5b83..815b4a5
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -61,6 +61,12 @@
        "collaborationkit-list-newitem-description": "Label for description 
field on new item dialog for CollaborationKit lists",
        "collaborationkit-listedit-description": "Header on edit page for the 
list description text box",
        "collaborationkit-listedit-list": "Header on edit page for the main 
body of the list",
+       "collaborationkit-hubedit-displayname": "Field label for the display 
name field on the edit page for hubs",
+       "collaborationkit-hubedit-introduction": "Field label for the 
introduction text on the edit page for hubs",
+       "collaborationkit-hubedit-footer": "Field label for the footer text on 
the edit page for hubs",
+       "collaborationkit-hubedit-image": "Field label for the image field on 
the edit page for hubs",
+       "collaborationkit-hubedit-colour": "Field label for the color field on 
the edit page for hubs",
+       "collaborationkit-hubedit-content": "Field label for the features field 
on the edit page for hubs",
        "collaborationkit-editjsontab": "Text of the tab used to edit the page 
as JSON.",
        "collaborationkit-hub-announcements-initial": "The initial announcement 
posted when a Collaboration Hub is created.",
        "collaborationkit-hub-members-description": "The default description 
for the member list generated on a new Collaboration Hub.",
diff --git a/includes/ApiEditCollaborationHub.php 
b/includes/ApiEditCollaborationHub.php
old mode 100644
new mode 100755
diff --git a/includes/CollaborationHubContentEditor.php 
b/includes/CollaborationHubContentEditor.php
new file mode 100755
index 0000000..bf2b2ca
--- /dev/null
+++ b/includes/CollaborationHubContentEditor.php
@@ -0,0 +1,198 @@
+<?php
+/**
+ * @todo Unicode unsafe browsers?
+ */
+class CollaborationHubContentEditor extends EditPage {
+
+       function __construct( $page ) {
+               parent::__construct( $page );
+               // Make human readable the default format for editing, but still
+               // save as json. Can be overriden by url 
?format=application/json param.
+               $this->contentFormat = 
CollaborationHubContentHandler::FORMAT_WIKI;
+       }
+
+       /**
+        * Build and return the aossociative array for the content source field.
+        * @param $mapping array
+        * @return array
+        */
+       protected function getOptions( $mapping ) {
+               $options = [];
+               foreach ( $mapping as $msgKey => $option ) {
+                       $options[] = [ 'label' => wfMessage( $msgKey 
)->escaped(), 'data' => $option ];
+               }
+               return $options;
+       }
+
+       /**
+        * @param $parts array
+        * @return array
+        */
+       protected function getFormFields( $parts ) {
+
+               $fields = [
+                       // Display name can be different from page title
+                       'display_name' => new OOUI\FieldLayout (
+                               new OOUI\TextInputWidget( [
+                                       'name' => 'wpCollabHubDisplayName',
+                                       'id' => 'wpCollabHubDisplayName',
+                                       'type' => 'text',
+                                       'class' => 'mw-ck-displayinput',
+                                       'value' => $parts[0]
+                                       ] ),
+                               [
+                                       'label' => wfMessage( 
'collaborationkit-hubedit-displayname' )->text(),
+                                       'align' => 'top'
+                               ] ),
+                       'introduction' => new OOUI\FieldLayout (
+                               new OOUI\TextInputWidget( [
+                                       'multiline' => true,
+                                       'name' => 'wpCollabHubIntroduction',
+                                       'id' => 'wpCollabHubIntroduction',
+                                       'type' => 'textarea',
+                                       'rows' => 5,
+                                       'class' => 'mw-ck-introductioninput',
+                                       'value' => $parts[1]
+                                       ] ),
+                               [
+                                       'label' => wfMessage( 
'collaborationkit-hubedit-introduction' )->text(),
+                                       'align' => 'top'
+                               ] ),
+                       'footer' => new OOUI\FieldLayout (
+                               new OOUI\TextInputWidget( [
+                                       'multiline' => true,
+                                       'name' => 'wpCollabHubFooter',
+                                       'id' => 'wpCollabHubFooter',
+                                       'type' => 'textarea',
+                                       'rows' => 5,
+                                       'class' => 'mw-ck-introductioninput',
+                                       'value' => $parts[2]
+                                       ] ),
+                               [
+                                       'label' => wfMessage( 
'collaborationkit-hubedit-footer' )->text(),
+                                       'align' => 'top'
+                               ] ),
+                       // Hub image/icon thing
+                       'image' => new OOUI\FieldLayout (
+                               new OOUI\TextInputWidget( [
+                                       'name' => 'wpCollabHubImage',
+                                       'id' => 'wpCollabHubImage',
+                                       'type' => 'text',
+                                       'class' => 'mw-ck-iconinput',
+                                       'value' => $parts[3]
+                                       ] ),
+                               [
+                                       'label' => wfMessage( 
'collaborationkit-hubedit-image' )->text(),
+                                       'align' => 'top'
+                               ] ),
+               ];
+               // Colours for the hub styles
+               $colours = [];
+               foreach ( CollaborationHubContent::getThemeColours() as $colour 
) {
+                       $colours[ 'collaborationkit-' . $colour ] = $colour;
+               }
+
+               if ( $parts[4] == '' ) {
+                       $selectedColour = 'blue5';
+               } else {
+                       $selectedColour = $parts[4];
+               }
+
+               $fields['colour'] = new OOUI\FieldLayout (
+                       new OOUI\DropdownInputWidget( [
+                               'name' => 'wpCollabHubColour',
+                               'id' => 'wpCollabHubColour',
+                               'type' => 'select',
+                               'options' => $this->getOptions( $colours ),
+                               'class' => 'mw-ck-colourinput',
+                               'value' => $selectedColour
+                               ] ),
+                       [
+                               'label' => wfMessage( 
'collaborationkit-hubedit-colour' )->text(),
+                               'align' => 'top'
+                       ] );
+
+               if ( $parts[5] == '' ) {
+                       $includedContent = '';
+               } else {
+                       $includedContent = $parts[5];
+               }
+
+               $fields['content'] = new OOUI\FieldLayout (
+                       new OOUI\TextInputWidget( [
+                               'multiline' => true,
+                               'name' => 'wpCollabHubContent',
+                               'id' => 'wpCollabHubContent',
+                               'type' => 'textarea',
+                               'rows' => 10,
+                               'class' => 'mw-ck-introductioninput',
+                               'value' => $includedContent
+                               ] ),
+                       [
+                               'label' => wfMessage( 
'collaborationkit-hubedit-content' )->text(),
+                               'align' => 'top'
+                       ] );
+
+               return $fields;
+       }
+
+       protected function showContentForm() {
+               if ( $this->contentFormat !== 
CollaborationHubContentHandler::FORMAT_WIKI ) {
+                       return parent::showContentForm();
+               }
+
+               $parts = explode( CollaborationHubContent::HUMAN_DESC_SPLIT, 
$this->textbox1, 6 );
+               if ( count( $parts ) !== 6 ) {
+                       return parent::showContentForm();
+               }
+
+               $out = RequestContext::getMain()->getOutput();
+               $pageLang = $this->getTitle()->getPageLanguage();
+
+               $formFields = $this->getFormFields( $parts );
+
+               $htmlForm = new OOUI\FieldsetLayout( [ 'items' => $formFields ] 
);
+               $out->enableOOUI();
+               $out->addHtml( $htmlForm );
+       }
+
+       static function trySubmit( $formData ) {
+               // No need to re-invent the validation wheel,
+               // so just returning true and moving on.
+               return true;
+       }
+
+       protected function importContentFormData( &$request ) {
+               $format = $request->getVal( 'format', 
CollaborationListContentHandler::FORMAT_WIKI );
+               if ( $format !== CollaborationListContentHandler::FORMAT_WIKI ) 
{
+                       return parent::importContentFormData( $request );
+               }
+               $displayname = trim( $request->getText( 
'wpCollabHubDisplayName' ) );
+               if ( $displayname === null ) {
+                       // Only 1 textbox?
+                       return parent::importContentFormData( $request );
+               }
+
+               $introduction = trim( $request->getText( 
'wpCollabHubIntroduction', '' ) );
+               $footer = trim( $request->getText( 'wpCollabHubFooter', '' ) );
+               $image = trim( $request->getText( 'wpCollabHubImage', '' ) );
+               $colour = trim( $request->getText( 'wpCollabHubColour', '' ) );
+               $content = trim( $request->getText( 'wpCollabHubContent', '' ) 
);
+               
+               return $displayname
+                       . CollaborationHubContent::HUMAN_DESC_SPLIT
+                       . $introduction
+                       . CollaborationHubContent::HUMAN_DESC_SPLIT
+                       . $footer
+                       . CollaborationHubContent::HUMAN_DESC_SPLIT
+                       . $image
+                       . CollaborationHubContent::HUMAN_DESC_SPLIT
+                       . $colour
+                       . CollaborationHubContent::HUMAN_DESC_SPLIT
+                       . $content;
+       }
+
+       protected function getDisplayFormat() {
+               return 'ooui';
+       }
+}
diff --git a/includes/CollaborationListContentEditor.php 
b/includes/CollaborationListContentEditor.php
old mode 100644
new mode 100755
diff --git a/includes/ResourceLoaderListStyleModule.php 
b/includes/ResourceLoaderListStyleModule.php
old mode 100644
new mode 100755
diff --git a/includes/SpecialCreateCollaborationHub.php 
b/includes/SpecialCreateCollaborationHub.php
old mode 100644
new mode 100755
diff --git a/includes/SpecialCreateHubFeature.php 
b/includes/SpecialCreateHubFeature.php
old mode 100644
new mode 100755
diff --git a/includes/content/CollaborationHubContent.php 
b/includes/content/CollaborationHubContent.php
old mode 100644
new mode 100755
index 48ade1d..44d1d7b
--- a/includes/content/CollaborationHubContent.php
+++ b/includes/content/CollaborationHubContent.php
@@ -24,6 +24,8 @@
  */
 class CollaborationHubContent extends JsonContent {
 
+       const HUMAN_DESC_SPLIT = "\n-----------------------\n";
+
        /** @var string */
        protected $displayName;
 
@@ -732,4 +734,165 @@
                // Nothing was found
                return null;
        }
+
+       public function convert( $toModel, $lossy = '' ) {
+               if ( $toModel === CONTENT_MODEL_WIKITEXT && $lossy === 'lossy' 
) {
+                       global $wgContLang;
+                       // using wgContLang is kind of icky. Maybe we should 
transclude
+                       // from mediawiki namespace, or give up on not 
splitting the
+                       // parser cache and just use {{int:... (?)
+                       $renderOpts = $this->getFullRenderListOptions();
+                       $text = $this->convertToWikitext( $wgContLang, 
$renderOpts );
+                       return ContentHandler::makeContent( $text, null, 
$toModel );
+               } elseif ( $toModel === CONTENT_MODEL_JSON ) {
+                       return ContentHandler::makeContent( 
$this->getNativeData(), null, $toModel );
+               }
+               return parent::convert( $toModel, $lossy );
+       }
+
+       /**
+        * Convert JSON to markup that's easier for humans.
+        */
+       public function convertToHumanEditable() {
+               $this->decode();
+
+               $output = $this->displayName;
+               $output .= self::HUMAN_DESC_SPLIT;
+               $output .= $this->introduction;
+               $output .= self::HUMAN_DESC_SPLIT;
+               $output .= $this->footer;
+               $output .= self::HUMAN_DESC_SPLIT;
+               $output .= $this->image;
+               $output .= self::HUMAN_DESC_SPLIT;
+               $output .= $this->themeColour;
+               $output .= self::HUMAN_DESC_SPLIT;
+               $output .= $this->getHumanEditableContent();
+               return $output;
+       }
+
+       /**
+        * Get the list of items in human editable form.
+        *
+        * @todo Should this be i18n-ized?
+        */
+       public function getHumanEditableContent() {
+               $this->decode();
+
+               $out = '';
+               foreach ( $this->content as $item ) {
+                       $out .= $this->escapeForHumanEditable( $item['title'] );
+                       if ( isset ( $item['image'] ) ) {
+                               $out .= "|image=" . 
$this->escapeForHumanEditable( $item['image'] );
+                       }
+                       if ( isset( $item['displayTitle'] ) ) {
+                               $out .= "|display_title=" . 
$this->escapeForHumanEditable( $item['displayTitle'] );
+                       }
+                       if ( substr( $out, -1 ) === '|' ) {
+                               $out = substr( $out, 0, strlen( $out ) - 1 );
+                       }
+                       $out .= "\n";
+               }
+               return $out;
+       }
+
+       /**
+        * Escape characters used as separators in human editable mode.
+        *
+        * @todo Unclear if this is best approach. Alternative might be
+        *  to use &#xA; Or an obscure unicode character like ␊ (U+240A).
+        */
+       private function escapeForHumanEditable( $text ) {
+               if ( strpos( $text, '{{!}}' ) !== false ) {
+                       // Maybe we should use \| too, but that's not MW like.
+                       throw new MWContentSerializationException( "{{!}} in 
content" );
+               }
+               if ( strpos( $text, "\\\n" ) !== false ) {
+                       // @todo We don't currently handle this properly.
+                       throw new MWContentSerializationException( "Line ending 
with a \\" );
+               }
+               $text = strtr( $text, [
+                       "\n" => '\n',
+                       '\n'=> '\\\\n',
+                       '|' => '{{!}}'
+               ] );
+               return $text;
+       }
+
+       private static function unescapeForHumanEditable( $text ) {
+               $text = strtr( $text, [
+                       '\\\\n'=> "\\n",
+                       '\n' => "\n",
+                       '{{!}}' => '|'
+               ] );
+               return $text;
+       }
+
+       /**
+        * Convert from human editable form into a (php) array
+        *
+        * @param $text String text to convert
+        * @return Array Result of converting it to native form
+        */
+       public static function convertFromHumanEditable( $text ) {
+               $res = [];
+               $split = explode( self::HUMAN_DESC_SPLIT, $text );
+
+               $res['display_name'] = $split[0];
+               $res['introduction'] = $split[1];
+               $res['footer'] = $split[2];
+               $res['image'] = $split[3];
+               $res['colour'] = $split[4];
+               $content = $split[5];
+               if ( trim( $content) == '' ) {
+                       $res['content'] = [];
+               } else {
+                       $listLines = explode( "\n", $content );
+                       foreach ( $listLines as $line ) {
+                               $res['content'][] = 
self::convertFromHumanEditableItemLine( $line );
+                       }
+               }
+               return $res;
+       }
+
+       private static function convertFromHumanEditableItemLine( $line ) {
+               $parts = explode( "|", $line );
+               $parts = array_map( [ __CLASS__, 'unescapeForHumanEditable' ], 
$parts );
+               $itemRes = [ 'title' => $parts[0] ];
+               if ( count( $parts ) > 1 ) {
+                       $parts = array_slice( $parts, 1 );
+                       foreach ( $parts as $part ) {
+                               list( $key, $value ) = explode( '=', $part );
+                               switch ( $key ) {
+                               case 'image':
+                               case 'display_title':
+                                       $itemRes[$key] = $value;
+                                       break;
+                               default:
+                                       $context = wfEscapeWikiText( substr( 
$part, 30 ) );
+                                       if ( strlen( $context ) === 30 ) {
+                                               $context .= '...';
+                                       }
+                                       throw new 
MWContentSerializationException(
+                                               "Unrecognized option for list 
item:" .
+                                               wfEscapeWikiText( $key )
+                                       );
+                               }
+                       }
+               }
+               return $itemRes;
+       }
+
+       /**
+        * Hook to use custom edit page for lists
+        *
+        * @param $page Page
+        * @param $user User
+        */
+       public static function onCustomEditor( Page $page, User $user ) {
+               if ( $page->getContentModel() === __CLASS__ ) {
+                       $editor = new CollaborationHubContentEditor( $page );
+                       $editor->edit();
+                       return false;
+               }
+       }
 }
diff --git a/includes/content/CollaborationHubContentHandler.php 
b/includes/content/CollaborationHubContentHandler.php
old mode 100644
new mode 100755
index 118c380..ab4c5d4
--- a/includes/content/CollaborationHubContentHandler.php
+++ b/includes/content/CollaborationHubContentHandler.php
@@ -2,8 +2,19 @@
 
 class CollaborationHubContentHandler extends TextContentHandler {
 
-       public function __construct( $modelId = 'CollaborationHubContent' ) {
-               parent::__construct( $modelId );
+       const FORMAT_WIKI = 'text/x-collabkit';
+
+       public function __construct(
+               $modelId = 'CollaborationHubContent',
+               $formats = [ CONTENT_FORMAT_JSON, CONTENT_FORMAT_TEXT, 
self::FORMAT_WIKI ]
+       ) {
+               // text/x-collabkit is a format for lists similar to <gallery>.
+               // CONTENT_FORMAT_TEXT is for back-compat with old revs. Could 
be removed.
+
+               // @todo Ideally, we'd have the preferred format for editing be 
self::FORMAT_WIKI
+               // and the preferred format for db be CONTENT_FORMAT_JSON. 
Unclear if that's
+               // possible.
+               parent::__construct( $modelId, $formats );
        }
 
        /**
@@ -22,19 +33,24 @@
                return false;
        }
 
-       /**
-        * @param $text string
-        * @param $format string
-        * @return CollaborationHubContent
-        * @throws MWContentSerializationException
-        */
        public function unserializeContent( $text, $format = null ) {
                $this->checkFormat( $format );
+               if ( $format === self::FORMAT_WIKI ) {
+                       $data = 
CollaborationHubContent::convertFromHumanEditable( $text );
+                       $text = FormatJson::encode( $data );
+               }
                $content = new CollaborationHubContent( $text );
                // Deliberately not validating at this step; validation is done 
later.
                return $content;
        }
 
+       public function serializeContent( Content $content, $format = null ) {
+               if ( $format === self::FORMAT_WIKI ) {
+                       return $content->convertToHumanEditable();
+               }
+               return parent::serializeContent( $content, $format );
+       }
+
        /**
         * @return CollaborationHubContent
         */
diff --git a/includes/content/CollaborationHubContentSchema.php 
b/includes/content/CollaborationHubContentSchema.php
old mode 100644
new mode 100755
diff --git a/includes/content/CollaborationHubDiffEngine.php 
b/includes/content/CollaborationHubDiffEngine.php
old mode 100644
new mode 100755
diff --git a/includes/content/CollaborationHubTOC.php 
b/includes/content/CollaborationHubTOC.php
old mode 100644
new mode 100755
diff --git a/includes/content/CollaborationKitIcon.php 
b/includes/content/CollaborationKitIcon.php
old mode 100644
new mode 100755
diff --git a/includes/content/CollaborationListContent.php 
b/includes/content/CollaborationListContent.php
old mode 100644
new mode 100755
diff --git a/includes/content/CollaborationListContentHandler.php 
b/includes/content/CollaborationListContentHandler.php
old mode 100644
new mode 100755
diff --git a/includes/content/CollaborationListContentSchema.php 
b/includes/content/CollaborationListContentSchema.php
old mode 100644
new mode 100755
diff --git a/modules/ext.CollaborationKit.hub.styles.less 
b/modules/ext.CollaborationKit.hub.styles.less
old mode 100644
new mode 100755
diff --git a/modules/ext.CollaborationKit.hub.subpage.styles.less 
b/modules/ext.CollaborationKit.hub.subpage.styles.less
old mode 100644
new mode 100755
diff --git a/modules/ext.CollaborationKit.list.edit.js 
b/modules/ext.CollaborationKit.list.edit.js
old mode 100644
new mode 100755
diff --git a/modules/ext.CollaborationKit.list.styles.less 
b/modules/ext.CollaborationKit.list.styles.less
old mode 100644
new mode 100755
diff --git a/modules/ext.CollaborationKit.mixins.less 
b/modules/ext.CollaborationKit.mixins.less
old mode 100644
new mode 100755
diff --git a/modules/images/blot.svg b/modules/images/blot.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/LICENSE b/modules/images/icons/LICENSE
old mode 100644
new mode 100755
diff --git a/modules/images/icons/addimage.svg 
b/modules/images/icons/addimage.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/addmapmarker.svg 
b/modules/images/icons/addmapmarker.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/addquote.svg 
b/modules/images/icons/addquote.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/bell.svg b/modules/images/icons/bell.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/book.svg b/modules/images/icons/book.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/circleline.svg 
b/modules/images/icons/circleline.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/circlestar.svg 
b/modules/images/icons/circlestar.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/circletriangle.svg 
b/modules/images/icons/circletriangle.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/circlex.svg b/modules/images/icons/circlex.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/clock.svg b/modules/images/icons/clock.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/community.svg 
b/modules/images/icons/community.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/contents.svg 
b/modules/images/icons/contents.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/die.svg b/modules/images/icons/die.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/discussion.svg 
b/modules/images/icons/discussion.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/download.svg 
b/modules/images/icons/download.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/edit.svg b/modules/images/icons/edit.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/editprotected.svg 
b/modules/images/icons/editprotected.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/eye.svg b/modules/images/icons/eye.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/flag.svg b/modules/images/icons/flag.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/funnel.svg b/modules/images/icons/funnel.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/gallery.svg b/modules/images/icons/gallery.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/gear.svg b/modules/images/icons/gear.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/heart.svg b/modules/images/icons/heart.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/icons-full.svg 
b/modules/images/icons/icons-full.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/image.svg b/modules/images/icons/image.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/journal.svg b/modules/images/icons/journal.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/key.svg b/modules/images/icons/key.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/link.svg b/modules/images/icons/link.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/lock.svg b/modules/images/icons/lock.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/mail.svg b/modules/images/icons/mail.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/map.svg b/modules/images/icons/map.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/mapmarker.svg 
b/modules/images/icons/mapmarker.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/menu.svg b/modules/images/icons/menu.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/message.svg b/modules/images/icons/message.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/messagenew.svg 
b/modules/images/icons/messagenew.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/messagescary.svg 
b/modules/images/icons/messagescary.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/move.svg b/modules/images/icons/move.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/newspaper.svg 
b/modules/images/icons/newspaper.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/nowiki.svg b/modules/images/icons/nowiki.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/ol.svg b/modules/images/icons/ol.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/page.svg b/modules/images/icons/page.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/pagechecked.svg 
b/modules/images/icons/pagechecked.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/pageribbon.svg 
b/modules/images/icons/pageribbon.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/pagesearch.svg 
b/modules/images/icons/pagesearch.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/paperclip.svg 
b/modules/images/icons/paperclip.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/print.svg b/modules/images/icons/print.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/puzzlepiece.svg 
b/modules/images/icons/puzzlepiece.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/quotes.svg b/modules/images/icons/quotes.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/ribbon.svg b/modules/images/icons/ribbon.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/rocket.svg b/modules/images/icons/rocket.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/search.svg b/modules/images/icons/search.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/star.svg b/modules/images/icons/star.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/starmenu.svg 
b/modules/images/icons/starmenu.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/sun.svg b/modules/images/icons/sun.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/translate.svg 
b/modules/images/icons/translate.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/trash.svg b/modules/images/icons/trash.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/ul.svg b/modules/images/icons/ul.svg
old mode 100644
new mode 100755
diff --git a/modules/images/icons/user.svg b/modules/images/icons/user.svg
old mode 100644
new mode 100755
diff --git a/package.json b/package.json
old mode 100644
new mode 100755
diff --git a/phpcs.xml b/phpcs.xml
old mode 100644
new mode 100755
diff --git a/tests/phpunit/CollaborationHubContentHandlerTest.php 
b/tests/phpunit/CollaborationHubContentHandlerTest.php
old mode 100644
new mode 100755
diff --git a/tests/phpunit/CollaborationHubContentTest.php 
b/tests/phpunit/CollaborationHubContentTest.php
old mode 100644
new mode 100755

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I25a2a13fdd3675b28da43259f543d4edecbb8d4e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CollaborationKit
Gerrit-Branch: master
Gerrit-Owner: Harej <jamesmh...@gmail.com>

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

Reply via email to