jenkins-bot has submitted this change and it was merged.

Change subject: Implement specialcreatecollaborationhub
......................................................................


Implement specialcreatecollaborationhub

Creates new hubs.

Change-Id: I6ad42f22f83798bf4c12aca4e0bad54550fe449f
---
M i18n/en.json
M i18n/qqq.json
M includes/SpecialCreateCollaborationHub.php
M includes/content/CollaborationHubContentHandler.php
4 files changed, 184 insertions(+), 18 deletions(-)

Approvals:
  Isarra: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index 382462a..23c972a 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -3,10 +3,11 @@
                "authors": [ "Isarra" ]
        },
        "colaborationkit-desc": "Extension for making form-based json hub 
things with automated workflows and stuff. More on this later when it exists.",
-       "collaborationkit-edit-invalidtitle": "Please specify a page that is 
part of a Collaboration Hub. An inputbox to facilitate this may be added later, 
but in the meantime, why are you even here?",
+       "collaborationkit-edit-invalidtitle": "Invalid title or incorrect 
content model of target",
        "editcollaborationhub": "Edit Collaboration Hub page",
        "editcollaborationhub-legend": "Edit Collaboration Hub",
        "createcollaborationhub": "Create new Collaboration Hub",
+       "createcollaborationhub-legend": "Create Collaboration Hub",
        "collaborationkit-edit-nopermission": "You do not have permission to 
edit this page.",
        "collaborationkit-edit-header": "You are editing a Collaboration Hub. 
Magic.",
        "collaborationkit-edit-pagetitle": "Editing $1",
@@ -16,6 +17,18 @@
        "collaborationkit-edit-description": "Description",
        "collaborationkit-edit-content": "Content",
        "collaborationkit-edit-summary": "Edit summary",
+       "collaborationkit-create-title": "Title",
+       "collaborationkit-create-page-name": "Display name",
+       "collaborationhub-create-new": "None",
+       "collaborationhub-create-import": "Wikitext",
+       "collaborationhub-create-clone": "Clone existing Collaboration Hub",
+       "collaborationkit-create-content": "Content import",
+       "collaborationkit-create-source": "Source",
+       "collaborationhub-create-invalidtitle": "The specified title is 
invalid",
+       "collaborationhub-create-exists": "A page already exists with the 
specified title, and there is no support yet for imports",
+       "collaborationhub-create-nopermission": "You do not have permission to 
create a hub with this title",
+       "collaborationhub-create-invalidsource": "The specified source cannot 
be used",
+       "collaborationhub-create-editsummary": "Create new Collaboration Hub",
        "collaborationhub-display-wikitext": "Generic wikitext page",
        "collaborationhub-display-subpage-list": "Index of pages",
        "collaborationhub-display-icon-list": "Block list with icons",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 31e175f..ae4242a 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -3,10 +3,11 @@
                "authors": [ "Isarra" ]
        },
        "colaborationkit-desc": 
"{{desc|name=CollaborationKit|url=https://www.mediawiki.org/wiki/Extension:CollaborationKit}}";,
-       "createcollaborationhub": "Header for Special:CreateCollaborationHub",
        "collaborationkit-edit-invalidtitle": "Error message shown instead of 
the form on Special:CreateCollaborationHub when an invalid title is provided",
        "editcollaborationhub": "Header for Special:EditCollaborationHub",
        "editcollaborationhub-legend": "Form legend for 
Special:EditCollaborationHub",
+       "createcollaborationhub": "Header for Special:CreateCollaborationHub",
+       "createcollaborationhub-legend": "Form legend for 
Special:CreateCollaborationHub",
        "collaborationkit-edit-nopermission": "Error message shown on 
Special:EditCollaborationHub when the user cannot edit the list",
        "collaborationkit-edit-header": "Introduction shown on 
Special:EditCollaborationHub",
        "collaborationkit-edit-pagetitle": "Replaces the page title on 
Special:EditCollaborationHub to mimic the title of action=edit",
@@ -16,6 +17,18 @@
        "collaborationkit-edit-description": "Label for the description 
textarea on Special:EditCollaborationHub",
        "collaborationkit-edit-content": "Label for the content textarea on 
Special:EditCollaborationHub",
        "collaborationkit-edit-summary": "Label for the edit summary input on 
