Merge "Warn if stateful ParserOutput transforms are used"
[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 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 * @var LinkCache
40 */
41 private $linkCache;
42
43 /**
44 * @param TitleFormatter $titleFormatter
45 * @param LinkCache $linkCache
46 */
47 public function __construct( TitleFormatter $titleFormatter, LinkCache $linkCache ) {
48 $this->titleFormatter = $titleFormatter;
49 $this->linkCache = $linkCache;
50 }
51
52 /**
53 * @return LinkRenderer
54 */
55 public function create() {
56 return new LinkRenderer( $this->titleFormatter, $this->linkCache );
57 }
58
59 /**
60 * @param User $user
61 * @return LinkRenderer
62 */
63 public function createForUser( User $user ) {
64 $linkRenderer = $this->create();
65 $linkRenderer->setStubThreshold( $user->getStubThreshold() );
66
67 return $linkRenderer;
68 }
69
70 /**
71 * @param array $options
72 * @return LinkRenderer
73 */
74 public function createFromLegacyOptions( array $options ) {
75 $linkRenderer = $this->create();
76
77 if ( in_array( 'forcearticlepath', $options, true ) ) {
78 $linkRenderer->setForceArticlePath( true );
79 }
80
81 if ( in_array( 'http', $options, true ) ) {
82 $linkRenderer->setExpandURLs( PROTO_HTTP );
83 } elseif ( in_array( 'https', $options, true ) ) {
84 $linkRenderer->setExpandURLs( PROTO_HTTPS );
85 }
86
87 if ( isset( $options['stubThreshold'] ) ) {
88 $linkRenderer->setStubThreshold(
89 $options['stubThreshold']
90 );
91 }
92
93 return $linkRenderer;
94 }
95 }