* Added a versionRequired() function to OutputPage, useful for extension
[lhc/web/wiklou.git] / includes / SpecialAllpages.php
index 2dd4907..4c704e3 100644 (file)
@@ -8,7 +8,7 @@
  * Entry point : initialise variables and call subfunctions.
  * @param string $par Becomes "FOO" when called like Special:Allpages/FOO (default NULL)
  */
-function wfSpecialAllpages( $par=NULL ) {
+function wfSpecialAllpages( $par=NULL, $specialPage ) {
        global $indexMaxperpage, $toplevelMaxperpage, $wgRequest, $wgOut, $wgContLang;
        # Config
        $indexMaxperpage = 480;
@@ -18,30 +18,29 @@ function wfSpecialAllpages( $par=NULL ) {
        $namespace = $wgRequest->getInt( 'namespace' );
        $invert = $wgRequest->getBool( 'invert' );
        
-       $names = $wgContLang->getNamespaces();
+       $namespaces = $wgContLang->getNamespaces();
 
-       if( !isset( $names[$namespace] ) ) {
+       if( !in_array($namespace, array_keys($namespaces)) )
                $namespace = 0;
-       }
 
        if ($invert) {
                $wgOut->setPagetitle( $namespace > 0 ?
-                       wfMsg( 'allnotinnamespace', $names[$namespace] ) :
+                       wfMsg( 'allnotinnamespace', $namespaces[$namespace] ) :
                        wfMsg( 'allnonarticles' )
                        );
        } else {
                $wgOut->setPagetitle( $namespace > 0 ?
-                       wfMsg( 'allinnamespace', $names[$namespace] ) :
+                       wfMsg( 'allinnamespace', $namespaces[$namespace] ) :
                        wfMsg( 'allarticles' )
                        );
        }
        
-       if ( $par ) {
-               indexShowChunk( $namespace, $par, $invert );
-       } elseif ( $from ) {
-               indexShowChunk( $namespace, $from, $invert );
+       if ( isset($par) ) {
+               indexShowChunk( $namespace, $par, $invert, $specialPage->including() );
+       } elseif ( isset($from) ) {
+               indexShowChunk( $namespace, $from, $invert, $specialPage->including() );
        } else {
-               indexShowToplevel ( $namespace, $invert );
+               indexShowToplevel ( $namespace, $invert, $specialPage->including() );
        }
 }
 
@@ -51,39 +50,53 @@ function wfSpecialAllpages( $par=NULL ) {
  * @param string $from Article name we are starting listing at.
  * @param bool $invert true if we want the namespaces inverted (default false)
  */
-function namespaceForm ( $namespace = NS_MAIN, $from = '', $invert ) {
+function indexNamespaceForm ( $namespace = NS_MAIN, $from = '', $invert = false ) {
        global $wgContLang, $wgScript;
        $t = Title::makeTitle( NS_SPECIAL, "Allpages" );
 
-       $namespaceselect = '<select name="namespace">';
-       $arr = $wgContLang->getNamespaces();
+       $namespaceselect = "<select name='namespace' id='nsselectbox'>";
+       $arr = $wgContLang->getFormattedNamespaces();
        foreach ( $arr as $ns => $name ) {
-               if ( $ns < NS_MAIN ) continue;
-               $namespacename = str_replace ( '_', ' ', $name);
-               $n = ($ns == 0) ? wfMsg ( 'blanknamespace' ) : $namespacename;
-               $sel = ($ns == $namespace) ? ' selected="selected"' : '';
-               $namespaceselect .= "<option value='{$ns}'{$sel}>{$n}</option>";        
+               if ($ns < NS_MAIN)
+                       continue;
+               $n = $ns == 0 ? wfMsg ( 'blanknamespace' ) : $name;
+               $sel = $ns == $namespace ? ' selected="selected"' : '';
+               $namespaceselect .= "<option value='$ns'$sel>$n</option>";      
        }
        $namespaceselect .= '</select>';
 
-       $frombox = '<input type="text" size="20" name="from" value="'
+       $frombox = "<input type='text' size='20' name='from' id='nsfrom' value=\""
                    . htmlspecialchars ( $from ) . '"/>';
        $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
        
-       $invertbox = "<input type='checkbox' name='invert' value='1'" . ( $invert ? ' checked="checked"' : '' ) . ' />';
+       $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ? ' checked="checked"' : '' ) . ' />';
 
        $out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>";
        $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
-       $out .= wfMsg ( 'allpagesformtext', $frombox, $namespaceselect, $submitbutton, $invertbox );
+       $out .= "
+<table id='nsselect' class='allpages'>
+       <tr>
+               <td align='right'>" . wfMsg('allpagesfrom') . "</td>
+               <td align='left'><label for='nsfrom'>$frombox</label></td>
+       </tr>
+       <tr>    
+               <td align='right'><label for='nsselectbox'>" . wfMsg('namespace') . "</label></td>
+               <td align='left'>
+                       $namespaceselect $submitbutton $invertbox
+                       <label for='nsinvert'>" . wfMsg('invert') . "</label>
+               </td>
+       </tr>
+</table>
+";
        $out .= '</form></div>';
-       return $out;
+               return $out;
 }
 
 /**
  * @param integer $namespace (default NS_MAIN)
  * @param bool $invert true if we want the namespaces inverted (default false)
  */
-function indexShowToplevel ( $namespace = NS_MAIN, $invert ) {
+function indexShowToplevel ( $namespace = NS_MAIN, $invert = false,  $including = false ) {
        global $wgOut, $indexMaxperpage, $toplevelMaxperpage, $wgContLang, $wgRequest, $wgUser;
        $sk = $wgUser->getSkin();
        $fname = "indexShowToplevel";
@@ -106,7 +119,7 @@ function indexShowToplevel ( $namespace = NS_MAIN, $invert ) {
        if ( $sections < 3 ) {
                # If there are only two or less sections, don't even display them.
                # Instead, display the first section directly.
-               indexShowChunk( $namespace, '', $invert );
+               indexShowChunk( $namespace, '', $invert, $including );
                return;
        }
 
@@ -153,33 +166,37 @@ function indexShowToplevel ( $namespace = NS_MAIN, $invert ) {
        }
        $out .= '</table>';
        
-       $nsForm = namespaceForm ( $namespace, '', $invert );
-
+       $nsForm = indexNamespaceForm ( $namespace, '', $invert );
+       
        # Is there more?
-       $morelinks = '';
-       if ( $offset > 0 ) {
-               $morelinks = $sk->makeKnownLink (
-                       $wgContLang->specialPage ( 'Allpages' ),
-                       wfMsg ( 'allpagesprev' ),
-                       ( $offset > $toplevelMaxperpage ) ? 'offset='.($offset-$toplevelMaxperpage) : ''
-               );
-       }
-       if ( $stopat < $sections-1 ) {
-               if ( $morelinks != '' ) { $morelinks .= " | "; }
-               $morelinks .= $sk->makeKnownLink (
-                       $wgContLang->specialPage ( 'Allpages' ),
-                       wfMsg ( 'allpagesnext' ),
-                       'offset=' . ($offset + $toplevelMaxperpage)
-               );
-       }
-
-       if ( $morelinks != '' ) {
-               $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
-               $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
-               $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">';
-               $out2 .= $morelinks . '</td></tr></table><hr />';
+       if ( $including ) {
+               $out2 = '';
        } else {
-               $out2 = $nsForm . '<hr />';
+               $morelinks = '';
+               if ( $offset > 0 ) {
+                       $morelinks = $sk->makeKnownLink (
+                               $wgContLang->specialPage ( 'Allpages' ),
+                               wfMsg ( 'allpagesprev' ),
+                               ( $offset > $toplevelMaxperpage ) ? 'offset='.($offset-$toplevelMaxperpage) : ''
+                       );
+               }
+               if ( $stopat < $sections-1 ) {
+                       if ( $morelinks != '' ) { $morelinks .= " | "; }
+                       $morelinks .= $sk->makeKnownLink (
+                               $wgContLang->specialPage ( 'Allpages' ),
+                               wfMsg ( 'allpagesnext' ),
+                               'offset=' . ($offset + $toplevelMaxperpage)
+                       );
+               }
+
+               if ( $morelinks != '' ) {
+                       $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
+                       $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
+                       $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">';
+                       $out2 .= $morelinks . '</td></tr></table><hr />';
+               } else {
+                       $out2 = $nsForm . '<hr />';
+               }
        }
 
        $wgOut->addHtml( $out2 . $out );
@@ -215,7 +232,7 @@ function indexShowline( $inpoint, $outpoint, $namespace = NS_MAIN, $invert ) {
  * @param string $from list all pages from this name (default FALSE)
  * @param bool $invert true if we want the namespaces inverted (default false)
  */
-function indexShowChunk( $namespace = NS_MAIN, $from, $invert ) {
+function indexShowChunk( $namespace = NS_MAIN, $from, $invert = false, $including = false ) {
        global $wgOut, $wgUser, $indexMaxperpage, $wgContLang;
        $sk = $wgUser->getSkin();
        $maxPlusOne = $indexMaxperpage + 1;
@@ -238,17 +255,14 @@ function indexShowChunk( $namespace = NS_MAIN, $from, $invert ) {
        $n = 0;
        $out = '<table style="background: inherit;" border="0" width="100%">';
        
-       $namespaces = $wgContLang->getNamespaces();
-       foreach($namespaces as $key => $ns) {
-               $namespaces[$key] = str_replace('_', ' ', $namespaces[$key]);
-       }
+       $namespaces = $wgContLang->getFormattedNamespaces();
        while( ($n < $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
                $t = Title::makeTitle( $s->page_namespace, $s->page_title );
                if( $t ) {
                        $ns = $s->page_namespace;
-                       $s = $invert && $namespaces[$ns] != $wgContLang->getNsText(NS_MAIN) ? ':' : '';
-                       $n = $invert ? $namespaces[$ns] : '';
-                       $link = $sk->makeKnownLinkObj( $t, $t->getText(), false, false, $n . $s ); 
+                       $prefix = $invert ? $namespaces[$ns] : '';
+                       $prefix .= $invert && $namespaces[$ns] != $wgContLang->getNsText(NS_MAIN) ? ':' : '';
+                       $link = $sk->makeKnownLinkObj( $t, $t->getText(), false, false, $prefix ); 
                } else {
                        $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
                }
@@ -266,21 +280,25 @@ function indexShowChunk( $namespace = NS_MAIN, $from, $invert ) {
        }
        $out .= '</table>';
        
-       $nsForm = namespaceForm ( $namespace, $from, $invert );
-       $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
-       $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
-       $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
-                       $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
-                               wfMsg ( 'allpages' ) );
-       if ( ($n == $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
-               $namespaceparam = $namespace ? "&namespace=$namespace" : "";
-               $invertparam = $invert ? "&invert=$invert" : '';
-               $out2 .= " | " . $sk->makeKnownLink(
-                       $wgContLang->specialPage( "Allpages" ),
-                       wfMsg ( 'nextpage', $s->page_title ),
-                       "from=" . wfUrlEncode ( $s->page_title ) . $namespaceparam . $invertparam );
+       if ( $including ) {
+               $out2 = '';
+       } else {
+               $nsForm = indexNamespaceForm ( $namespace, $from, $invert );
+               $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
+               $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
+               $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
+                               $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
+                                       wfMsg ( 'allpages' ) );
+               if ( ($n == $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
+                       $namespaceparam = $namespace ? "&namespace=$namespace" : "";
+                       $invertparam = $invert ? "&invert=$invert" : '';
+                       $out2 .= " | " . $sk->makeKnownLink(
+                               $wgContLang->specialPage( "Allpages" ),
+                               wfMsg ( 'nextpage', $s->page_title ),
+                               "from=" . wfUrlEncode ( $s->page_title ) . $namespaceparam . $invertparam );
+               }
+               $out2 .= "</td></tr></table><hr />";
        }
-       $out2 .= "</td></tr></table><hr />";
 
        $wgOut->addHtml( $out2 . $out );
 }