Merge "Remove parameter 'options' from hook 'SkinEditSectionLinks'"
[lhc/web/wiklou.git] / includes / linker / LinkRendererFactory.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @author Kunal Mehta <legoktm@member.fsf.org>
20 */
21 namespace MediaWiki\Linker;
22
23 use LinkCache;
24 use NamespaceInfo;
25 use TitleFormatter;
26 use User;
27
28 /**
29 * Factory to create LinkRender objects
30 * @since 1.28
31 */
32 class LinkRendererFactory {
33
34 /**
35 * @var TitleFormatter
36 */
37 private $titleFormatter;
38
39 /**
40 * @var LinkCache
41 */
42 private $linkCache;
43
44 /**
45 * @var NamespaceInfo
46 */
47 private $nsInfo;
48
49 /**
50 * @param TitleFormatter $titleFormatter
51 * @param LinkCache $linkCache
52 * @param NamespaceInfo $nsInfo
53 */
54 public function __construct(
55 TitleFormatter $titleFormatter, LinkCache $linkCache, NamespaceInfo $nsInfo
56 ) {
57 $this->titleFormatter = $titleFormatter;
58 $this->linkCache = $linkCache;
59 $this->nsInfo = $nsInfo;
60 }
61
62 /**
63 * @return LinkRenderer
64 */
65 public function create() {
66 return new LinkRenderer( $this->titleFormatter, $this->linkCache, $this->nsInfo );
67 }
68
69 /**
70 * @param User $user
71 * @return LinkRenderer
72 */
73 public function createForUser( User $user ) {
74 $linkRenderer = $this->create();
75 $linkRenderer->setStubThreshold( $user->getStubThreshold() );
76
77 return $linkRenderer;
78 }
79
80 /**
81 * @param array $options
82 * @return LinkRenderer
83 */
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 }