Special:EditCollaborationHub",
+       "collaborationkit-create-title": "Label for target page title input on 
Special:CreateCollaborationHub",
+       "collaborationkit-create-page-name": "Label for page display name input 
on Special:CreateCollaborationHub",
+       "collaborationhub-create-new": "Select option for no import",
+       "collaborationhub-create-import": "Select option for importing from 
wikitext",
+       "collaborationhub-create-clone": "Select option for cloning an existing 
hub",
+       "collaborationkit-create-content": "Label for content import options 
select on Special:CreateCollaborationHub",
+       "collaborationkit-create-source": "Label for content import source page 
input Special:CreateCollaborationHub",
+       "collaborationhub-create-invalidtitle": "Error message for an invalid 
title",
+       "collaborationhub-create-exists": "Error message for attempting to 
create a page that already exists",
+       "collaborationhub-create-nopermission": "Error message for no 
permission to edit/create/whatever",
+       "collaborationhub-create-invalidsource": "Error message for an invalid 
title for the source import",
+       "collaborationhub-create-editsummary": "Edit summary for creating a new 
Collaboration Hub via Special:CreateCollaborationHub",
        "collaborationhub-display-wikitext": "Select option for wikitext",
        "collaborationhub-display-subpage-list": "Select option for page-list",
        "collaborationhub-display-icon-list": "Select option for icon-list",
diff --git a/includes/SpecialCreateCollaborationHub.php 
b/includes/SpecialCreateCollaborationHub.php
index a519d1f..282a890 100644
--- a/includes/SpecialCreateCollaborationHub.php
+++ b/includes/SpecialCreateCollaborationHub.php
@@ -1,30 +1,172 @@
 <?php
 
 /**
- * Form to create Collaboration Hubs (and maybe even migrate them later, but 
not yet)
+ * Form to create Collaboration Hubs + migrations/imports/clones
  * Based on code from MassMessage
  *
  * @file
  */
 
