SpecialPages grouped into categories/English
![]() | This extension is obsolete!
It has been replaced by core functionality in the MediaWiki software (which was added in version 1.13.0). |
中文版本(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).
<?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":
$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 "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":
$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 "CreateTemplate": #SMW extension
case "ExpandTemplates": #Extension
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 "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>" );
# }
}
?>