Talk:SpecialPages grouped into categories

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search

English version?[edit]

How about it? -Eep² 20:04, 21 July 2007 (UTC)Reply[reply]

OK, I did it (in SpecialPages grouped into categories/English) but the script gives an error: Fatal error: Call to undefined method SpecialPage::getpages() in ... -Eep² 14:03, 22 July 2007 (UTC)Reply[reply]
OK, I fixed that error by replacing the old MediaWiki 1.7.1 getPages() function with the new(?) MediaWiki 1.9.3 functions but now I get this error: Warning: array_push() [function.array-push]: First argument should be an array in ../includes/SpecialSpecialpages.php on line 152 (16x) which is array_push($kat[$cat], $sk->makeKnownLinkObj( $title, $desc ));.
OK, I'm an idiot; I had different named categories ("Site" and "Page") that were not in each array (whatever). I hate programming. The category declarations should only occur once anyway, but I didn't code this originally...and I'm not sure how to do it, other than $cat1 = "Category"; $cat2 = "hide";, etc, but that's lame. Anyway, it works now--only for MediaWiki 1.9.3 (and hopefully it works in 1.10.x but I haven't upgraded yet). I'd like to add other extension special pages in, too, and it'd be nice to have extensions automatically categorize themselves in multiple ways (extension name, alphabetically, date installed/added, and by general sections/categories as this script does). -Eep² 21:04, 22 July 2007 (UTC)Reply[reply]

Test note and Chinese version[edit]

Hi Patrick and Eep. Thanks for your sharing and this is has been tested on MediaWiki 1.11.0. See Chinese version--Roc michael 11:15, 5 December 2007 (UTC)Reply[reply]

German version does not work[edit]

Hello, i have the media Wiki version 1.11.2. It has two languages German and English. The English special pages works fine but the German special page does not identify the correct categories. The German translation of the link names does not allow the right allocation of categories.

Has anyone an idea to resolve this problem? Thank you very much! Thomas

Workaround[edit]

Es werden jetzt deutsche und alle englischen Seiten sortiert. Bis auf Seiten mit Umlauten (ä,ü,ö) in den Titeln. Dafür muss die die Datei "languages > messages > MessagesDE.php" geändert werden. Am einfachsten wäre es wohl die Umlaute umzuwandeln (ae,ue,oe). Das Problem dabei ist, dass beim nächsten Mediawiki Update diese Datei wieder überschrieben wird.... Weder das Eintragen der Seitennamen mit Umlauten noch deren ASCII Synonymen funktionierte.

<?php
/**
 * @package MediaWiki
 * @subpackage SpecialPage
 */
 
function wfSpecialSpecialpages() {
        global $wgOut, $wgUser;#, $wgAvailableRights;
 
        $wgOut->setRobotpolicy( 'index,nofollow' );
        $sk = $wgUser->getSkin();
 
        /** Pages available to all */
        wfSpecialSpecialpages_gen( SpecialPage::getRegularPages(), 'spheading', $sk );
 
        /** Restricted special pages */
        wfSpecialSpecialpages_gen( SpecialPage::getRestrictedPages(), 'restrictedpheading', $sk );
 
        # Get listable pages, in a 2-d array with the first dimension being user right
        #$pages = SpecialPage::getPages();
 
        /** Pages available to all */
        #wfSpecialSpecialpages_gen($pages[''],'spheading',$sk);
 
        /** Restricted special pages */
#        $rpages = array();
#        foreach($wgAvailableRights as $right) {
                /** only show pages a user can access */
#                if( $wgUser->isAllowed($right) ) {
                        /** some rights might not have any special page associated */
#                        if(isset($pages[$right])) {
#                                $rpages = array_merge( $rpages, $pages[$right] );
#                        }
#                }
#        }
#        wfSpecialSpecialpages_gen( $rpages, 'restrictedpheading', $sk );
}
 
/**
 * 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_gen($pages,$heading,$sk) {
        global $wgOut, $wgSortSpecialPages;
 
        if( count( $pages ) == 0 ) {
                # Yeah, that was pointless. Thanks for coming.
                return;
        }
 
        /** Put them into a sortable array */
        $sortedPages = array();
        foreach ( $pages as $page ) {
                if ( $page->isListed() ) {
                        $sortedPages[$page->getDescription()] = $page->getTitle();
                }
        }
 
        /** Sort */
        if ( $wgSortSpecialPages ) {
                ksort( $sortedPages );
        }
 
        # Set categories--ideally, using a wiki-editable page to supply these so this PHP file doesn't have to be dorked with...
        $catCategory   = "Category";
        $catFile       = "File";
        $catMediaWiki  = "MediaWiki";
        $catRedirects  = "Redirects";
        $catPage       = "Page";
        $catSearch     = "Search";
        $catTemplate   = "Template";
        $catUser       = "User";
        $catOther      = "Other"; #Miscellaneous
        $catHide       = "hide"; #For hidden pages, if any
 
        # Extension-specific:
        $catSemantic   = "Semantic"; #Semantic MediaWiki (SMW), Semantic Forms, etc
        $catData       = "Data Extension"; #Data Table
 
        # Use a "foreach" here? This is the actual order the categories will appear in.
        $cats[$catCategory] = Array();
        $cats[$catData] = Array();
        $cats[$catFile] = Array();
        $cats[$catMediaWiki] = Array();
        $cats[$catPage] = Array();
        $cats[$catRedirects] = Array();
        $cats[$catSearch] = Array();
        $cats[$catSemantic] = Array();
        $cats[$catTemplate] = Array();
        $cats[$catUser] = Array();
        $cats[$catOther] = Array();
        $cats[$catHide] = Array();
 
        foreach ( $sortedPages as $desc => $title ) {
                $t = $title->getText();
                $cat = "";
                switch ($t) {
                        /* Parse the page names for words in the categories, so "*page*" would go in the "Page" section? */
                    case "Categories":
                    case "CategoryTree": #Extension
                    case "Mostcategories":
                    case "Mostlinkedcategories":
                    case "Uncategorizedcategories":
                    case "Unusedcategories":
                    case "Wantedcategories":
					case "Verwaiste Kategorien":
					case "Nicht kategorisierte Kategorien":
					case "Kategorien":
					case "Meistbenutzte Kategorien":
					case "Unbenutzte Kategorien":
                        $cat = $catCategory;
                        break;
                    case "Imagelist":
                    case "Filepath": #Extension
                    case "Mostimages":
                    case "Newimages":
                    case "Unusedimages":
                    case "Upload":
                    case "Uncategorizedimages":
					case "Dateien":
					case "Unbenutzte Dateien":
					case "Nicht kategorisierte Dateien":
					case "Neue Dateien":
					case "Hochladen":
					case "Meistbenutzte Dateien":
                        $cat = $catFile;
                        break;
                    case "Allmessages":
                    case "Log":
                    case "Statistics":
                    case "Version":
					case "MediaWiki-Systemnachrichten":
					case "Statistik":
					case "Suche":
					case "MIME-Typ-Suche":
					case "Weiterleitungen":
					case "ISBN-Suche":
					case "Logbuch":
                        $cat = $catMediaWiki;
                        break;
                    case "Allpages":
                    case "Ancientpages":
                    case "CrossNamespaceLinks": #Extension
                    case "Deadendpages":
                    case "Disambiguations":
                    case "Export":
                    case "Import":
                    case "Lonelypages":
                    case "Longpages":
                    case "Mostlinked":
                    case "Mostrevisions":
                    case "Newpages":
                    case "Popularpages":
                    case "Prefixindex":
                    case "Random":
                    case "Recentchanges":
                    case "Shortpages":
                    case "Uncategorizedpages":
                    case "Undelete":
                    case "Unwatchedpages":
                    case "Wantedpages":
                    case "Whatlinkshere":
					case "Fewestrevisions":
					case "Withoutinterwiki":
					case "Protectedpages":
					case "Protectedtitles":
					case "Sackgassenseiten":
					case "Exportieren":
					case "Praefixindex":
					case "Importieren":
					case "Wiederherstellen":
					case "Ignorierte Seiten":
					case "Verwaiste Seiten":
					case "Fehlende Interwikis":
					case "Wenigstbearbeitete Seiten":
					case "Meistbearbeitete Seiten":
					case "Nicht kategorisierte Seiten":
					case "Neue Seiten":
					case "Alle Seiten":
					case "Beliebteste Seiten":
					case "Gesperrte Titel":
					case "Linkliste":
					case "Meistkategorisierte Seiten":
					    $cat = $catPage;
                        break;
                    case "Listredirects":
                    case "BrokenRedirects":
                    case "DoubleRedirects":
                    case "Randomredirect":
					case "Doppelte Weiterleitungen":
					case "Kaputte Weiterleitungen":
                        $cat = $catRedirects;
                        break;
                    case "Search":
                    case "Booksources":
                    case "Linksearch": #Extension
                    case "MIMEsearch":
					    $cat = $catSearch;
                        break;
                    case "Templates": #SMW extension (but vague enough to be in general section)
                    case "CreateTemplate": #SMW extension
                    case "ExpandTemplates": #Extension
                    case "Unusedtemplates": 
					case "Mostlinkedtemplates": 
					case "Uncategorizedtemplates": 
					case "Nicht kategorisierte Vorlagen":
					case "Unbenutzte Vorlagen":
					case "Meistbenutzte Vorlagen":
                        $cat = $catTemplate;
                        break;
                    case "Listusers":
                    case "Blockip":
                    case "CheckUser": #Extension
                    case "Contributions": #Extension
                    case "DeletedContributions": #Extension
					case "Disabledusers":#Extension
					case "UserScore":#Extension
					case "PasswordReset":#Extension
                    case "Ipblocklist":
                    case "Preferences":
                    case "Userlogin":
                    case "Userrights":
                    case "Watchlist":
					case "Benutzer":
					case "Anmelden":
					case "Beobachtungsliste":
					case "Sperren":
					case "Benutzerrechte":
					case "Einstellungen":
					case "Gesperrte IPs":
                        $cat = $catUser;
                        break;
                    case "AddData":
                    case "AddPage":
                    case "Ask":
                    case "Attributes":
                    case "Browse":
                    case "CreateForm":
                    case "CreateProperty":
                    case "EditData":
                    case "ExportRDF":
                    case "ExtendedStatistics":
                    case "Forms":
                    case "Relations":
                    case "SearchByAttribute":
                    case "SearchByRelation":
                    case "Types":
                    case "UnusedAttributes":
                    case "UnusedRelations":
                    case "WantedRelations":
                    case "SMWAdmin":
                        $cat = $catSemantic;
                        break;
                    case "Data":
                    case "Joindata":
                        $cat = $catData;
                        break;
                    default:
                    case "Form": #SpecialForm extension
                        $cat = $catOther;
                        break;
                        $cat = $catHide;
                        break;
                }
                array_push($cats[$cat], $sk->makeKnownLinkObj( $title, $desc ));
        }
 
        /** Now output the HTML */
        # A sortable table and/or multiple columns would be nice, optionally leaving in sections (section-sorting) or clumping altogether into a single list
#        $wgOut->addHTML('<table><tr valign=top>');
#        foreach ($heading as $heading) {
                $wgOut->addHTML( '<h2>' . wfMsgHtml( $heading ) . "</h2>\n<ul>" );
                foreach ( $cats as $title => $value ) {
                        if ($title == "hide")
                            continue;
                        if (sizeof($value) == 0)
                            continue;
                        $wgOut->addHTML( '<h3>' .  $title  . "</h3>\n<ul>" );
 
                        foreach ( $value as $link )
                            $wgOut->addHTML( "<li>{$link}</li>\n" );
                        $wgOut->addHTML( "</ul>" );
                }
                $wgOut->addHTML( "</ul>\n" );
#        $wgOut->addHTML( "</tr></table>" );
#       }
}
?>

Gruß Thomas