*
* @file
*/
+use MediaWiki\MediaWikiServices;
/**
* This is a utility class with only static functions
*/
public static function getCanonicalName( $index ) {
$nslist = self::getCanonicalNamespaces();
- if ( isset( $nslist[$index] ) ) {
- return $nslist[$index];
- } else {
- return false;
- }
+ return $nslist[$index] ?? false;
}
/**
* @return bool True if this namespace either is or has a corresponding talk namespace.
*/
public static function canTalk( $index ) {
+ wfDeprecated( __METHOD__, '1.30' );
return self::hasTalkNamespace( $index );
}
* Get the default content model for a namespace
* This does not mean that all pages in that namespace have the model
*
+ * @note To determine the default model for a new page's main slot, or any slot in general,
+ * use SlotRoleHandler::getDefaultModel() together with SlotRoleRegistry::getRoleHandler().
+ *
* @since 1.21
* @param int $index Index to check
* @return null|string Default model name for the given namespace, if set
*/
public static function getNamespaceContentModel( $index ) {
- global $wgNamespaceContentModels;
- return $wgNamespaceContentModels[$index] ?? null;
+ $config = MediaWikiServices::getInstance()->getMainConfig();
+ $models = $config->get( 'NamespaceContentModels' );
+ return $models[$index] ?? null;
}
/**
*
* @since 1.23
* @param int $index Index to check
- * @param User $user User to check
+ * @param User|null $user User to check
* @return array
*/
public static function getRestrictionLevels( $index, User $user = null ) {
return $usableLevels;
}
+
+ /**
+ * Returns the link type to be used for categories.
+ *
+ * This determines which section of a category page titles
+ * in the namespace will appear within.
+ *
+ * @since 1.32
+ * @param int $index Namespace index
+ * @return string One of 'subcat', 'file', 'page'
+ */
+ public static function getCategoryLinkType( $index ) {
+ self::isMethodValidFor( $index, __METHOD__ );
+
+ if ( $index == NS_CATEGORY ) {
+ return 'subcat';
+ } elseif ( $index == NS_FILE ) {
+ return 'file';
+ } else {
+ return 'page';
+ }
+ }
}