Harej has uploaded a new change for review. https://gerrit.wikimedia.org/r/313667
Change subject: Embedding member list in CollaborationHubContent pages. ...................................................................... Embedding member list in CollaborationHubContent pages. This embeds the /Members subpage where it exists and includes three random members. It also includes a button linking to the full list and a "join" button that just goes to action=edit on the members page. Also fixed: * An error occurred if you tried to randomize a list with only one entry. This is fixed; if the list only has one entry, the randomizer just returns the one-entry list. * Trying to add anything other than notes in the batch editor to entries that did not already have notes resulted in everything being interpreted as notes. This is now fixed in the batch editor. However, it is still a bug in the JavaScript per-item editor. Namely, if you try to edit an item without notes associated with it, it will create a duplicate entry. Change-Id: I55d83e7032275371f88633b936634ef360fa3833 --- M i18n/en.json M includes/content/CollaborationHubContent.php M includes/content/CollaborationListContent.php 3 files changed, 95 insertions(+), 67 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CollaborationKit refs/changes/67/313667/1 diff --git a/i18n/en.json b/i18n/en.json index ae14ca9..798bc7c 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -58,8 +58,8 @@ "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-header": "Meet our members!", + "collaborationkit-hub-members-signup": "Join", "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", diff --git a/includes/content/CollaborationHubContent.php b/includes/content/CollaborationHubContent.php index 53a819c..5c03484 100644 --- a/includes/content/CollaborationHubContent.php +++ b/includes/content/CollaborationHubContent.php @@ -226,7 +226,6 @@ // Dummy parse intro and footer to get categories and whatnot $output = $wgParser->parse( $this->getIntroduction() . $this->getFooter(), $title, $options, true, true, $revId ); - $html = ''; // set up hub with theme stuff $html .= Html::openElement( @@ -314,56 +313,48 @@ * @return string */ protected function getMembersBlock( Title $title, ParserOptions $options ) { - // deprecated; we need proper list handling to do this properly - /* - // Members - $membersTitle = Title::newFromText( $title->getFullText() . '/' . wfMessage( 'collaborationkit-hub-members-header' )->inContentLanguage()->text() ); - $membersTitleRev = $title ? Revision::newFromTitle( $membersTitle ) : null; - if ( $membersTitleRev ) { + global $wgParser; - $prependiture .= Html::openElement( - 'div', - [ 'id' => 'wp-header-members' ] - ); - $prependiture .= Html::element( - 'h2', - [], - wfmessage( 'collaborationkit-members-header' )->inContentLanguage()->text() - ); - $prependiture .= Html::rawElement( - 'div', - [], - Revision::newFromTitle( $membersTitle )->getContent()->generateList( $title, $options, $output ) - ); - - // BUTTONS - $membersSignupUrl = SpecialPage::getTitleFor( - 'EditCollaborationHub', - $membersTitle->getPrefixedUrl() - )->getLinkUrl(); - - $signupButton = new OOUI\ButtonWidget( [ - 'label' => wfMessage( 'collaborationkit-hub-members-signup' )->inContentLanguage()->text(), - 'href' => $membersSignupUrl, - 'id' => 'wp-signup', - 'flags' => [ 'progressive' ] - ] ); - $seeAllButton = new OOUI\ButtonWidget( [ - 'label' => wfMessage( 'collaborationkit-hub-members-view' )->inContentLanguage()->text(), - 'href' => $membersTitle->getLinkUrl(), - 'id' => 'wp-seeall' - ] ); - $prependiture .= Html::rawElement( - 'div', - [ 'id' => 'wp-members-buttons' ], - $signupButton . ' ' . $seeAllButton - ); - - $prependiture .= Html::closeElement( 'div' ); + $lang = $options->getTargetLanguage(); + if ( !$lang ) { + $lang = $title->getPageLanguage(); } - */ - return 'MEMBERS BLOCK HERE (PENDING T140178)'; + $membersPageName = $title->getFullText() . '/' . wfMessage( 'collaborationkit-hub-pagetitle-members' )->inContentLanguage()->text(); + $membersTitle = Title::newFromText( $membersPageName ); + if ( $membersTitle->exists() ) { + $membersContent = Revision::newFromTitle( $membersTitle )->getContent(); + $wikitext = $membersContent->convertToWikitext( + $lang, + [ + 'includeDesc' => false, + 'maxItems' => 3, + 'defaultSort' => 'random' + ] + ); + $membersListHtml = $wgParser->parse( $wikitext, $membersTitle, $options )->getText(); + + // rawElement is used because we don't want [edit] links or usual header behavior + $membersHeader = Html::rawElement( + 'h3', + [ 'style' => 'text-align: center;' ], + wfMessage( 'collaborationkit-hub-members-header' ) + ); + + $membersViewButton = new OOUI\ButtonWidget( [ + 'label' => wfMessage( 'collaborationkit-hub-members-view' )->inContentLanguage()->text(), + 'href' => $membersTitle->getLinkURL() + ] ); + $membersJoinButton = new OOUI\ButtonWidget( [ + 'label' => wfMessage( 'collaborationkit-hub-members-signup' )->inContentLanguage()->text(), + 'href' => $membersTitle->getEditURL(), // Going through editor is non-JS fallback + 'flags' => [ 'primary', 'progressive' ] + ] ); + + OutputPage::setupOOUI(); + $text = $membersHeader . $membersListHtml . $membersViewButton->toString() . $membersJoinButton->toString(); + return $text; + } } /** diff --git a/includes/content/CollaborationListContent.php b/includes/content/CollaborationListContent.php index d08c202..d0968b6 100644 --- a/includes/content/CollaborationListContent.php +++ b/includes/content/CollaborationListContent.php @@ -51,6 +51,23 @@ return false; } + private static function validateOption( $name, &$value ) { + $listSchema = include __DIR__ . '/CollaborationListContentSchema.php'; + + // Force intrepretation as boolean for certain options + if ( $name == "ismemberlist" || $name == "includedesc" ) { + $value = (bool)$value; + } + + // Set up a dummy CollaborationListContent array featuring the options being validated + $toValidate = [ + 'description' => '', + 'items' => [], + 'options' => [ $name => $value ] + ]; + return EventLogging::schemaValidate( $toValidate, $listSchema ); + } + /** * Format json * @@ -163,7 +180,7 @@ $text .= $this->getDescription() . "\n"; } if ( count( $this->items ) === 0 ) { - $text .= "<hr>\n{{mediawiki:collaborationkit-list-isempty}}\n"; + $text .= "{{mediawiki:collaborationkit-list-isempty}}\n"; return $text; } $curItem = 0; @@ -311,22 +328,24 @@ */ private function sortRandomly( &$items ) { $totItems = count( $items ); - $rand1 = mt_rand( 1, $totItems - 1 ); - $rand2 = mt_rand( 0, $totItems - 1 ); + if ( count( $items ) > 1 ) { // No point in randomizing if only one item + $rand1 = mt_rand( 1, $totItems - 1 ); + $rand2 = mt_rand( 0, $totItems - 1 ); - while ( $rand1 < $totItems - 1 && $rand1 % $totItems === 0 ) { - // Make rand1 relatively prime to $totItems. - $rand1++; - } - uksort( $items, function ( $a, $b ) use( $rand1, $rand2, $totItems ) { - $a2 = ( $a * $rand1 + $rand2 ) % $totItems; - $b2 = ( $b * $rand1 + $rand2 ) % $totItems; - if ( $a2 === $b2 ) { - // Really should not happen - return 0; + while ( $rand1 < $totItems - 1 && $rand1 % $totItems === 0 ) { + // Make rand1 relatively prime to $totItems. + $rand1++; } - return $a2 > $b2 ? 1 : -1; - } ); + uksort( $items, function ( $a, $b ) use( $rand1, $rand2, $totItems ) { + $a2 = ( $a * $rand1 + $rand2 ) % $totItems; + $b2 = ( $b * $rand1 + $rand2 ) % $totItems; + if ( $a2 === $b2 ) { + // Really should not happen + return 0; + } + return $a2 > $b2 ? 1 : -1; + } ); + } return $items; } @@ -386,6 +405,9 @@ $this->decode(); $ret = ''; foreach ( $this->options as $opt => $value ) { + if ( $opt == "memberoptions" ) { // this is an object which messes with the parsing + continue; // FIXME add special handling + } $ret .= $opt . '=' . $value . "\n"; } return $ret; @@ -402,7 +424,11 @@ $out = ''; foreach ( $this->items as $item ) { $out .= $this->escapeForHumanEditable( $item->title ); - $out .= "|" . $this->escapeForHumanEditable( $item->notes ); + if ( isset ( $item->notes ) ) { + $out .= "|" . $this->escapeForHumanEditable( $item->notes ); + } else { + $out .= "|"; + } if ( isset( $item->link ) ) { if ( $item->link === false ) { $out .= "|nolink"; @@ -479,6 +505,9 @@ if ( self::validateOption( $name, $value ) ) { $finalList[$name] = $value; } + if ( in_array( 'ismemberlist', $finalList ) ) { + $finalList['memberoptions'] = (object)[]; // dumb hack + } } return (object)$finalList; } @@ -521,7 +550,15 @@ $parts = array_map( [ __CLASS__, 'unescapeForHumanEditable' ], $parts ); $itemRes = [ 'title' => $parts[0] ]; if ( count( $parts ) > 1 ) { - $itemRes['notes'] = $parts[1]; + // If people are using batch editor, they might define an image etc. despite lack of a note + // This is to catch that and prevent weirdness. + $testExplosion = explode( "=", $parts[1] ); + if ( in_array( $testExplosion[0], [ 'image', 'link', 'tags', 'sortkey' ] ) ) { + $itemRes[ $testExplosion[0] ] = $testExplosion[1]; + $itemRes['notes'] = ''; + } else { + $itemRes['notes'] = $parts[1]; + } $parts = array_slice( $parts, 2 ); foreach ( $parts as $part ) { list( $key, $value ) = explode( '=', $part ); -- To view, visit https://gerrit.wikimedia.org/r/313667 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I55d83e7032275371f88633b936634ef360fa3833 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