Harej has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/333434 )
Change subject: One-click project join from within the hub. ...................................................................... One-click project join from within the hub. Clicking the blue "Join" button on a hub will now have you join as a member just in one click. You are then taken to the member list. Once you join as a member, the blue "Join" member disappears. Going to the member page's action=edit remains as a no-JS fallback Change-Id: Iebbf8d2c1c06912f73a1f52f74c34fb42e78d9c3 --- M includes/content/CollaborationHubContent.php M modules/ext.CollaborationKit.colour.js M modules/ext.CollaborationKit.list.edit.js 3 files changed, 72 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CollaborationKit refs/changes/34/333434/1 diff --git a/includes/content/CollaborationHubContent.php b/includes/content/CollaborationHubContent.php index 2ea7cd1..edf956c 100644 --- a/includes/content/CollaborationHubContent.php +++ b/includes/content/CollaborationHubContent.php @@ -233,7 +233,7 @@ $html .= Html::rawElement( 'div', [ 'class' => 'mw-ck-hub-members' ], - $this->getMembersBlock( $title, $options ) + $this->getMembersBlock( $title, $options, $output ) ); // get parsed intro $html .= Html::rawElement( @@ -290,6 +290,9 @@ 'ext.CollaborationKit.blots', 'ext.CollaborationKit.list.styles' ] ); + $output->addModules( [ + 'ext.CollaborationKit.list.edit' + ] ); $output->setEnableOOUI( true ); } } @@ -320,7 +323,7 @@ * @param $options ParserOptions * @return string */ - protected function getMembersBlock( Title $title, ParserOptions $options ) { + protected function getMembersBlock( Title $title, ParserOptions $options, ParserOutput &$output ) { global $wgParser; $html = ''; @@ -333,6 +336,10 @@ $membersPageName = $title->getFullText() . '/' . wfMessage( 'collaborationkit-hub-pagetitle-members' )->inContentLanguage()->text(); $membersTitle = Title::newFromText( $membersPageName ); if ( $membersTitle->exists() ) { + + $membersPageID = $membersTitle->getArticleID(); + $output->addJsConfigVars( 'wgCollaborationKitAssociatedMemberList', $membersPageID ); + // rawElement is used because we don't want [edit] links or usual header behavior $html .= Html::rawElement( 'h3', @@ -362,7 +369,8 @@ $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' ] + 'flags' => [ 'primary', 'progressive' ], + 'classes' => [ 'mw-ck-members-join' ] ] ); OutputPage::setupOOUI(); diff --git a/modules/ext.CollaborationKit.colour.js b/modules/ext.CollaborationKit.colour.js index 6d777d0..64e8a18 100644 --- a/modules/ext.CollaborationKit.colour.js +++ b/modules/ext.CollaborationKit.colour.js @@ -86,7 +86,7 @@ ); // Set form value - $( 'div.mw-ck-colour-input select option[value=' + toAppend + ']' ) + $( 'div.mw-ck-colour input select option[value=' + toAppend + ']' ) .attr( 'selected', 'selected' ); dialog.close( { action: action } ); diff --git a/modules/ext.CollaborationKit.list.edit.js b/modules/ext.CollaborationKit.list.edit.js index 03da66b..cba46c0 100644 --- a/modules/ext.CollaborationKit.list.edit.js +++ b/modules/ext.CollaborationKit.list.edit.js @@ -32,10 +32,11 @@ /** * Find if the current user is already is in list. * + * @param {int} destinationPage The Page ID of the list if not the current page. * @return {boolean} */ - curUserIsInList = function curUserIsInList() { - var titleObj, escapedText, currentUser; + curUserIsInList = function ( destinationPage ) { + var titleObj, escapedText, currentUser, wrapper; currentUser = mw.config.get( 'wgUserName' ); if ( !currentUser ) { return false; @@ -44,9 +45,25 @@ escapedText = titleObj.getPrefixedText(); escapedText = escapedText.replace( /\\/g, '\\\\' ); escapedText = escapedText.replace( /"/g, '\\"' ); - query = '.mw-ck-list-item[data-collabkit-item-title="' + - escapedText + '"]'; - return $( query ).length > 0; + if ( destinationPage === undefined ) { + query = '.mw-ck-list-item[data-collabkit-item-title="' + + escapedText + '"]'; + return $( query ).length > 0; + } else { + new mw.Api().get( { + action: 'parse', + pageid: destinationPage + } ) + .done( function ( data ) { + newMemberList = data.parse.text[ '*' ]; + query = 'data-collabkit-item-title="' + + escapedText + '"'; + if ( newMemberList.search( query ) > -1 ) { + $( '.mw-ck-members-join' ).css( 'display', 'none' ); + } + } + ); + } }; /** @@ -85,8 +102,18 @@ } ); }; - addSelf = function () { - getCurrentJson( mw.config.get( 'wgArticleId' ), function ( res ) { + /** + * One-click project-joining button + * + * @param {int} destinationPage Page ID of member list, if different from current page + * @param {string} destinationUrl Full URL of member list, if different from current page + */ + addSelf = function ( destinationPage, destinationUrl ) { + if ( destinationPage === undefined ) { + destinationPage = mw.config.get( 'wgArticleId' ); + } + + getCurrentJson( destinationPage, function ( res ) { var index, i, curUserTitle, itemToAdd = {}; @@ -110,7 +137,11 @@ res.content.columns[ 0 ].items[ index ] = itemToAdd; res.summary = mw.msg( 'collaborationkit-list-add-self-summary', itemToAdd.title ); saveJson( res, function () { - location.reload(); + if ( destinationUrl === undefined ) { + location.reload(); + } else { + window.location = destinationUrl; + } } ); } ); @@ -517,7 +548,26 @@ }; $( function () { - var $list, buttonMsg; + var $list, buttonMsg, memberListPage; + + if ( mw.config.get( 'wgCollaborationKitAssociatedMemberList' ) ) { + memberListPage = mw.config.get( 'wgCollaborationKitAssociatedMemberList' ); + curUserIsInList( memberListPage ); // removes Join button if user already is member + new mw.Api().get( { + action: 'query', + prop: 'info', + inprop: 'url', + pageids: memberListPage + } ).done( function ( data ) { + memberListUrl = data.query.pages[ memberListPage ].fullurl; + $( '.mw-ck-members-join a' ) + .attr( 'href', memberListUrl ); + + $( '.mw-ck-members-join' ).on( 'click', function () { + addSelf( memberListPage, memberListUrl ); + } ) + } ) + } if ( !mw.config.get( 'wgEnableCollaborationKitListEdit' ) ) { // This page is not a list, or user does not have edit rights. @@ -670,7 +720,7 @@ new OO.ui.ButtonWidget( { label: mw.msg( 'collaborationkit-list-add-self' ), icon: 'add', - flags: 'constructive' + flags: [ 'constructive', 'primary' ] } ).on( 'click', addSelf ) .$element ) -- To view, visit https://gerrit.wikimedia.org/r/333434 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iebbf8d2c1c06912f73a1f52f74c34fb42e78d9c3 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