2019-10-10 13:25:11 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DiscussionTools extension hooks
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
* @license MIT
|
|
|
|
*/
|
2019-09-26 07:06:56 +00:00
|
|
|
|
2021-01-29 18:36:04 +00:00
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
2020-05-14 22:44:49 +00:00
|
|
|
|
|
|
|
use Action;
|
2020-12-14 18:52:47 +00:00
|
|
|
use ExtensionRegistry;
|
2021-07-28 10:36:58 +00:00
|
|
|
use IContextSource;
|
2020-02-20 20:39:35 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-08-02 16:25:23 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2020-05-14 22:44:49 +00:00
|
|
|
use OutputPage;
|
|
|
|
use RequestContext;
|
2020-12-16 16:08:56 +00:00
|
|
|
use Title;
|
2020-02-20 20:39:35 +00:00
|
|
|
|
2021-01-29 18:36:04 +00:00
|
|
|
class HookUtils {
|
2021-04-08 12:30:28 +00:00
|
|
|
public const REPLYTOOL = 'replytool';
|
|
|
|
public const NEWTOPICTOOL = 'newtopictool';
|
|
|
|
public const SOURCEMODETOOLBAR = 'sourcemodetoolbar';
|
|
|
|
public const TOPICSUBSCRIPTION = 'topicsubscription';
|
2021-08-17 20:23:27 +00:00
|
|
|
public const AUTOTOPICSUB = 'autotopicsub';
|
|
|
|
|
2021-02-17 17:16:17 +00:00
|
|
|
/**
|
|
|
|
* @var string[] List of all sub-features. Will be used to generate:
|
|
|
|
* - Feature override global: $wgDiscussionTools_FEATURE
|
2021-03-13 14:39:39 +00:00
|
|
|
* - Body class: ext-discussiontools-FEATURE-enabled
|
2021-02-17 17:16:17 +00:00
|
|
|
* - User option: discussiontools-FEATURE
|
|
|
|
*/
|
|
|
|
public const FEATURES = [
|
2021-04-08 12:30:28 +00:00
|
|
|
self::REPLYTOOL,
|
|
|
|
self::NEWTOPICTOOL,
|
|
|
|
self::SOURCEMODETOOLBAR,
|
|
|
|
self::TOPICSUBSCRIPTION,
|
2021-08-17 20:23:27 +00:00
|
|
|
self::AUTOTOPICSUB,
|
2021-02-17 17:16:17 +00:00
|
|
|
];
|
|
|
|
|
2021-12-07 22:32:06 +00:00
|
|
|
protected static $propCache = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a title has a page prop, and use an in-memory cache to avoid extra queries
|
|
|
|
*
|
|
|
|
* @param Title $title Title
|
|
|
|
* @param string $prop Page property
|
|
|
|
* @return bool Title has page property
|
|
|
|
*/
|
|
|
|
public static function hasPagePropCached( Title $title, string $prop ): bool {
|
|
|
|
$id = $title->getArticleId();
|
|
|
|
if ( !isset( self::$propCache[ $id ] ) ) {
|
|
|
|
self::$propCache[ $id ] = [];
|
|
|
|
}
|
|
|
|
if ( !isset( self::$propCache[ $id ][ $prop ] ) ) {
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$props = $services->getPageProps()->getProperties( $title, $prop );
|
|
|
|
self::$propCache[ $id ][ $prop ] = isset( $props[ $id ] );
|
|
|
|
}
|
|
|
|
return self::$propCache[ $id ][ $prop ];
|
|
|
|
}
|
|
|
|
|
2019-10-10 19:11:07 +00:00
|
|
|
/**
|
2020-12-16 16:07:32 +00:00
|
|
|
* Check if a DiscussionTools feature is available to this user
|
2019-10-10 19:11:07 +00:00
|
|
|
*
|
2021-08-02 16:25:23 +00:00
|
|
|
* @param UserIdentity $user
|
2021-02-17 17:16:17 +00:00
|
|
|
* @param string|null $feature Feature to check for (one of static::FEATURES)
|
2020-12-16 16:07:32 +00:00
|
|
|
* Null will check for any DT feature.
|
2020-09-10 13:43:13 +00:00
|
|
|
* @return bool
|
2019-10-10 19:11:07 +00:00
|
|
|
*/
|
2021-08-02 16:25:23 +00:00
|
|
|
public static function isFeatureAvailableToUser( UserIdentity $user, ?string $feature = null ): bool {
|
2020-12-16 16:07:32 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$dtConfig = $services->getConfigFactory()->makeConfig( 'discussiontools' );
|
2020-09-10 13:43:13 +00:00
|
|
|
|
2020-12-16 16:07:32 +00:00
|
|
|
if ( !$dtConfig->get( 'DiscussionToolsEnable' ) ) {
|
2020-12-16 16:08:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-17 20:23:27 +00:00
|
|
|
if ( ( $feature === self::TOPICSUBSCRIPTION || $feature === self::AUTOTOPICSUB ) && !$user->isRegistered() ) {
|
2021-02-17 22:34:02 +00:00
|
|
|
// Users must be logged in to use topic subscription
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-16 16:07:32 +00:00
|
|
|
$optionsLookup = $services->getUserOptionsLookup();
|
|
|
|
|
2021-01-13 19:30:59 +00:00
|
|
|
if ( $feature ) {
|
2021-02-17 17:16:17 +00:00
|
|
|
// Feature-specific override
|
2021-01-13 19:30:59 +00:00
|
|
|
if ( $dtConfig->get( 'DiscussionTools_' . $feature ) !== 'default' ) {
|
|
|
|
// Feature setting can be 'available' or 'unavailable', overriding any BetaFeatures settings
|
|
|
|
return $dtConfig->get( 'DiscussionTools_' . $feature ) === 'available';
|
|
|
|
}
|
|
|
|
} else {
|
2021-02-17 17:16:17 +00:00
|
|
|
// Non-feature-specific override, check for any feature
|
|
|
|
foreach ( static::FEATURES as $feat ) {
|
|
|
|
if ( $dtConfig->get( 'DiscussionTools_' . $feat ) === 'available' ) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-13 19:30:59 +00:00
|
|
|
}
|
2020-12-14 18:52:47 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 16:07:32 +00:00
|
|
|
// No feature-specific override found.
|
|
|
|
|
2021-01-13 06:38:11 +00:00
|
|
|
if ( $dtConfig->get( 'DiscussionToolsBeta' ) ) {
|
|
|
|
$betaenabled = $optionsLookup->getOption( $user, 'discussiontools-betaenable', -1 );
|
|
|
|
if ( $betaenabled !== -1 ) {
|
|
|
|
// betaenable doesn't have a default value, so we can check
|
|
|
|
// for it being unset like this. If the user has explicitly
|
2021-03-09 21:20:03 +00:00
|
|
|
// enabled or disabled it, we should immediately return that.
|
2021-11-22 19:07:23 +00:00
|
|
|
return (bool)$betaenabled;
|
2021-01-13 06:38:11 +00:00
|
|
|
}
|
|
|
|
// Otherwise, being in the "test" group for this feature means
|
|
|
|
// it's effectively beta-enabled.
|
2021-02-17 17:16:17 +00:00
|
|
|
return static::determineUserABTestBucket( $user, $feature ) === 'test';
|
2021-01-13 06:38:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 16:07:32 +00:00
|
|
|
// Assume that if BetaFeature is turned off, or user has it enabled, that
|
|
|
|
// some features are available.
|
|
|
|
// If this isn't the case, then DiscussionToolsEnable should have been set to false.
|
2021-01-13 06:38:11 +00:00
|
|
|
return true;
|
2020-12-16 16:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a DiscussionTools feature is enabled by this user
|
|
|
|
*
|
2021-08-02 16:25:23 +00:00
|
|
|
* @param UserIdentity $user
|
2021-02-17 17:16:17 +00:00
|
|
|
* @param string|null $feature Feature to check for (one of static::FEATURES)
|
2020-12-16 16:07:32 +00:00
|
|
|
* Null will check for any DT feature.
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-08-02 16:25:23 +00:00
|
|
|
public static function isFeatureEnabledForUser( UserIdentity $user, ?string $feature = null ): bool {
|
2021-02-17 17:16:17 +00:00
|
|
|
if ( !static::isFeatureAvailableToUser( $user, $feature ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-16 16:07:32 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$optionsLookup = $services->getUserOptionsLookup();
|
2021-02-17 17:16:17 +00:00
|
|
|
if ( $feature ) {
|
2020-12-16 16:07:32 +00:00
|
|
|
// Check for a specific feature
|
2021-02-17 17:16:17 +00:00
|
|
|
return $optionsLookup->getOption( $user, 'discussiontools-' . $feature );
|
|
|
|
} else {
|
2020-12-16 16:07:32 +00:00
|
|
|
// Check for any feature
|
2021-02-17 17:16:17 +00:00
|
|
|
foreach ( static::FEATURES as $feat ) {
|
|
|
|
if ( $optionsLookup->getOption( $user, 'discussiontools-' . $feat ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-16 16:08:56 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 06:38:11 +00:00
|
|
|
/**
|
|
|
|
* Work out the A/B test bucket for the current user
|
|
|
|
*
|
2021-03-09 21:20:03 +00:00
|
|
|
* Checks whether the user has been enrolled in the last A/B test, if any was enabled.
|
|
|
|
*
|
|
|
|
* If the A/B test is enabled, and the user is eligible and not enrolled, it will enroll them.
|
2021-01-13 06:38:11 +00:00
|
|
|
*
|
2021-08-02 16:25:23 +00:00
|
|
|
* @param UserIdentity $user
|
2021-02-17 17:16:17 +00:00
|
|
|
* @param string|null $feature Feature to check for (one of static::FEATURES)
|
2021-01-13 06:38:11 +00:00
|
|
|
* Null will check for any DT feature.
|
|
|
|
* @return string 'test' if in the test group, 'control' if in the control group, or '' if they've
|
|
|
|
* never been in the test
|
|
|
|
*/
|
2021-12-01 14:53:20 +00:00
|
|
|
private static function determineUserABTestBucket( UserIdentity $user, ?string $feature = null ): string {
|
2021-01-13 06:38:11 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$optionsManager = $services->getUserOptionsManager();
|
|
|
|
$dtConfig = $services->getConfigFactory()->makeConfig( 'discussiontools' );
|
|
|
|
|
|
|
|
$abtest = $dtConfig->get( 'DiscussionToolsABTest' );
|
2021-12-10 07:21:33 +00:00
|
|
|
$abstate = $optionsManager->getOption( $user, 'discussiontools-abtest2' );
|
2021-03-09 21:20:03 +00:00
|
|
|
|
2021-01-13 06:38:11 +00:00
|
|
|
if (
|
2021-08-02 16:25:23 +00:00
|
|
|
$user->isRegistered() &&
|
2021-12-10 07:21:33 +00:00
|
|
|
$feature && $abtest == $feature
|
2021-01-13 06:38:11 +00:00
|
|
|
) {
|
|
|
|
// The A/B test is enabled, and the user is qualified to be in the
|
|
|
|
// test by being logged in.
|
2021-12-10 07:21:33 +00:00
|
|
|
if ( !$abstate && !$optionsManager->getOption( $user, 'discussiontools-newtopictool-opened' ) ) {
|
2021-01-13 06:38:11 +00:00
|
|
|
// Assign the user to a group. This is only being done to
|
|
|
|
// users who have never used the tool before, for which we're
|
2021-12-10 07:21:33 +00:00
|
|
|
// using the absence of discussiontools-newtopictool-opened.
|
2021-01-13 06:38:11 +00:00
|
|
|
$abstate = $user->getId() % 2 == 0 ? 'test' : 'control';
|
2021-12-10 07:21:33 +00:00
|
|
|
$optionsManager->setOption( $user, 'discussiontools-abtest2', $abstate );
|
2021-01-13 06:38:11 +00:00
|
|
|
$optionsManager->saveOptions( $user );
|
|
|
|
}
|
2021-12-10 07:21:33 +00:00
|
|
|
return $abstate;
|
2021-01-13 06:38:11 +00:00
|
|
|
}
|
2021-12-10 07:21:33 +00:00
|
|
|
return '';
|
2021-01-13 06:38:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 16:08:56 +00:00
|
|
|
/**
|
2020-12-16 16:07:32 +00:00
|
|
|
* Check if the tools are available for a given title
|
2020-12-16 16:08:56 +00:00
|
|
|
*
|
|
|
|
* @param Title $title
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public static function isAvailableForTitle( Title $title ): bool {
|
2021-04-26 17:39:01 +00:00
|
|
|
// Only wikitext pages (e.g. not Flow boards, special pages)
|
2020-09-10 13:43:13 +00:00
|
|
|
if ( $title->getContentModel() !== CONTENT_MODEL_WIKITEXT ) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-04-26 17:39:01 +00:00
|
|
|
if ( !$title->canExist() ) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-09-10 13:43:13 +00:00
|
|
|
|
2021-12-07 22:32:06 +00:00
|
|
|
$hasNewSectionLink = self::hasPagePropCached( $title, 'newsectionlink' );
|
2020-12-16 16:08:56 +00:00
|
|
|
|
2021-12-07 22:32:06 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
2020-12-16 16:07:32 +00:00
|
|
|
// Check that the page supports discussions.
|
|
|
|
// Treat pages with __NEWSECTIONLINK__ as talk pages (T245890)
|
|
|
|
return $hasNewSectionLink ||
|
2020-09-10 13:43:13 +00:00
|
|
|
// `wantSignatures` includes talk pages
|
2021-09-26 00:37:46 +00:00
|
|
|
$services->getNamespaceInfo()->wantSignatures( $title->getNamespace() );
|
2020-09-10 13:43:13 +00:00
|
|
|
// TODO: Consider not loading if forceHideNewSectionLink is true.
|
2020-12-16 16:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the tool is available on a given page
|
|
|
|
*
|
|
|
|
* @param OutputPage $output
|
2021-02-17 17:16:17 +00:00
|
|
|
* @param string|null $feature Feature to check for (one of static::FEATURES)
|
2020-12-16 16:07:32 +00:00
|
|
|
* Null will check for any DT feature.
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public static function isFeatureEnabledForOutput( OutputPage $output, ?string $feature = null ): bool {
|
2020-12-16 16:07:32 +00:00
|
|
|
// Don't show on edit pages, history, etc.
|
2021-07-28 10:36:58 +00:00
|
|
|
if ( $feature !== self::NEWTOPICTOOL && Action::getActionName( $output->getContext() ) !== 'view' ) {
|
2020-12-16 16:07:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = $output->getTitle();
|
|
|
|
// Don't show on pages without a Title
|
|
|
|
if ( !$title ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-15 19:45:05 +00:00
|
|
|
$isMobile = false;
|
2020-12-16 16:07:32 +00:00
|
|
|
if ( ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) ) {
|
|
|
|
$mobFrontContext = MediaWikiServices::getInstance()->getService( 'MobileFrontend.Context' );
|
2020-12-15 19:45:05 +00:00
|
|
|
$isMobile = $mobFrontContext->shouldDisplayMobileView();
|
|
|
|
}
|
|
|
|
|
|
|
|
$dtConfig = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'discussiontools' );
|
|
|
|
|
|
|
|
if ( $isMobile && (
|
2021-11-11 14:39:04 +00:00
|
|
|
!$dtConfig->get( 'DiscussionToolsEnableMobile' ) ||
|
2020-12-15 19:45:05 +00:00
|
|
|
// Still disable some features for now
|
2021-04-29 14:24:49 +00:00
|
|
|
$feature === self::TOPICSUBSCRIPTION
|
2020-12-15 19:45:05 +00:00
|
|
|
) ) {
|
|
|
|
return false;
|
2020-12-16 16:07:32 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 22:34:02 +00:00
|
|
|
// Topic subscription is not available on your own talk page, as you will
|
2021-08-17 18:33:46 +00:00
|
|
|
// get 'edit-user-talk' notifications already. (T276996)
|
2021-08-17 20:23:27 +00:00
|
|
|
if (
|
|
|
|
( $feature === self::TOPICSUBSCRIPTION || $feature === self::AUTOTOPICSUB ) &&
|
|
|
|
$title->equals( $output->getUser()->getTalkPage() )
|
|
|
|
) {
|
2021-08-17 18:33:46 +00:00
|
|
|
return false;
|
2021-02-17 22:34:02 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 14:24:49 +00:00
|
|
|
// 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 ) {
|
2021-12-07 22:32:06 +00:00
|
|
|
if ( self::hasPagePropCached( $title, 'nonewsectionlink' ) ) {
|
2021-04-29 14:24:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 16:07:32 +00:00
|
|
|
// ?dtenable=1 overrides all user and title checks
|
2021-06-26 15:46:07 +00:00
|
|
|
$queryEnable = $output->getRequest()->getRawVal( 'dtenable' ) ?:
|
2020-12-16 16:07:32 +00:00
|
|
|
// Extra hack for parses from API, where this parameter isn't passed to derivative requests
|
2021-04-15 00:21:53 +00:00
|
|
|
RequestContext::getMain()->getRequest()->getRawVal( 'dtenable' );
|
2021-04-13 22:08:52 +00:00
|
|
|
|
2021-06-07 20:45:54 +00:00
|
|
|
if (
|
2021-08-17 20:23:27 +00:00
|
|
|
( $feature === self::TOPICSUBSCRIPTION || $feature === self::AUTOTOPICSUB ) &&
|
2021-06-07 20:45:54 +00:00
|
|
|
!$dtConfig->get( 'DiscussionToolsEnableTopicSubscriptionBackend' )
|
|
|
|
) {
|
2021-04-14 18:35:17 +00:00
|
|
|
// Can't be enabled via query, because the tables may not exist yet (T280082)
|
2021-04-13 22:08:52 +00:00
|
|
|
$queryEnable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $queryEnable ) {
|
2020-12-16 16:07:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-26 15:46:07 +00:00
|
|
|
if ( $queryEnable === "0" ) {
|
|
|
|
// ?dtenable=0 forcibly disables the feature regardless of any other checks (T285578)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-14 18:35:17 +00:00
|
|
|
return static::isAvailableForTitle( $title ) &&
|
|
|
|
static::isFeatureEnabledForUser( $output->getUser(), $feature );
|
2020-09-10 13:43:13 +00:00
|
|
|
}
|
2021-07-28 10:36:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if this page view should open the new topic tool on page load.
|
|
|
|
*
|
|
|
|
* @param IContextSource $context
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-09-20 16:20:06 +00:00
|
|
|
public static function shouldOpenNewTopicTool( IContextSource $context ): bool {
|
2021-07-28 10:36:58 +00:00
|
|
|
$req = $context->getRequest();
|
|
|
|
$out = $context->getOutput();
|
|
|
|
|
|
|
|
return (
|
|
|
|
// ?title=...&action=edit§ion=new
|
|
|
|
// ?title=...&veaction=editsource§ion=new
|
|
|
|
( $req->getVal( 'action' ) === 'edit' || $req->getVal( 'veaction' ) === 'editsource' ) &&
|
2021-09-20 16:20:06 +00:00
|
|
|
$req->getVal( 'section' ) === 'new' &&
|
2021-07-28 10:36:58 +00:00
|
|
|
// Adding a new topic with preloaded text is not supported yet (T269310)
|
|
|
|
!(
|
|
|
|
$req->getVal( 'editintro' ) || $req->getVal( 'preload' ) ||
|
|
|
|
$req->getVal( 'preloadparams' ) || $req->getVal( 'preloadtitle' )
|
|
|
|
) &&
|
|
|
|
// User has new topic tool enabled (and not using &dtenable=0)
|
|
|
|
self::isFeatureEnabledForOutput( $out, self::NEWTOPICTOOL )
|
|
|
|
);
|
|
|
|
}
|
2021-09-20 16:20:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if this page view should display the empty state for talk pages that don't exist.
|
|
|
|
*
|
|
|
|
* @param IContextSource $context
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function shouldDisplayEmptyState( IContextSource $context ): bool {
|
|
|
|
$req = $context->getRequest();
|
|
|
|
$out = $context->getOutput();
|
|
|
|
$title = $context->getTitle();
|
|
|
|
|
|
|
|
return (
|
|
|
|
(
|
|
|
|
// When following a red link from another page (but not when clicking the 'Edit' tab)
|
|
|
|
( $req->getVal( 'action' ) === 'edit' && $req->getVal( 'redlink' ) === '1' ) ||
|
|
|
|
// When the new topic tool will be opened (usually when clicking the 'Add topic' tab)
|
|
|
|
self::shouldOpenNewTopicTool( $context ) ||
|
|
|
|
// In read mode (accessible for non-existent pages by clicking 'Cancel' in editor)
|
|
|
|
$req->getVal( 'action', 'view' ) === 'view'
|
|
|
|
) &&
|
|
|
|
// Duh
|
|
|
|
!$title->exists() &&
|
|
|
|
// Only in talk namespaces, not including other namespaces that isAvailableForTitle() allows
|
|
|
|
$title->isTalkPage() &&
|
|
|
|
// The default display will probably be more useful for...
|
|
|
|
// ...Permanent links to revisions of pages which have been deleted
|
|
|
|
$req->getIntOrNull( 'oldid' ) === null &&
|
|
|
|
// ...Non-existent pages with default content, e.g. in 'MediaWiki:' namespace
|
|
|
|
!$title->hasSourceText() &&
|
|
|
|
// User has new topic tool enabled (and not using &dtenable=0)
|
|
|
|
self::isFeatureEnabledForOutput( $out, self::NEWTOPICTOOL )
|
|
|
|
);
|
|
|
|
}
|
2021-08-17 20:23:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if we should be adding automatic topic subscriptions for this user on this page.
|
|
|
|
*
|
|
|
|
* @param UserIdentity $user
|
|
|
|
* @param Title $title
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function shouldAddAutoSubscription( UserIdentity $user, Title $title ): bool {
|
|
|
|
// This duplicates the logic from isFeatureEnabledForOutput(),
|
|
|
|
// because we don't have access to the request or the output here.
|
|
|
|
|
|
|
|
// Topic subscription is not available on your own talk page, as you will
|
|
|
|
// get 'edit-user-talk' notifications already. (T276996)
|
|
|
|
// (can't use User::getTalkPage() to check because this is a UserIdentity)
|
|
|
|
if ( $title->inNamespace( NS_USER_TALK ) && $title->getText() === $user->getName() ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the user has automatic subscriptions enabled, and the tools are enabled on the page.
|
|
|
|
return static::isAvailableForTitle( $title ) &&
|
|
|
|
static::isFeatureEnabledForUser( $user, self::AUTOTOPICSUB );
|
|
|
|
}
|
2019-10-10 19:11:07 +00:00
|
|
|
}
|