SpecialUncategorizedCategories.php 2.8 KB

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