24be9aad36182e90be375179a93da98374852076
4 * @addtogroup SpecialPage
10 function wfSpecialSpecialpages() {
11 global $wgOut, $wgUser, $wgMessageCache;
13 $wgMessageCache->loadAllMessages();
15 $wgOut->setRobotpolicy( 'noindex,nofollow' ); # Is this really needed?
17 # Read the special pages
18 $pagesRegular = SpecialPage
::getRegularPages();
19 $pagesRestricted = SpecialPage
::getRestrictedPages();
20 if( count( $pagesRegular ) == 0 && count( $pagesRestricted ) == 0 ) {
21 # Yeah, that was pointless. Thanks for coming.
25 # Put regular and restricted special pages into sortable arrays
26 $unsortedPagesRegular = wfSpecialSpecialpages_read( $pagesRegular );
27 $unsortedPagesRestricted = wfSpecialSpecialpages_read( $pagesRestricted );
30 $tpl = wfMsg( 'specialpages-tpl' );
33 # Parse the template and create a localized wikitext page
34 foreach ( explode( "\n", $tpl ) as $line ) {
35 # Look for 'special:' in the line
36 $pos = strpos( $line, 'special:' );
39 # Preserve the line start
40 $lineStart = ( $pos > 0 ) ?
substr( $line, 0, $pos ) : '';
42 # Get the canonical special page name
43 $canonical = strtolower( trim( substr( $line, $pos +
8 ) ) );
45 # Check if it is a valid regular special page name
46 # Restricted pages will be added at the end
47 if( isset( $unsortedPagesRegular[$canonical] ) ) {
49 $newSpecialPage .= $lineStart . "[[special:" . $canonical . "|" . $unsortedPagesRegular[$canonical] . "]]\n";
50 # Delete this regular special page from the array to avoid double output
51 unset( $unsortedPagesRegular[$canonical] );
53 # Ok, no valid special page, but add the line to the output
54 $newSpecialPage .= $line . "\n";
57 $newSpecialPage .= $line . "\n";
62 $newSpecialPage .= wfSpecialSpecialpages_out( 'specialpages-other', $unsortedPagesRegular );
63 # Add the restricted special pages
64 $newSpecialPage .= wfSpecialSpecialpages_out( 'restrictedpheading', $unsortedPagesRestricted );
66 # Output the customized special pages list
67 $wgOut->addWikiText( $newSpecialPage );
69 if ( $wgUser->isAllowed( 'editinterface' ) ) {
70 # Output a nice link to edit the template
71 $wgOut->addHtml( wfSpecialSpecialpages_edit() );
76 * Output the rest special pages as wikitext
77 * @param string $heading Message name for the heading
78 * @param array $sortedPages List of other special pages
79 * @return string $rest Wikitext
81 function wfSpecialSpecialpages_out( $heading, $pages ) {
82 global $wgOut, $wgSortSpecialPages;
84 if( count( $pages ) == 0 ) {
85 # Yeah, that was pointless. Thanks for coming.
90 if ( $wgSortSpecialPages ) {
94 # Now output the rest special pages as wikitext
95 $rest = '== ' . wfMsgExt( $heading, array( 'parseinline' ) ) . " ==\n";
96 foreach ( $pages as $title => $desc ) {
97 $rest .= "* [[special:" . $title . "|" . $desc . "]]\n";
103 * Create array with descriptions and names of special pages
104 * @param array $pagelist List of special pages
105 * @return array $unsortedPagesList Wikitext
107 function wfSpecialSpecialpages_read( $pagelist ) {
108 $unsortedPagesList = array();
109 foreach ( $pagelist as $page ) {
110 if ( $page->isListed() ) {
111 $name = strtolower( $page->getName() );
112 $unsortedPagesList[$name] = $page->getDescription();
115 return $unsortedPagesList;
119 * Build edit link to MediaWiki:specialpages-tpl
123 function wfSpecialSpecialpages_edit() {
124 global $wgUser, $wgContLang;
125 $align = $wgContLang->isRtl() ?
'left' : 'right';
126 $skin = $wgUser->getSkin();
127 $link = $skin->makeLink ( 'MediaWiki:specialpages-tpl', wfMsgHtml( 'specialpages-edit' ) );
128 return '<p style="float:' . $align . ';" class="mw-specialspecialpages-edit">' . $link . '</p>';