Merge "Support new topic tool on mobile"

This commit is contained in:
jenkins-bot 2021-11-05 16:01:14 +00:00 committed by Gerrit Code Review
commit 22f48be13b
5 changed files with 58 additions and 6 deletions

View file

@ -429,6 +429,7 @@
"LoadExtensionSchemaUpdates": "installer",
"ParserAfterParse": "parser",
"ParserAfterTidy": "parser",
"ArticleViewHeader": "page",
"BeforeDisplayNoArticleText": "page",
"BeforePageDisplay": "page",
"GetActionName": "page",

View file

@ -222,8 +222,7 @@ class HookUtils {
if ( $isMobile && (
!$dtConfig->get( 'DiscussionToolsEnableMobile' ) ||
// Still disable some features for now
$feature === self::TOPICSUBSCRIPTION ||
$feature === self::NEWTOPICTOOL
$feature === self::TOPICSUBSCRIPTION
) ) {
return false;
}
@ -234,6 +233,17 @@ class HookUtils {
return false;
}
// New topic tool is not available if __NONEWSECTIONLINK__ is set
// We may need to move this check to the client when we support
// launching the tool from other pages.
if ( $feature === self::NEWTOPICTOOL ) {
$services = MediaWikiServices::getInstance();
$props = $services->getPageProps()->getProperties( $title, 'nonewsectionlink' );
if ( isset( $props[ $title->getArticleId() ] ) ) {
return false;
}
}
// ?dtenable=1 overrides all user and title checks
$queryEnable = $output->getRequest()->getRawVal( 'dtenable' ) ?:
// Extra hack for parses from API, where this parameter isn't passed to derivative requests

View file

@ -18,17 +18,20 @@ use MediaWiki\Extension\DiscussionTools\CommentFormatter;
use MediaWiki\Extension\DiscussionTools\SubscriptionStore;
use MediaWiki\Hook\BeforePageDisplayHook;
use MediaWiki\Hook\OutputPageBeforeHTMLHook;
use MediaWiki\Page\Hook\ArticleViewHeaderHook;
use MediaWiki\Page\Hook\BeforeDisplayNoArticleTextHook;
use MediaWiki\User\UserNameUtils;
use MediaWiki\User\UserOptionsLookup;
use OOUI\ButtonWidget;
use OutputPage;
use ParserOutput;
use RequestContext;
use Skin;
use SpecialPage;
use VisualEditorHooks;
class PageHooks implements
ArticleViewHeaderHook,
BeforeDisplayNoArticleTextHook,
BeforePageDisplayHook,
GetActionNameHook,
@ -309,4 +312,34 @@ class PageHooks implements
return false;
}
/**
* @param Article $article
* @param bool|ParserOutput &$outputDone
* @param bool &$pcache
* @return bool|void
*/
public function onArticleViewHeader( $article, &$outputDone, &$pcache ) {
$context = $article->getContext();
$output = $context->getOutput();
if (
$output->getSkin()->getSkinName() === 'minerva' &&
HookUtils::isFeatureEnabledForOutput( $output, HookUtils::NEWTOPICTOOL ) &&
// No need to show the button when the empty state banner is shown
!HookUtils::shouldDisplayEmptyState( $context )
) {
// Minerva doesn't show a new topic button by default, unless the MobileFrontend
// talk page feature is enabled, but we shouldn't depend on code from there.
$output->enableOOUI();
$output->addHTML(
new ButtonWidget( [
'href' => $article->getTitle()->getLinkURL( [ 'action' => 'edit', 'section' => 'new' ] ),
// TODO: Make this a local message if the Minerva feature goes away
'label' => $context->msg( 'minerva-talk-add-topic' )->text(),
'flags' => [ 'progressive', 'primary' ],
'classes' => [ 'ext-discussiontools-init-new-topic' ]
] )
);
}
}
}

View file

@ -25,11 +25,10 @@ function ReplyLinksController( $pageContainer ) {
if ( $addSectionTab.length ) {
this.$addSectionLink = $addSectionTab.find( 'a' );
this.$addSectionLink.on( 'click keypress', this.onAddSectionLinkClickHandler );
// Handle events on all links that potentially open the new section interface,
// including links in the page content (from templates) or from gadgets.
this.$body.on( 'click keypress', 'a:not( [data-mw-comment] )', this.onAnyLinkClickHandler );
}
// Handle events on all links that potentially open the new section interface,
// including links in the page content (from templates) or from gadgets.
this.$body.on( 'click keypress', 'a:not( [data-mw-comment] )', this.onAnyLinkClickHandler );
}
}

View file

@ -173,10 +173,19 @@ span[ data-mw-comment-start ] {
}
}
.ext-discussiontools-init-new-topic {
margin-top: 1em;
}
.ext-discussiontools-emptystate {
display: flex;
justify-content: space-between;
.skin-minerva & {
// Add space between this and page-actions-menu in Minerva
margin-top: 1em;
}
> img {
width: 250px;
}