Merge "Add .pipeline/ with dev image variant"
[lhc/web/wiklou.git] / includes / specials / SpecialUncategorizedCategories.php
1 <?php
2 /**
3 * Implements Special:Uncategorizedcategories
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 * A special page that lists uncategorized categories
26 *
27 * @ingroup SpecialPage
28 */
29 class SpecialUncategorizedCategories extends SpecialUncategorizedPages {
30 /**
31 * Holds a list of categories, which shouldn't be listed on this special page,
32 * even if it is uncategorized.
33 * @var array
34 */
35 private $exceptionList = null;
36
37 function __construct( $name = 'Uncategorizedcategories' ) {
38 parent::__construct( $name );
39 $this->requestedNamespace = NS_CATEGORY;
40 }
41
42 /**
43 * Returns an array of category titles (usually without the namespace), which
44 * shouldn't be listed on this page, even if they're uncategorized.
45 *
46 * @return array
47 */
48 private function getExceptionList() {
49 if ( $this->exceptionList === null ) {
50 $this->exceptionList = [];
51 $exList = $this->msg( 'uncategorized-categories-exceptionlist' )
52 ->inContentLanguage()->plain();
53 $proposedTitles = explode( "\n", $exList );
54 foreach ( $proposedTitles as $count => $titleStr ) {
55 if ( strpos( $titleStr, '*' ) !== 0 ) {
56 continue;
57 }
58 $titleStr = preg_replace( "/^\\*\\s*/", '', $titleStr );
59 $title = Title::newFromText( $titleStr, NS_CATEGORY );
60 if ( $title && $title->getNamespace() !== NS_CATEGORY ) {
61 $title = Title::makeTitleSafe( NS_CATEGORY, $titleStr );
62 }
63 if ( $title ) {
64 $this->exceptionList[] = $title->getDBkey();
65 }
66 }
67 }
68 return $this->exceptionList;
69 }
70
71 public function getQueryInfo() {
72 $dbr = wfGetDB( DB_REPLICA );
73 $query = parent::getQueryInfo();
74 $exceptionList = $this->getExceptionList();
75 if ( $exceptionList ) {
76 $query['conds'][] = 'page_title not in ( ' . $dbr->makeList( $exceptionList ) . ' )';
77 }
78
79 return $query;
80 }
81
82 /**
83 * Formats the result
84 * @param Skin $skin The current skin
85 * @param object $result The query result
86 * @return string The category link
87 */
88 function formatResult( $skin, $result ) {
89 $title = Title::makeTitle( NS_CATEGORY, $result->title );
90 $text = $title->getText();
91
92 return $this->getLinkRenderer()->makeKnownLink( $title, $text );
93 }
94 }