Merge "RightsLogFormatter: Use DB key to generate foreign user link"
[lhc/web/wiklou.git] / includes / specials / SpecialCategories.php
1 <?php
2 /**
3 * Implements Special:Categories
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * @ingroup SpecialPage
26 */
27 class SpecialCategories extends SpecialPage {
28
29 /**
30 * @var PageLinkRenderer
31 */
32 protected $linkRenderer = null;
33
34 public function __construct() {
35 parent::__construct( 'Categories' );
36
37 // Since we don't control the constructor parameters, we can't inject services that way.
38 // Instead, we initialize services in the execute() method, and allow them to be overridden
39 // using the initServices() method.
40 }
41
42 /**
43 * Initialize or override the PageLinkRenderer SpecialCategories collaborates with.
44 * Useful mainly for testing.
45 *
46 * @todo the pager should also be injected, and de-coupled from the rendering logic.
47 *
48 * @param PageLinkRenderer $linkRenderer
49 */
50 public function setPageLinkRenderer(
51 PageLinkRenderer $linkRenderer
52 ) {
53 $this->linkRenderer = $linkRenderer;
54 }
55
56 /**
57 * Initialize any services we'll need (unless it has already been provided via a setter).
58 * This allows for dependency injection even though we don't control object creation.
59 */
60 private function initServices() {
61 if ( !$this->linkRenderer ) {
62 $lang = $this->getContext()->getLanguage();
63 $titleFormatter = new MediaWikiTitleCodec( $lang, GenderCache::singleton() );
64 $this->linkRenderer = new MediaWikiPageLinkRenderer( $titleFormatter );
65 }
66 }
67
68 public function execute( $par ) {
69 $this->initServices();
70
71 $this->setHeaders();
72 $this->outputHeader();
73 $this->getOutput()->allowClickjacking();
74
75 $from = $this->getRequest()->getText( 'from', $par );
76
77 $cap = new CategoryPager( $this->getContext(), $from, $this->linkRenderer );
78 $cap->doQuery();
79
80 $this->getOutput()->addHTML(
81 Html::openElement( 'div', [ 'class' => 'mw-spcontent' ] ) .
82 $this->msg( 'categoriespagetext', $cap->getNumRows() )->parseAsBlock() .
83 $cap->getStartForm( $from ) .
84 $cap->getNavigationBar() .
85 '<ul>' . $cap->getBody() . '</ul>' .
86 $cap->getNavigationBar() .
87 Html::closeElement( 'div' )
88 );
89 }
90
91 protected function getGroupName() {
92 return 'pages';
93 }
94 }