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