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
19 * @author Kunal Mehta <legoktm@debian.org>
21 namespace MediaWiki\Linker
;
23 use MediaWiki\Cache\LinkCache
;
24 use MediaWiki\Config\ServiceOptions
;
25 use MediaWiki\HookContainer\HookContainer
;
26 use MediaWiki\SpecialPage\SpecialPageFactory
;
27 use MediaWiki\Title\TitleFormatter
;
30 * Factory to create LinkRender objects
33 class LinkRendererFactory
{
38 private $titleFormatter;
48 private $hookContainer;
51 * @var SpecialPageFactory
53 private $specialPageFactory;
56 * @internal For use by core ServiceWiring
57 * @param TitleFormatter $titleFormatter
58 * @param LinkCache $linkCache
59 * @param SpecialPageFactory $specialPageFactory
60 * @param HookContainer $hookContainer
62 public function __construct(
63 TitleFormatter
$titleFormatter,
65 SpecialPageFactory
$specialPageFactory,
66 HookContainer
$hookContainer
68 $this->titleFormatter
= $titleFormatter;
69 $this->linkCache
= $linkCache;
70 $this->specialPageFactory
= $specialPageFactory;
71 $this->hookContainer
= $hookContainer;
75 * @param array $options optional flags for rendering
76 * - 'renderForComment': set to true if the created LinkRenderer will be used for
77 * links in an edit summary or log comments. An instance with renderForComment
78 * enabled must not be used for other links.
80 * @return LinkRenderer
82 public function create( array $options = [ 'renderForComment' => false ] ) {
83 return new LinkRenderer(
84 $this->titleFormatter
, $this->linkCache
, $this->specialPageFactory
,
86 new ServiceOptions( LinkRenderer
::CONSTRUCTOR_OPTIONS
, $options )
91 * @param array $options
92 * @return LinkRenderer
94 public function createFromLegacyOptions( array $options ) {
95 $linkRenderer = $this->create();
97 if ( in_array( 'forcearticlepath', $options, true ) ) {
98 $linkRenderer->setForceArticlePath( true );
101 if ( in_array( 'http', $options, true ) ) {
102 $linkRenderer->setExpandURLs( PROTO_HTTP
);
103 } elseif ( in_array( 'https', $options, true ) ) {
104 $linkRenderer->setExpandURLs( PROTO_HTTPS
);
107 return $linkRenderer;