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

Change subject: Embedding member list and announcements page in 
CollaborationHubContent pages.
......................................................................


Embedding member list and announcements page 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. It also embeds the 
/Announcements subpage where it exists.

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. However, in the JavaScript per-item editor, making changes 
to the first item results in that first item being duplicated.
* CollaborationListContent styles now show up on hub pages.
* Module styles are now property loaded (T144526)

Bug: T144526
Change-Id: I55d83e7032275371f88633b936634ef360fa3833
---
M i18n/en.json
M includes/content/CollaborationHubContent.php
M includes/content/CollaborationListContent.php
3 files changed, 135 insertions(+), 70 deletions(-)

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



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..c1c0409 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(
@@ -251,6 +250,12 @@
                        'div',
                        [ 'class' => 'wp-intro' ],
                        $this->getParsedIntroduction( $title, $options )
+               );
+               // get announcements
+               $html .= Html::rawElement(
+                       'div',
+                       [ 'class' => 'wp-announcements' ],
+                       $this->getParsedAnnouncements( $title, $options )
                );
                // get table of contents
                $html .= Html::rawElement(
@@ -278,6 +283,7 @@
                $output->addModuleStyles( 'ext.CollaborationKit.main' );
                $output->addModules( 'ext.CollaborationKit.icons' );
                $output->addModules( 'ext.CollaborationKit.blots' );
+               $output->addModules( 'ext.CollaborationKit.list.styles' );
                $output->setEnableOOUI( true );
        }
 
@@ -314,56 +320,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; padding-bottom: 1em;' ],
+                                                                               
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;
+               }
        }
 
        /**
@@ -377,6 +375,32 @@
                $tempOutput = $wgParser->parse( $this->getIntroduction(), 
$title, $options );
 
                return $tempOutput->getText();
+       }
+
+       /**
+        * Helper function for fillParserOutput
+        * @param $title Title
+        * @param $options ParserOptions
+        * @return string
+        */
+       protected function getParsedAnnouncements( Title $title, ParserOptions 
$options ) {
+               $announcementsSubpageName = wfMessage( 
'collaborationkit-hub-pagetitle-announcements' )->inContentLanguage()->text();
+               $announcementsTitle = Title::newFromText( $title->getFullText() 
. '/' . $announcementsSubpageName );
+               if ( $announcementsTitle->exists() ) {
+                       $announcementsWikiPage = WikiPage::factory( 
$announcementsTitle );
+                       $announcementsText = 
$announcementsWikiPage->getContent()->getParserOutput( $announcementsTitle 
)->getText();
+
+                       $announcementsEditLink = Html::rawElement(
+                                                                               
                                "a",
+                                                                               
                                [ 'href' => $announcementsTitle->getEditURL() ],
+                                                                               
                                wfMessage( 'edit' ) );
+
+                       $announcementsHeader = Html::rawElement(
+                                                                               
                        "h3",
+                                                                               
                        (object)[],
+                                                                               
                        $announcementsSubpageName . ' [' . 
$announcementsEditLink . ']' );
+                       return $announcementsHeader . $announcementsText;
+               }
        }
 
        /**
@@ -456,12 +480,14 @@
                                        $frame = 
$wgParser->getPreprocessor()->newFrame()->newChild( [], $spTitle );
                                        $node = $wgParser->preprocessToDom( 
$rawText, Parser::PTD_FOR_INCLUSION );
                                        $processedText = $frame->expand( $node, 
PPFrame::RECOVER_ORIG & ( ~PPFrame::NO_IGNORE ) );
-                                       $text = $wgParser->parse( 
$processedText, $title, $options )->getText();
+                                       $parsedWikitext = $wgParser->parse( 
$processedText, $title, $options );
+                                       $text = $parsedWikitext->getText();
+                                       $output->addModuleStyles( 
$parsedWikitext->getModuleStyles() );
                                } else {
                                        // Parse whatever (else) as whatever
                                        $contentOutput = 
$spContent->getParserOutput( $spTitle, $spRev, $options );
-
-                                       $text = $contentOutput->getText();
+                                       $output->addModuleStyles( 
$contentOutput->getModuleStyles() );
+                                       $text = $contentOutput->getRawText();
                                }
 
                                $html .= $text;
diff --git a/includes/content/CollaborationListContent.php 
b/includes/content/CollaborationListContent.php
index d08c202..382ccfe 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 );
@@ -553,6 +590,8 @@
                                        );
                                }
                        }
+               } else {
+                       $itemRes['notes'] = '';
                }
                return $itemRes;
        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I55d83e7032275371f88633b936634ef360fa3833
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/CollaborationKit
Gerrit-Branch: master
Gerrit-Owner: Harej <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: Isarra <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to