Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / linker / LinkRendererFactory.php
blobb7c05c2fe88944ce0b2c140dda02c82210ea3563
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.
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.
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
18 * @file
19 * @license GPL-2.0+
20 * @author Kunal Mehta <legoktm@member.fsf.org>
22 namespace MediaWiki\Linker;
24 use LinkCache;
25 use TitleFormatter;
26 use User;
28 /**
29 * Factory to create LinkRender objects
30 * @since 1.28
32 class LinkRendererFactory {
34 /**
35 * @var TitleFormatter
37 private $titleFormatter;
39 /**
40 * @var LinkCache
42 private $linkCache;
44 /**
45 * @param TitleFormatter $titleFormatter
46 * @param LinkCache $linkCache
48 public function __construct( TitleFormatter $titleFormatter, LinkCache $linkCache ) {
49 $this->titleFormatter = $titleFormatter;
50 $this->linkCache = $linkCache;
53 /**
54 * @return LinkRenderer
56 public function create() {
57 return new LinkRenderer( $this->titleFormatter, $this->linkCache );
60 /**
61 * @param User $user
62 * @return LinkRenderer
64 public function createForUser( User $user ) {
65 $linkRenderer = $this->create();
66 $linkRenderer->setStubThreshold( $user->getStubThreshold() );
68 return $linkRenderer;
71 /**
72 * @param array $options
73 * @return LinkRenderer
75 public function createFromLegacyOptions( array $options ) {
76 $linkRenderer = $this->create();
78 if ( in_array( 'forcearticlepath', $options, true ) ) {
79 $linkRenderer->setForceArticlePath( true );
82 if ( in_array( 'http', $options, true ) ) {
83 $linkRenderer->setExpandURLs( PROTO_HTTP );
84 } elseif ( in_array( 'https', $options, true ) ) {
85 $linkRenderer->setExpandURLs( PROTO_HTTPS );
88 if ( isset( $options['stubThreshold'] ) ) {
89 $linkRenderer->setStubThreshold(
90 $options['stubThreshold']
94 return $linkRenderer;