MediaWiki  1.34.0
LinkRendererFactory.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Linker;
22 
23 use LinkCache;
24 use NamespaceInfo;
25 use TitleFormatter;
26 use User;
27 
33 
37  private $titleFormatter;
38 
42  private $linkCache;
43 
47  private $nsInfo;
48 
54  public function __construct(
56  ) {
57  $this->titleFormatter = $titleFormatter;
58  $this->linkCache = $linkCache;
59  $this->nsInfo = $nsInfo;
60  }
61 
65  public function create() {
66  return new LinkRenderer( $this->titleFormatter, $this->linkCache, $this->nsInfo );
67  }
68 
73  public function createForUser( User $user ) {
74  $linkRenderer = $this->create();
75  $linkRenderer->setStubThreshold( $user->getStubThreshold() );
76 
77  return $linkRenderer;
78  }
79 
84  public function createFromLegacyOptions( array $options ) {
85  $linkRenderer = $this->create();
86 
87  if ( in_array( 'forcearticlepath', $options, true ) ) {
88  $linkRenderer->setForceArticlePath( true );
89  }
90 
91  if ( in_array( 'http', $options, true ) ) {
92  $linkRenderer->setExpandURLs( PROTO_HTTP );
93  } elseif ( in_array( 'https', $options, true ) ) {
94  $linkRenderer->setExpandURLs( PROTO_HTTPS );
95  }
96 
97  if ( isset( $options['stubThreshold'] ) ) {
98  $linkRenderer->setStubThreshold(
99  $options['stubThreshold']
100  );
101  }
102 
103  return $linkRenderer;
104  }
105 }
LinkCache
Cache for article titles (prefixed DB keys) and ids linked from one source.
Definition: LinkCache.php:34
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition: LinkRenderer.php:41
User\getStubThreshold
getStubThreshold()
Get the user preferred stub threshold.
Definition: User.php:3281
MediaWiki\Linker\LinkRendererFactory\createFromLegacyOptions
createFromLegacyOptions(array $options)
Definition: LinkRendererFactory.php:84
MediaWiki\Linker\LinkRendererFactory
Factory to create LinkRender objects.
Definition: LinkRendererFactory.php:32
MediaWiki\Linker\LinkRendererFactory\__construct
__construct(TitleFormatter $titleFormatter, LinkCache $linkCache, NamespaceInfo $nsInfo)
Definition: LinkRendererFactory.php:54
MediaWiki\Linker\LinkRendererFactory\createForUser
createForUser(User $user)
Definition: LinkRendererFactory.php:73
MediaWiki\Linker
Definition: LinkRenderer.php:21
MediaWiki\Linker\LinkRendererFactory\$nsInfo
NamespaceInfo $nsInfo
Definition: LinkRendererFactory.php:47
PROTO_HTTPS
const PROTO_HTTPS
Definition: Defines.php:200
PROTO_HTTP
const PROTO_HTTP
Definition: Defines.php:199
MediaWiki\Linker\LinkRendererFactory\$titleFormatter
TitleFormatter $titleFormatter
Definition: LinkRendererFactory.php:37
TitleFormatter
A title formatter service for MediaWiki.
Definition: TitleFormatter.php:34
NamespaceInfo
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Definition: NamespaceInfo.php:33
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
MediaWiki\Linker\LinkRendererFactory\create
create()
Definition: LinkRendererFactory.php:65
MediaWiki\Linker\LinkRendererFactory\$linkCache
LinkCache $linkCache
Definition: LinkRendererFactory.php:42