* (bug 1459) Search for duplicate files by hash: Special:FileDuplicateSearch
[lhc/web/wiklou.git] / includes / SpecialSpecialpages.php
index 24be9aa..4ea956b 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 /**
- * Main function
+ *
  */
 function wfSpecialSpecialpages() {
        global $wgOut, $wgUser, $wgMessageCache;
@@ -13,72 +13,22 @@ function wfSpecialSpecialpages() {
        $wgMessageCache->loadAllMessages();
 
        $wgOut->setRobotpolicy( 'noindex,nofollow' );  # Is this really needed?
+       $sk = $wgUser->getSkin();
 
-       # Read the special pages
-       $pagesRegular = SpecialPage::getRegularPages();
-       $pagesRestricted = SpecialPage::getRestrictedPages();
-       if( count( $pagesRegular ) == 0 && count( $pagesRestricted ) == 0 ) {
-               # Yeah, that was pointless. Thanks for coming.
-               return;
-       }
-
-       # Put regular and restricted special pages into sortable arrays
-       $unsortedPagesRegular = wfSpecialSpecialpages_read( $pagesRegular );
-       $unsortedPagesRestricted = wfSpecialSpecialpages_read( $pagesRestricted );
-
-       # Read the template
-       $tpl = wfMsg( 'specialpages-tpl' );
-       $newSpecialPage = '';
-
-       # Parse the template and create a localized wikitext page
-       foreach ( explode( "\n", $tpl ) as $line ) {
-               # Look for 'special:' in the line
-               $pos = strpos( $line, 'special:' );
-               if( $pos >= 0 ) {
-
-                       # Preserve the line start
-                       $lineStart = ( $pos > 0 ) ? substr( $line, 0, $pos ) : '';
+       /** Pages available to all */
+       wfSpecialSpecialpages_gen( SpecialPage::getRegularPages(), 'spheading', $sk );
 
-                       # Get the canonical special page name
-                       $canonical = strtolower( trim( substr( $line, $pos + 8 ) ) );
-
-                       # Check if it is a valid regular special page name
-                       # Restricted pages will be added at the end
-                       if( isset( $unsortedPagesRegular[$canonical] ) ) {
-                               # Add a new line
-                               $newSpecialPage .= $lineStart . "[[special:" . $canonical . "|" . $unsortedPagesRegular[$canonical] . "]]\n";
-                               # Delete this regular special page from the array to avoid double output
-                               unset( $unsortedPagesRegular[$canonical] );
-                       } else {
-                               # Ok, no valid special page, but add the line to the output
-                               $newSpecialPage .= $line . "\n";
-                       }
-               } else {
-                       $newSpecialPage .= $line . "\n";
-               }
-       }
-
-       # Add the rest
-       $newSpecialPage .= wfSpecialSpecialpages_out( 'specialpages-other', $unsortedPagesRegular );
-       # Add the restricted special pages
-       $newSpecialPage .= wfSpecialSpecialpages_out( 'restrictedpheading', $unsortedPagesRestricted );
-
-       # Output the customized special pages list
-       $wgOut->addWikiText( $newSpecialPage );
-
-       if ( $wgUser->isAllowed( 'editinterface' ) ) {
-               # Output a nice link to edit the template
-               $wgOut->addHtml( wfSpecialSpecialpages_edit() );
-       }
+       /** Restricted special pages */
+       wfSpecialSpecialpages_gen( SpecialPage::getRestrictedPages(), 'restrictedpheading', $sk );
 }
 
 /**
- * Output the rest special pages as wikitext
- * @param string $heading Message name for the heading
- * @param array $sortedPages List of other special pages
- * @return string $rest Wikitext
+ * sub function generating the list of pages
+ * @param $pages the list of pages
+ * @param $heading header to be used
+ * @param $sk skin object ???
  */
-function wfSpecialSpecialpages_out( $heading, $pages ) {
+function wfSpecialSpecialpages_gen($pages,$heading,$sk) {
        global $wgOut, $wgSortSpecialPages;
 
        if( count( $pages ) == 0 ) {
@@ -86,44 +36,26 @@ function wfSpecialSpecialpages_out( $heading, $pages ) {
                return;
        }
 
-       # Sort
-       if ( $wgSortSpecialPages ) {
-               asort( $pages );
+       /** Put them into a sortable array */
+       $sortedPages = array();
+       foreach ( $pages as $page ) {
+               if ( $page->isListed() ) {
+                       $sortedPages[$page->getDescription()] = $page->getTitle();
+               }
        }
 
-       # Now output the rest special pages as wikitext
-       $rest = '== ' . wfMsgExt( $heading, array( 'parseinline' ) ) . " ==\n";
-       foreach ( $pages as $title => $desc ) {
-               $rest .= "* [[special:" . $title . "|" . $desc . "]]\n";
+       /** Sort */
+       if ( $wgSortSpecialPages ) {
+               ksort( $sortedPages );
        }
-       return $rest;
-}
 
-/**
- * Create array with descriptions and names of special pages
- * @param array $pagelist List of special pages
- * @return array $unsortedPagesList Wikitext
- */
-function wfSpecialSpecialpages_read( $pagelist ) {
-       $unsortedPagesList = array();
-       foreach ( $pagelist as $page ) {
-               if ( $page->isListed() ) {
-                       $name = strtolower( $page->getName() );
-                       $unsortedPagesList[$name] = $page->getDescription();
-               }
+       /** Now output the HTML */
+       $wgOut->addHTML( '<h2>' . wfMsgHtml( $heading ) . "</h2>\n<ul>" );
+       foreach ( $sortedPages as $desc => $title ) {
+               $link = $sk->makeKnownLinkObj( $title , htmlspecialchars( $desc ) );
+               $wgOut->addHTML( "<li>{$link}</li>\n" );
        }
-       return $unsortedPagesList;
+       $wgOut->addHTML( "</ul>\n" );
 }
 
-/**
- * Build edit link to MediaWiki:specialpages-tpl
- *
- * @return string
- */
-function wfSpecialSpecialpages_edit() {
-       global $wgUser, $wgContLang;
-       $align = $wgContLang->isRtl() ? 'left' : 'right';
-       $skin = $wgUser->getSkin();
-       $link = $skin->makeLink ( 'MediaWiki:specialpages-tpl', wfMsgHtml( 'specialpages-edit' ) );
-       return '<p style="float:' . $align . ';" class="mw-specialspecialpages-edit">' . $link . '</p>';
-}
+