MediaWiki  master
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 }
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:51
const PROTO_HTTPS
Definition: Defines.php:200
__construct(TitleFormatter $titleFormatter, LinkCache $linkCache, NamespaceInfo $nsInfo)
Class that generates HTML links for pages.
const PROTO_HTTP
Definition: Defines.php:199
getStubThreshold()
Get the user preferred stub threshold.
Definition: User.php:3333
Factory to create LinkRender objects.