Harej has uploaded a new change for review. https://gerrit.wikimedia.org/r/308497
Change subject: Special:CreateCollaborationHub: create members and announcement features and sign up project creator as first member. ...................................................................... Special:CreateCollaborationHub: create members and announcement features and sign up project creator as first member. Bug: T140995 Bug: T140994 Bug: T140180 Change-Id: Iad29c3ed367dc90e606e5d122a0af08c671e97a5 --- M i18n/en.json M i18n/qqq.json M includes/SpecialCreateCollaborationHub.php M includes/content/CollaborationHubContent.php M includes/content/CollaborationListContent.php M includes/content/CollaborationListContentHandler.php 6 files changed, 119 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CollaborationKit refs/changes/97/308497/1 diff --git a/i18n/en.json b/i18n/en.json index f7501e5..1feab00 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -41,11 +41,15 @@ "collaborationkit-listedit-description": "Description", "collaborationkit-listedit-list": "List items", "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.", "collaborationkit-hub-members-header": "Members", "collaborationkit-hub-members-signup": "Join Project", "collaborationkit-hub-members-view": "View full list", "collaborationkit-hub-missingpage-note": "This feature does not exist. You can create a new project feature using the button below.", "collaborationkit-hub-missingpage-create": "Create feature", + "collaborationkit-hub-pagetitle-members": "Members", + "collaborationkit-hub-pagetitle-announcements": "Announcements", "collaborationkit-hub-subpage-view": "View", "collaborationkit-hub-subpage-remove": "Remove feature", "collaborationkit-hub-edit-apierror": "API edit error: $1", diff --git a/i18n/qqq.json b/i18n/qqq.json index 3d02923..a59e42b 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -41,11 +41,15 @@ "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-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.", "collaborationkit-hub-members-header": "Members header for Collaboration Hub mainpages; also used for feature (subpage) name", "collaborationkit-hub-members-signup": "Label for the 'join' button in the members block", "collaborationkit-hub-members-view": "Label for the 'view all' button in the members block", "collaborationkit-hub-missingpage-note": "Note and helpt text for missing feature sections (subpages) on a collaboration hub mainpage", "collaborationkit-hub-missingpage-create": "Button label for creating a new feature (subpage)", + "collaborationkit-hub-pagetitle-members": "The title of the /Members subpage for a Collaboration Hub (without the leading slash)", + "collaborationkit-hub-pagetitle-announcements": "The title of the /Announcements subpage for a Collaboration Hub (without the leading slash)", "collaborationkit-hub-subpage-view": "View link label for subpages on Collaboration Hub mainpages", "collaborationkit-hub-subpage-remove": "Remove link label for subpages on Collaboration Hub mainpages", "collaborationkit-hub-edit-apierror": "Error message for API edit error", diff --git a/includes/SpecialCreateCollaborationHub.php b/includes/SpecialCreateCollaborationHub.php index c2397f1..064d838 100644 --- a/includes/SpecialCreateCollaborationHub.php +++ b/includes/SpecialCreateCollaborationHub.php @@ -156,6 +156,48 @@ return $result; } + $memberListTitle = Title::newFromText( $data['title'] . '/' . $this->msg( 'collaborationkit-hub-pagetitle-members' ) ); + if ( !$memberListTitle ) { + return Status::newFatal( 'collaborationkit-createhub-invalidtitle' ); + } + $memberResult = CollaborationListContentHandler::postMemberList( + $memberListTitle, + $this->msg( 'collaborationkit-createhub-editsummary' )->inContentLanguage()->plain(), + $this->getContext() + ); + + if ( !$memberResult->isGood() ) { + return $memberResult; + } + + $announcementsTitle = Title::newFromText( $data['title'] . '/' . $this->msg( 'collaborationkit-hub-pagetitle-announcements' ) ); + if ( !$announcementsTitle ) { + return Status::newFatal( 'collaborationkit-createhub-invalidtitle' ); + } + // Ensure that a valid context is provided to the API in unit tests + $context = $this->getContext(); + $der = new DerivativeContext( $context ); + $request = new DerivativeRequest( + $context->getRequest(), + [ + 'action' => 'edit', + 'title' => $announcementsTitle->getFullText(), + 'text' => "* " . $context->msg( 'collaborationkit-hub-announcements-initial' ) . " ~~~~~", + 'summary' => $context->msg( 'collaborationkit-createhub-editsummary' )->inContentLanguage()->plain(), + 'token' => $context->getUser()->getEditToken(), + ], + true // Treat data as POSTed + ); + $der->setRequest( $request ); + try { + $api = new ApiMain( $der, true ); + $api->execute(); + } catch ( UsageException $e ) { + return Status::newFatal( $context->msg( 'collaborationkit-hub-edit-apierror', + $e->getCodeString() ) ); + } + + // Once all the pages we want to create are created, we send them to the first one $this->getOutput()->redirect( $title->getFullUrl() ); return Status::newGood(); } diff --git a/includes/content/CollaborationHubContent.php b/includes/content/CollaborationHubContent.php index 19a1997..0147b07 100644 --- a/includes/content/CollaborationHubContent.php +++ b/includes/content/CollaborationHubContent.php @@ -13,7 +13,7 @@ * { * "title": "The title, generally a subpage; we'll force this later", * "image": "Image or icon to use", - "display_title": "What to show on the page (defaults to {{SUBPAGENAME}} otherwise)", + * "display_title": "What to show on the page (defaults to {{SUBPAGENAME}} otherwise)", * ... * }, * ... diff --git a/includes/content/CollaborationListContent.php b/includes/content/CollaborationListContent.php index 2b9d775..b6864fe 100644 --- a/includes/content/CollaborationListContent.php +++ b/includes/content/CollaborationListContent.php @@ -24,9 +24,12 @@ * "order": "numeric", // or potentially collation?? * "default": "string-Text here" // or "column-title", etc * }, - * ... * }, * "defaultsort": "sort-criteria name" // or "column-title" ?? what about multi-key sort?? + * "ismemberlist": true/false, // TODO, causes page to render totally differently + * "memberoptions": { // for future customizations + * ... + * } * } * "description": "Some arbitrary wikitext" *} @@ -108,7 +111,7 @@ /** * Format json * - * Do not escape < and > its unnecessary and ugly + * Do not escape < and > it's unnecessary and ugly * @return string */ public function beautifyJSON() { diff --git a/includes/content/CollaborationListContentHandler.php b/includes/content/CollaborationListContentHandler.php index 10e164d..a25da79 100644 --- a/includes/content/CollaborationListContentHandler.php +++ b/includes/content/CollaborationListContentHandler.php @@ -60,6 +60,30 @@ } /** + * @param string $username + * @return CollaborationListContent + */ + public static function makeMemberList( $username, $initialDescription ) { + $linkToUserpage = Title::makeTitleSafe( NS_USER, $username )->getPrefixedText(); + $newMemberList = [ + "items" => [ + [ + "title" => $linkToUserpage + ] + ], + "options" => [ + "ismemberlist" => true, + "memberoptions" => (object)[] + ], + "description" => "$initialDescription" + ]; + + $newMemberListJson = FormatJson::encode( $newMemberList, "\t", FormatJson::ALL_OK ); + + return new CollaborationListContent( $newMemberListJson ); + } + + /** * @return string */ protected function getContentClass() { @@ -90,6 +114,45 @@ public function supportsDirectApiEditing() { return true; } + + /** + * @param Title $title + * @param string $summary + * @param IContextSource $context + * @todo rework this to use a generic CollaborationList editor function once it exists + */ + public static function postMemberList( Title $title, $summary, IContextSource $context ) { + + $username = $context->getUser()->getName(); + $collabList = self::makeMemberList( + $username, + $context->msg( 'collaborationkit-hub-members-description' ) + ); + + // Ensure that a valid context is provided to the API in unit tests + $der = new DerivativeContext( $context ); + $request = new DerivativeRequest( + $context->getRequest(), + [ + 'action' => 'edit', + 'title' => $title->getFullText(), + 'contentmodel' => 'CollaborationListContent', + 'text' => $collabList->serialize(), + 'summary' => $summary, + 'token' => $context->getUser()->getEditToken(), + ], + true // Treat data as POSTed + ); + $der->setRequest( $request ); + try { + $api = new ApiMain( $der, true ); + $api->execute(); + } catch ( UsageException $e ) { + return Status::newFatal( $context->msg( 'collaborationkit-hub-edit-apierror', + $e->getCodeString() ) ); + } + return Status::newGood(); + } } -- To view, visit https://gerrit.wikimedia.org/r/308497 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iad29c3ed367dc90e606e5d122a0af08c671e97a5 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