]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/specials/SpecialUncategorizedcategories.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.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 UncategorizedCategoriesPage extends UncategorizedPagesPage {
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                         $exList = $this->msg( 'uncategorized-categories-exceptionlist' )
51                                 ->inContentLanguage()->plain();
52                         $proposedTitles = explode( "\n", $exList );
53                         foreach ( $proposedTitles as $count => $titleStr ) {
54                                 if ( strpos( $titleStr, '*' ) !== 0 ) {
55                                         continue;
56                                 }
57                                 $titleStr = preg_replace( "/^\\*\\s*/", '', $titleStr );
58                                 $title = Title::newFromText( $titleStr, NS_CATEGORY );
59                                 if ( $title && $title->getNamespace() !== NS_CATEGORY ) {
60                                         $title = Title::makeTitleSafe( NS_CATEGORY, $titleStr );
61                                 }
62                                 if ( $title ) {
63                                         $this->exceptionList[] = $title->getDBKey();
64                                 }
65                         }
66                 }
67                 return $this->exceptionList;
68         }
69
70         public function getQueryInfo() {
71                 $dbr = wfGetDB( DB_REPLICA );
72                 $query = parent::getQueryInfo();
73                 $exceptionList = $this->getExceptionList();
74                 if ( $exceptionList ) {
75                         $query['conds'][] = 'page_title not in ( ' . $dbr->makeList( $exceptionList ) . ' )';
76                 }
77
78                 return $query;
79         }
80
81         /**
82          * Formats the result
83          * @param Skin $skin The current skin
84          * @param object $result The query result
85          * @return string The category link
86          */
87         function formatResult( $skin, $result ) {
88                 $title = Title::makeTitle( NS_CATEGORY, $result->title );
89                 $text = $title->getText();
90
91                 return $this->getLinkRenderer()->makeKnownLink( $title, $text );
92         }
93 }