SpecialPages grouped into categories/zh

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

English version by User:Eep

中文版本(Chinese version)修訂者Roc michael

Note: this is for MediaWiki 1.9.3 and has not been tested on any other version (if you test it on other/newer versions, please mention it here). It differs from the original version which was designed for MediaWiki 1.7.x.

Check here to see this in action.

If you can optimize it better, please do; see comments. Ideally, an extension should be created (so it doesn't mess with the wiki's main files) that automatically pulls in the existing special pages, groups them into user-customizable categories (with default ones specified), allows sorting into categories for extension-specified special pages (such as the ones by Semantic MediaWiki, Semantic Forms, etc), and in a sortable table or list format (which Dynamic Page List may be able to do).

  • 注意:此中文版本僅於MediaWiki 1.11.0上測試過(this is for MediaWiki 1.11.0 and has not been tested on any other version .)。
  • 歡迎編輯本頁(Welcome to edit this page)
  • 檔案存放位置(File location): ../includes/SpecialSpecialpages.php

程式碼[edit]

<?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)";
        $catTodo       = "待辦事項(Todo)";
        $catOther      = "其他(Other)"; #Miscellaneous
        $catHide       = "隱藏(hide)"; #For hidden pages, if any
 
        # Extension-specific:
        $catSemantic   = "語意維基(Semantic)"; #Semantic MediaWiki (SMW), Semantic Forms, etc
        $catSD         = "語意鑽取(Semantic Drilldown)";        
        $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[$catSD] = Array();
        $cats[$catTemplate] = Array();
        $cats[$catUser] = Array();
        $cats[$catTodo] = 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":
                        $cat = $catCategory;
                        break;
                    case "Imagelist":
                    case "Filepath": #Extension
                    case "Mostimages":
                    case "Newimages":
                    case "Unusedimages":
                    case "Upload":
                    case "Uncategorizedimages":
                        $cat = $catFile;
                        break;
                    case "Allmessages":
                    case "Log":
                    case "Statistics":
                    case "Version":
                        $cat = $catMediaWiki;
                        break;
                    case "Allpages":
                    case "Ancientpages":
                    case "CrossNamespaceLinks": #Extension
                    case "Deadendpages":
                    case "Disambiguations":
                    case "Export":
                    case "Fewestrevisions":
                    case "Import":
                    case "Lonelypages":
                    case "Longpages":
                    case "Mostlinked":
                    case "Mostrevisions":
                    case "Newpages":
                    case "Popularpages":
                    case "Prefixindex":
                    case "Protectedpages":
                    case "Random":
                    case "Recentchanges":
                    case "Shortpages":
                    case "Uncategorizedpages":
                    case "Undelete":
                    case "Unwatchedpages":
                    case "Wantedpages":
                    case "Whatlinkshere":
                        $cat = $catPage;
                        break;
                    case "Listredirects":
                    case "BrokenRedirects":
                    case "DoubleRedirects":
                    case "Randomredirect":
                        $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 "Mostlinkedtemplates":
                    case "CreateTemplate": #SMW extension
                    case "ExpandTemplates": #Extension
                    case "Uncategorizedtemplates":                          
                    case "Unusedtemplates": #SMW extension
                        $cat = $catTemplate;
                        break;
                    case "Listusers":
                    case "Blockip":
                    case "CheckUser": #Extension
                    case "Contributions": #Extension
                    case "DeletedContributions": #Extension
                    case "Ipblocklist":
                    case "Preferences":
                    case "Userlogin":
                    case "Userrights":
                    case "Watchlist":
                        $cat = $catUser;
                        break;
                    case "TaskList":
                    case "TaskListByProject":  
                        $cat = $catTodo;
                        break;
                    case "AddData":
                    case "AddPage":
                    case "Ask":
                    case "Attributes":
                    case "Browse":
                    case "CreateCategory":          
                    case "CreateForm":
                    case "CreateProperty":
                    case "EditData":
                    case "ExportRDF":
                    case "ExtendedStatistics":
                    case "Forms":
                    case "Properties":                    
                    case "Relations":
                    case "SearchByAttribute":
                    case "SearchByRelation":
                    case "SearchByProperty":
                    case "SemanticStatistics":                    
                    case "Types":
                    case "UnusedAttributes":
                    case "UnusedProperties":
                    case "UnusedRelations":
                    case "WantedProperties":                    
                    case "WantedRelations":
                    case "SMWAdmin":                  
                        $cat = $catSemantic;
                        break;
                    case "Filters": 
                    case "CreateFilter":                                     
                    case "BrowseData": 
                        $cat = $catSD;
                        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>" );
#       }
}
?>

參見[edit]