Merge "Add support for icu-ta collation"
[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 * @license GPL-2.0+
20 * @author Kunal Mehta <legoktm@member.fsf.org>
21 */
22 namespace MediaWiki\Linker;
23
24 use TitleFormatter;
25 use User;
26
27 /**
28 * Factory to create LinkRender objects
29 * @since 1.28
30 */
31 class LinkRendererFactory {
32
33 /**
34 * @var TitleFormatter
35 */
36 private $titleFormatter;
37
38 /**
39 * @param TitleFormatter $titleFormatter
40 */
41 public function __construct( TitleFormatter $titleFormatter ) {
42 $this->titleFormatter = $titleFormatter;
43 }
44
45 /**
46 * @return LinkRenderer
47 */
48 public function create() {
49 return new LinkRenderer( $this->titleFormatter );
50 }
51
52 /**
53 * @param User $user
54 * @return LinkRenderer
55 */
56 public function createForUser( User $user ) {
57 $linkRenderer = $this->create();
58 $linkRenderer->setStubThreshold( $user->getStubThreshold() );
59
60 return $linkRenderer;
61 }
62
63 /**
64 * @param array $options
65 * @return LinkRenderer
66 */
67 public function createFromLegacyOptions( array $options ) {
68 $linkRenderer = $this->create();
69
70 if ( in_array( 'forcearticlepath', $options, true ) ) {
71 $linkRenderer->setForceArticlePath( true );
72 }
73
74 if ( in_array( 'http', $options, true ) ) {
75 $linkRenderer->setExpandURLs( PROTO_HTTP );
76 } elseif ( in_array( 'https', $options, true ) ) {
77 $linkRenderer->setExpandURLs( PROTO_HTTPS );
78 }
79
80 if ( isset( $options['stubThreshold'] ) ) {
81 $linkRenderer->setStubThreshold(
82 $options['stubThreshold']
83 );
84 }
85
86 return $linkRenderer;
87 }
88 }