MediaWiki  1.33.0
MainSlotRoleHandler.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Revision;
24 
26 use Hooks;
28 use Title;
29 
42 
48 
54  parent::__construct( 'main', CONTENT_MODEL_WIKITEXT );
55  $this->namespaceContentModels = $namespaceContentModels;
56  }
57 
58  public function supportsArticleCount() {
59  return true;
60  }
61 
68  public function isAllowedModel( $model, LinkTarget $page ) {
71  return $handler->canBeUsedOn( $title );
72  }
73 
79  public function getDefaultModel( LinkTarget $page ) {
80  // NOTE: this method must not rely on $title->getContentModel() directly or indirectly,
81  // because it is used to initialize the mContentModel member.
82 
83  $ext = '';
84  $ns = $page->getNamespace();
85  $model = $this->namespaceContentModels[$ns] ?? null;
86 
87  // Hook can determine default model
89  if ( !Hooks::run( 'ContentHandlerDefaultModelFor', [ $title, &$model ] ) && !is_null( $model ) ) {
90  return $model;
91  }
92 
93  // Could this page contain code based on the title?
94  $isCodePage = $ns === NS_MEDIAWIKI && preg_match( '!\.(css|js|json)$!u', $title->getText(), $m );
95  if ( $isCodePage ) {
96  $ext = $m[1];
97  }
98 
99  // Is this a user subpage containing code?
100  $isCodeSubpage = $ns === NS_USER
101  && !$isCodePage
102  && preg_match( "/\\/.*\\.(js|css|json)$/", $title->getText(), $m );
103 
104  if ( $isCodeSubpage ) {
105  $ext = $m[1];
106  }
107 
108  // Is this wikitext, according to $wgNamespaceContentModels or the DefaultModelFor hook?
109  $isWikitext = is_null( $model ) || $model == CONTENT_MODEL_WIKITEXT;
110  $isWikitext = $isWikitext && !$isCodePage && !$isCodeSubpage;
111 
112  if ( !$isWikitext ) {
113  switch ( $ext ) {
114  case 'js':
116  case 'css':
117  return CONTENT_MODEL_CSS;
118  case 'json':
119  return CONTENT_MODEL_JSON;
120  default:
121  return $model ?? CONTENT_MODEL_TEXT;
122  }
123  }
124 
125  // We established that it must be wikitext
126 
127  return CONTENT_MODEL_WIKITEXT;
128  }
129 
130 }
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:239
ContentHandler
A content handler knows how do deal with a specific type of content on a wiki page.
Definition: ContentHandler.php:53
ContentHandler\getForModelID
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
Definition: ContentHandler.php:252
Revision\MainSlotRoleHandler\isAllowedModel
isAllowedModel( $model, LinkTarget $page)
Definition: MainSlotRoleHandler.php:68
Revision\MainSlotRoleHandler\supportsArticleCount
supportsArticleCount()
Whether this slot should be considered when determining whether a page should be counted as an "artic...
Definition: MainSlotRoleHandler.php:58
Revision\MainSlotRoleHandler
A SlotRoleHandler for the main slot.
Definition: MainSlotRoleHandler.php:41
Revision\MainSlotRoleHandler\$namespaceContentModels
string[] $namespaceContentModels
A mapping of namespaces to content models.
Definition: MainSlotRoleHandler.php:47
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:237
Revision\SlotRoleHandler
SlotRoleHandler instances are used to declare the existence and behavior of slot roles.
Definition: SlotRoleHandler.php:34
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:235
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Revision
Created by PhpStorm.
Definition: FallbackSlotRoleHandler.php:23
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
$handler
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition: hooks.txt:780
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:269
Title
Represents a title within MediaWiki.
Definition: Title.php:40
NS_USER
const NS_USER
Definition: Defines.php:66
$ext
if(!is_readable( $file)) $ext
Definition: router.php:48
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:236
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
CONTENT_MODEL_TEXT
const CONTENT_MODEL_TEXT
Definition: Defines.php:238
Revision\MainSlotRoleHandler\getDefaultModel
getDefaultModel(LinkTarget $page)
Definition: MainSlotRoleHandler.php:79
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
Hooks
Hooks class.
Definition: Hooks.php:34
Revision\MainSlotRoleHandler\__construct
__construct(array $namespaceContentModels)
Definition: MainSlotRoleHandler.php:53