-class SpecialCreateCollaborationHub extends SpecialPage {
+class SpecialCreateCollaborationHub extends FormSpecialPage {
 
        public function __construct() {
                parent::__construct( 'CreateCollaborationHub' );
        }
 
-       /*
-       description of page
-       inputbox for a name
-               go: check if it already exists
-                       yes & is wikitext:
-                               warn that it already exists with link
-                               inputbox for new pagename for archive; button 
to convert
-                                       go: dump 'em on 
special:editcollaborationhub with some prefilled (possibly invisible) items
+       /**
+        * @param string $par
+        */
+       public function execute( $par ) {
+               $this->getOutput()->addModules( 'ext.CollaborationKit.edit' );
+               parent::execute( $par );
+       }
 
-                       yes & is collaborationhub: warn that it already exists 
with link; display original inputbox
+       /**
+        * @return array
+        */
+       protected function getFormFields() {
+               // TODO: Do an actual check based on stuff (page type not 
already set to 'main' with autofill, is an actual subpage)
+               // If this isn't possible, move this logic to js (but it should 
be?)
 
-                       no: dump 'em on special:editcollaborationhub with some 
prefilled (possibly invisible) items
-       */
+               // We know it's a subpage, so ignore mainpage options
+               $isSubpage = false;
+               // We know it's a mainpage, so ignore subpage options
+               $isMainpage = true;
+
+               $fields = array(
+                       // autofilled from how they got here, hopefully
+                       'title' => array(
+                               'type' => 'text',
+                               'label-message' => 
'collaborationkit-create-title',
+                       ),
+                       // Display name can be different from page title
+                       'display_name' => array(
+                               'type' => 'text',
+                               'label-message' => 
'collaborationkit-create-page-name',
+                       )
+               );
+
+               // Content source options
+               $fields['content_source'] = array(
+                       'type' => 'select',
+                       'options' => $this->getOptions( array(
+                               'collaborationhub-create-new' => 'new',
+                               'collaborationhub-create-import' => 'import',
+                               'collaborationhub-create-clone' => 'clone',
+                       ) ),
+                       'default' => 'new', // might want to change to clone 
from the default (TODO add a canned default as example and stuff)
+                       'label-message' => 'collaborationkit-create-content',
+               );
+               $fields['source'] = array(
+                       'type' => 'text',
+                       'label-message' => 'collaborationkit-create-source',
+               );
+
+               $fields['description'] = array(
+                       'type' => 'textarea',
+                       'rows' => 5,
+                       'label-message' => 'collaborationkit-edit-description',
+               );
+
+               return $fields;
+       }
+
+       /**
+        * Build and return the aossociative array for the content source field.
+        * @return array
+        */
+       protected function getOptions( $mapping ) {
+               $options = array();
+               foreach ( $mapping as $msgKey => $option ) {
+                       $options[$this->msg( $msgKey )->escaped()] = $option;
+               }
+               return $options;
+       }
+
+       /**
+        * @param array $data
+        * @return Status
+        */
+       public function onSubmit( array $data ) {
+               $title = Title::newFromText( $data['title'] );
+               if ( !$title ) {
+                       return Status::newFatal( 
'collaborationhub-create-invalidtitle' );
+               } elseif ( $title->exists() ) {
+                       // TODO: Option to import it to itself as target
+                       return Status::newFatal( 
'collaborationhub-create-exists' );
+               } elseif (
+                       !$title->userCan( 'edit' ) ||
+                       !$title->userCan( 'create' ) ||
+                       !$title->userCan( 'editcontentmodel' )
+               ) {
+                       return Status::newFatal( 
'collaborationhub-create-nopermission' );
+               }
+
+               $content = array();
+
+               // ACTUAL STUFF HERE
+               if ( $data['content_source'] !== 'new' ) { // Importing from 
wikitext
+                       $source = Title::newFromText( $data['source'] );
+                       if ( !$source ) {
+                               return Status::newFatal( 
'collaborationhub-create-invalidsource' );
+                       }
+
+                       if ( $data['content_source'] === 'clone' ) {
+                               // Copy another hub
+                               // Just copy some of the bits...
+
+                               // TODO prefill the actual content
+                       } elseif ( $data['content_source'] === 'import' ) {
+                               // Do some magic based on the source:
+                               // If wikiproject x project: get module list, 
recreate modules
+                               // If regular page: pull headers
+
+                               // TODO prefill the actual content
+                       }
+                       // Render preview
+               } else {
+
+                       // ...?
+               }
+
+               $title = Title::newFromText( $data['title'] );
+               if ( !$title ) {
+                       return Status::newFatal( 
'collaborationhub-create-invalidtitle' );
+               }
+
+               $result = CollaborationHubContentHandler::edit(
+                       $title,
+                       $data['display_name'],
+                       'main',
+                       'subpage-list',
+                       $data['description'],
+                       $content,
+                       $this->msg( 'collaborationhub-create-editsummary' 
)->inContentLanguage()->plain(),
+                       $this->getContext()
+               );
+
+               if ( !$result->isGood() ) {
+                       return $result;
+               }
+
+               $this->getOutput()->redirect( $title->getFullUrl() );
+               return Status::newGood();
+       }
+
+       public function onSuccess() {
+               // No-op: We have already redirected.
+       }
+
+       /**
+        * Set the form format to div instead of table
+        * @param HTMLForm $form
+        */
+       protected function alterForm( HTMLForm $form ) {
+               $form->setDisplayFormat( 'div' );
+       }
+
+       // Hide source input unless actually providing a source (not 'new')
+       // Autofill displayname based on title (same as title minus namespace 
by default)
+       // ...?
 
 }
diff --git a/includes/content/CollaborationHubContentHandler.php 
b/includes/content/CollaborationHubContentHandler.php
index e3329ad..2cc9dca 100644
--- a/includes/content/CollaborationHubContentHandler.php
+++ b/includes/content/CollaborationHubContentHandler.php
@@ -60,9 +60,7 @@
         * @param IContextSource $context The calling context
         * @return Status
         */
-       public static function edit( Title $title, $pageName, $pageType, 
$contentType, $description, $content, $summary,
-               IContextSource $context
-       ) {
+       public static function edit( Title $title, $pageName, $pageType, 
$contentType, $description, $content, $summary, IContextSource $context ) {
                $contentBlock = array(
                        'page_name' => $pageName,
                        'description' => $description

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I6ad42f22f83798bf4c12aca4e0bad54550fe449f
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/CollaborationKit
Gerrit-Branch: master
Gerrit-Owner: Isarra <[email protected]>
Gerrit-Reviewer: Isarra <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to