Extension:SpecialPagesOrganizer
From MediaWiki.org
|
SpecialPagesOrganizer Release status: stable |
|
|---|---|
| Implementation | Special page |
| Description | provides an easy way to reorder and organize the way pages are displayed on the specialpages page. |
| Author(s) | Artem Kaznatcheev, Schneelocke |
| Version | 1.1 (2008-06-24) |
| MediaWiki | <1.13 |
| Download | from page |
| Parameters | $egDisplayNCSP, $egOrderArray, $egPageName, $egOrderRP |
| Hooks used | SpecialPageExecuteBeforePage |
On the standard MediaWiki distribution, the Specialpages special page (the one that lists all the Special Pages) is badly organized and hard to navigate. In the standard version the special pages are listed in alphabetical order and with a large amount of pages it becomes impossible to navigate. The normal way to overcome this order is to hack the code and modify SpecialSpecialpages.php, however sometimes that is unwanted. This extension provides an easy way to reorder your pages and organize them under any heading without leaving LocalSettings.php. For any pages your reorganize, the extension also allows you to change the linking text.
Contents |
[edit] Old Way
The old way involved opening SpecialSpecialpages.php and recoding part of it with a giant case statement to sort all the special pages into various sections.
[edit] Installing
- Create a file called
SpecialPagesOrganizer.phpin your extensions directory. - Copy and paste the SpecialPagesOrganizer code into the new file
- In
LocalSettings.php, create an array called$egOrderArrayfollowing the following template:$egOrderArray["<section title>"] = array('specialpage 1', 'specialpage 2', 'specialpage n');
- In
LocalSettings.php, add the following line:require_once( "$IP/extensions/SpecialPagesOrganizer.php");
- In
LocalSettings.php, add any of the extensions global settings you want set.
[edit] Settings
Currently, the properties of the extension can only be effected by people with access to LocalSettings.php.
[edit] $egOrderArray
This is an associative array of arrays. The first (associative) index is named by the desired name of each section, into which the pages will be split up. Each name index points to an array of special page names that lists which pages will be displayed in the section. You have to use the official programming names of the special pages, not the names they are given on the site. There is an example (the same division as in english wiki), I think:
$egOrderArray["Maintenance reports"] = array('Uncategorizedpages', 'Uncategorizedcategories', 'Uncategorizedimages', 'Uncategorizedtemplates', 'Unusedcategories', 'Unusedimages', 'Unusedtemplates', 'BrokenRedirects', 'DoubleRedirects', 'Longpages', 'Lonelypages', 'Withoutinterwiki', 'Protectedpages', 'Protectedtitles'); $egOrderArray["Login / sign up"] = array('Userlogin'); $egOrderArray["Recent changes and logs"] = array('Newimages', 'Log', 'Watchlist', 'Newpages', 'Recentchanges'); $egOrderArray["Media reports and uploads"] = array('Filepath', 'Imagelist', 'MIMEsearch', 'Upload'); $egOrderArray["Users and rights"] = array('Ipblocklist', 'Contributions', 'Listusers'); $egOrderArray["Pages in need of work"] = array('Deadendpages', 'Ancientpages', 'Shortpages', 'Wantedcategories', 'Wantedpages'); $egOrderArray["High use pages"] = array('Mostlinkedcategories', 'Mostimages', 'Mostlinked', 'Mostlinkedtemplates', 'Mostcategories', 'Mostrevisions');
Make sure to define this array before you include SpecialPagesOrganizer.php
[edit] $egDisplayNCSP
This is a boolean that defines if the non-classified special pages should be displayed at the bottom of the specialpages page. This is provided as a tool for the admin to see what pages they have not yet thrown into another group. In general it is advised to set this to false once the desired groups are achieved.
Make sure to set this boolean after you include SpecialPagesOrganizer.php
[edit] $egOrderRP
This is a boolean that defines if the restricted pages should be orderable, or if they should just be included in one big "restricted pages" grouping. You will not be able to use this to make pages that people do not have the privelage to see visible, but you can use it to sort the restricted pages into categories like the normal pages, inside $egOrderArray.
Make sure to set this boolean after you include SpecialPagesOrganizer.php
[edit] $egPageNameArray
This is an associative array of strings. The associative index is the special page name (like the ones you used in $egOrderArray. The value is the new link text for that item. For the code to work, you need the special page you are dealing with to also appear somewhere in $egOrderArray. An example that replaces the link text for the Randompage special page from "Random Page" to "OMG a RANDOM PAGE!".
$egPageNameArray['Randompage'] = "OMG a RANDOM PAGE!";
Make sure to set this boolean after you include SpecialPagesOrganizer.php
[edit] Code
<?php /* SpecialPagesOrganizer 1.1 - a special pages organizer for MediaWiki * Copyright (C) 2008 Artem Kaznatcheev * * 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, see <http://www.gnu.org/licenses/>. */ # Not a valid entry point, skip unless MEDIAWIKI is defined if (!defined('MEDIAWIKI')) {exit( 1 );} $wgExtensionCredits['other'][] = array( 'name' => 'Specialpages Organizer', 'version' => '1.1', 'author' => 'Artem Kaznatcheev, Schneelocke', 'description' => 'reorders the special pages on the specialpages page', 'url' => 'http://www.mediawiki.org/wiki/Extension:SpecialPagesOrganizer' ); $egDisplayNCSP = True; //default value $egOrderRP = False; //default value $egPageNameArray = array(); //default value /* * This function effectively replaces wfSpecialSpecialpages. It should be * called by the 'SpecialPageExecuteBeforePage' hook. As data, this page * will need an array of arrays to show how the categorization breaks down. * The outer array is assosiative and should be indexed by the desired * names of the section. The data each index holds is an array of all the * items in that section, listed by their proper name (which can be found * at the start of SpecialPages.php) */ function efReorderSpecial($order, $specialpage, $par, $func){ // The if statement is to check for being on the right page. // If on the wrong page, execution continues as normal if (($specialpage->getName()) != 'Specialpages'){ return true; } global $wgOut, $wgUser, $egDisplayNCSP, $egOrderRP; $wgOut->setRobotpolicy( 'index,nofollow' ); $sk = $wgUser->getSkin(); //get the list of all Regular Special Pages $fullList = SpecialPage::getRegularPages(); if ($egOrderRP) { //get restricted pages if desired $fullList = array_merge($fullList, SpecialPage::getRestrictedPages()); } //for each section, populate the Special Pages foreach ($order as $head => $members) { $subList = array(); foreach ($members as $member){ $subList[$member] = $fullList[$member]; unset($fullList[$member]); //remove the item from the fullList array } efReorderSpecialpages_gen($subList, $head, $sk); } if (!($egOrderRP)) { //get restricted pages if they where not fetched earlier wfSpecialSpecialpages_gen( SpecialPage::getRestrictedPages(), 'restrictedpheading', $sk ); } if ($egDisplayNCSP) { //generate the "Others" section efReorderSpecialpages_gen($fullList, 'Non-Categorized Specialpages', $sk); } return false; } /* * This function is made to output the ordered arrays, with the proper * titles. Most of this function is copied from wfSpecialSpecialpages_gen * in SpecialSpecialpages.php */ function efReorderSpecialpages_gen($pages,$heading,$sk) { global $wgOut, $wgSortSpecialPages, $egPageNameArray; if( count( $pages ) == 0 ) { return; } $sortedPages = array(); foreach ( $pages as $name => $page ) { if ( $page && $page->isListed() ) { if (array_key_exists($name, $egPageNameArray)) { $pageName = $egPageNameArray[$name]; } else { $pageName = $page->getDescription(); } $sortedPages[$pageName] = $page->getTitle();; } } if ( $wgSortSpecialPages ) { ksort( $sortedPages ); } /* * Now output the HTML * This section is modified to take the titles straight from the array, * without "wfMsgHtml" */ $wgOut->addHTML('<h2>'.$heading."</h2>\n<ul>"); foreach ( $sortedPages as $desc => $title ) { $link = $sk->makeKnownLinkObj( $title , htmlspecialchars( $desc ) ); $wgOut->addHTML( "<li>{$link}</li>\n" ); } $wgOut->addHTML( "</ul>\n" ); } //below is the hook that actually brings the array into the wiki $wgHooks['SpecialPageExecuteBeforePage'][] = array('efReorderSpecial', $egOrderArray); ?>
[edit] Changes
[edit] 1.1
- Fix: added
$egOrderRPin global statement in line 50
[edit] 1.0
- Allowed the ordering of restricted pages
- Introducted a global variable
$egOrderRP
- Introducted a global variable
- Moved out of beta
[edit] 0.5
- Really minor style changes in the code
- Provided the ability to rename links to special pages
- Introduced a global array
$egPageNameArray
- Introduced a global array
[edit] 0.4
- Introduced a license on the extension
- Expanded the registering
- Improved style
- Added a function to display uncategorized pages (so that users know what pages are left)
- Added a global variable
$egDisplayNCSP
- Added a global variable
[edit] 0.3
- Fix "Warning: call_user_func(efReoderSpecial) [function.call-user-func]: First argument is expected to be a valid callback", "Fatal error: Call to a member function isListed() on a non-object" and "Detected bug in an extension! Hook efReorderSpecial failed to return a value; should return true to continue hook processing or false to abort." (Schneelocke)
[edit] 0.2
- Extension modified to register properly on Special:Version page
[edit] Future Improvements
If you have some ideas or features you would like to see if future releases of the SpecialPagesOrganizer, please add them to the ideas page. I will try to implement them when I have time. Below potential future features are listed.
- Fancy javascript
- Collapseable sections
- Loading special pages inside the organizer page

