]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialSpecialpages.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialSpecialpages.php
index 84ab689afa87184d8c510ae9ddc01d4ad8ecc217..4f29082227bf14de8fd9079492273d7a1749420b 100644 (file)
 <?php
 /**
+ * Implements Special:Specialpages
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup SpecialPage
  */
 
 /**
+ * A special page that lists special pages
  *
+ * @ingroup SpecialPage
  */
-function wfSpecialSpecialpages() {
-       global $wgOut, $wgUser, $wgMessageCache, $wgSortSpecialPages;
+class SpecialSpecialpages extends UnlistedSpecialPage {
 
-       $wgMessageCache->loadAllMessages();
+       function __construct() {
+               parent::__construct( 'Specialpages' );
+       }
 
-       $wgOut->setRobotPolicy( 'noindex,nofollow' );  # Is this really needed?
-       $sk = $wgUser->getSkin();
+       function execute( $par ) {
+               $out = $this->getOutput();
+               $this->setHeaders();
+               $this->outputHeader();
+               $out->allowClickjacking();
+               $out->addModuleStyles( 'mediawiki.special' );
 
-       $pages = SpecialPage::getUsablePages();
+               $groups = $this->getPageGroups();
 
-       if( count( $pages ) == 0 ) {
-               # Yeah, that was pointless. Thanks for coming.
-               return;
+               if ( $groups === false ) {
+                       return;
+               }
+
+               $this->addHelpLink( 'Help:Special pages' );
+               $this->outputPageList( $groups );
        }
 
-       /** Put them into a sortable array */
-       $groups = array();
-       foreach ( $pages as $page ) {
-               if ( $page->isListed() ) {
-                       $group = SpecialPage::getGroup( $page );
-                       if( !isset($groups[$group]) ) {
-                               $groups[$group] = array();
+       private function getPageGroups() {
+               $pages = SpecialPageFactory::getUsablePages( $this->getUser() );
+
+               if ( !count( $pages ) ) {
+                       # Yeah, that was pointless. Thanks for coming.
+                       return false;
+               }
+
+               /** Put them into a sortable array */
+               $groups = [];
+               /** @var SpecialPage $page */
+               foreach ( $pages as $page ) {
+                       if ( $page->isListed() ) {
+                               $group = $page->getFinalGroupName();
+                               if ( !isset( $groups[$group] ) ) {
+                                       $groups[$group] = [];
+                               }
+                               $groups[$group][$page->getDescription()] = [
+                                       $page->getPageTitle(),
+                                       $page->isRestricted(),
+                                       $page->isCached()
+                               ];
                        }
-                       $groups[$group][$page->getDescription()] = array( $page->getTitle(), $page->isRestricted() );
                }
-       }
 
-       /** Sort */
-       if ( $wgSortSpecialPages ) {
-               foreach( $groups as $group => $sortedPages ) {
+               /** Sort */
+               foreach ( $groups as $group => $sortedPages ) {
                        ksort( $groups[$group] );
                }
-       }
 
-       /** Always move "other" to end */
-       if( array_key_exists('other',$groups) ) {
-               $other = $groups['other'];
-               unset( $groups['other'] );
-               $groups['other'] = $other;
+               /** Always move "other" to end */
+               if ( array_key_exists( 'other', $groups ) ) {
+                       $other = $groups['other'];
+                       unset( $groups['other'] );
+                       $groups['other'] = $other;
+               }
+
+               return $groups;
        }
 
-       $includesRestrictedPages = false;
-       /** Now output the HTML */
-       foreach ( $groups as $group => $sortedPages ) {
-               $middle = ceil( count($sortedPages)/2 );
-               $total = count($sortedPages);
-               $count = 0;
-
-               $wgOut->wrapWikiMsg( "<h4 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h4>\n", "specialpages-group-$group" );
-               $wgOut->addHTML( "<table style='width: 100%;' class='mw-specialpages-table'><tr>" );
-               $wgOut->addHTML( "<td width='30%' valign='top'><ul>\n" );
-               foreach( $sortedPages as $desc => $specialpage ) {
-                       list( $title, $restricted ) = $specialpage;
-                       $link = $sk->linkKnown( $title , htmlspecialchars( $desc ) );
-                       if( $restricted ) {
-                               $includesRestrictedPages = true;
-                               $wgOut->addHTML( "<li class='mw-specialpages-page mw-specialpagerestricted'><strong>{$link}</strong></li>\n" );
-                       } else {
-                               $wgOut->addHTML( "<li>{$link}</li>\n" );
-                       }
+       private function outputPageList( $groups ) {
+               $out = $this->getOutput();
+
+               $includesRestrictedPages = false;
+               $includesCachedPages = false;
+
+               foreach ( $groups as $group => $sortedPages ) {
+                       $out->wrapWikiMsg(
+                               "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n",
+                               "specialpages-group-$group"
+                       );
+                       $out->addHTML(
+                               Html::openElement( 'div', [ 'class' => 'mw-specialpages-list' ] )
+                               . '<ul>'
+                       );
+                       foreach ( $sortedPages as $desc => $specialpage ) {
+                               list( $title, $restricted, $cached ) = $specialpage;
+
+                               $pageClasses = [];
+                               if ( $cached ) {
+                                       $includesCachedPages = true;
+                                       $pageClasses[] = 'mw-specialpagecached';
+                               }
+                               if ( $restricted ) {
+                                       $includesRestrictedPages = true;
+                                       $pageClasses[] = 'mw-specialpagerestricted';
+                               }
 
-                       # Split up the larger groups
-                       $count++;
-                       if( $total > 3 && $count == $middle ) {
-                               $wgOut->addHTML( "</ul></td><td width='10%'></td><td width='30%' valign='top'><ul>" );
+                               $link = $this->getLinkRenderer()->makeKnownLink( $title, $desc );
+                               $out->addHTML( Html::rawElement(
+                                               'li',
+                                               [ 'class' => implode( ' ', $pageClasses ) ],
+                                               $link
+                                       ) . "\n" );
                        }
+                       $out->addHTML(
+                               Html::closeElement( 'ul' ) .
+                               Html::closeElement( 'div' )
+                       );
                }
-               $wgOut->addHTML( "</ul></td><td width='30%' valign='top'></td></tr></table>\n" );
-       }
 
-       if ( $includesRestrictedPages ) {
-               $wgOut->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
+               // add legend
+               $notes = [];
+               if ( $includesRestrictedPages ) {
+                       $restricedMsg = $this->msg( 'specialpages-note-restricted' );
+                       if ( !$restricedMsg->isDisabled() ) {
+                               $notes[] = $restricedMsg->plain();
+                       }
+               }
+               if ( $includesCachedPages ) {
+                       $cachedMsg = $this->msg( 'specialpages-note-cached' );
+                       if ( !$cachedMsg->isDisabled() ) {
+                               $notes[] = $cachedMsg->plain();
+                       }
+               }
+               if ( $notes !== [] ) {
+                       $out->wrapWikiMsg(
+                               "<h2 class=\"mw-specialpages-note-top\">$1</h2>", 'specialpages-note-top'
+                       );
+                       $out->addWikiText(
+                               "<div class=\"mw-specialpages-notes\">\n" .
+                               implode( "\n", $notes ) .
+                               "\n</div>"
+                       );
+               }
        }
 }