* Moving hardcoded styles into CSS.
[lhc/web/wiklou.git] / includes / SpecialAllpages.php
index 99e457f..70f52ea 100644 (file)
@@ -1,13 +1,12 @@
 <?php
 /**
- *
  * @package MediaWiki
  * @subpackage SpecialPage
  */
 
 /**
  * Entry point : initialise variables and call subfunctions.
- * @param string $par ????? (default NULL)
+ * @param string $par Becomes "FOO" when called like Special:Allpages/FOO (default NULL)
  */
 function wfSpecialAllpages( $par=NULL ) {
        global $indexMaxperpage, $toplevelMaxperpage, $wgRequest, $wgOut, $wgContLang;
@@ -17,7 +16,7 @@ function wfSpecialAllpages( $par=NULL ) {
        # GET values
        $from = $wgRequest->getVal( 'from' );
        $namespace = $wgRequest->getInt( 'namespace' );
-       $invert = $wgRequest->getInt( 'invert' );
+       $invert = $wgRequest->getBool( 'invert' );
        
        $names = $wgContLang->getNamespaces();
 
@@ -50,8 +49,9 @@ function wfSpecialAllpages( $par=NULL ) {
  * HTML for the top form
  * @param integer $namespace A namespace constant (default NS_MAIN).
  * @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 = 0) {
+function namespaceForm ( $namespace = NS_MAIN, $from = '', $invert ) {
        global $wgContLang, $wgScript;
        $t = Title::makeTitle( NS_SPECIAL, "Allpages" );
 
@@ -70,7 +70,7 @@ function namespaceForm ( $namespace = NS_MAIN, $from = '', $invert = 0) {
                    . htmlspecialchars ( $from ) . '"/>';
        $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
        
-       $invertbox = "<input type='checkbox' name='invert' value='1'" . ( $invert == 1 ? ' checked="checked"' : '' ) . ' />';
+       $invertbox = "<input type='checkbox' name='invert' value='1'" . ( $invert ? ' checked="checked"' : '' ) . ' />';
 
        $out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>";
        $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
@@ -80,22 +80,21 @@ function namespaceForm ( $namespace = NS_MAIN, $from = '', $invert = 0) {
 }
 
 /**
- * @todo Document
  * @param integer $namespace (default NS_MAIN)
+ * @param bool $invert true if we want the namespaces inverted (default false)
  */
-function indexShowToplevel ( $namespace = NS_MAIN, $invert = 0 ) {
+function indexShowToplevel ( $namespace = NS_MAIN, $invert ) {
        global $wgOut, $indexMaxperpage, $toplevelMaxperpage, $wgContLang, $wgRequest, $wgUser;
        $sk = $wgUser->getSkin();
        $fname = "indexShowToplevel";
-       $namespace = intval ($namespace);
 
        # TODO: Either make this *much* faster or cache the title index points
        # in the querycache table.
 
        $dbr =& wfGetDB( DB_SLAVE );
        $page = $dbr->tableName( 'page' );
-       $invsql = ($invert) ? '!' : '';
-       $fromwhere = "FROM $page WHERE page_namespace$invsql=$namespace";
+       $fromwhere = "FROM $page WHERE page_namespace" .
+       ($invert ? '!' : '') . "=$namespace";
        $order_arr = array ( 'ORDER BY' => 'page_title' );
        $order_str = 'ORDER BY page_title';
        $out = "";
@@ -149,7 +148,7 @@ function indexShowToplevel ( $namespace = NS_MAIN, $invert = 0 ) {
        while ( count ( $lines ) > 0 ) {
                $inpoint = array_shift ( $lines );
                $outpoint = array_shift ( $lines );
-               $out .= indexShowline ( $inpoint, $outpoint, $namespace );
+               $out .= indexShowline ( $inpoint, $outpoint, $namespace, $invert );
        }
        $out .= '</table>';
        
@@ -189,15 +188,16 @@ function indexShowToplevel ( $namespace = NS_MAIN, $invert = 0 ) {
  * @todo Document
  * @param string $from 
  * @param integer $namespace (Default NS_MAIN)
+ * @param bool $invert true if we want the namespaces inverted (default false)
  */
-function indexShowline( $inpoint, $outpoint, $namespace = NS_MAIN ) {
+function indexShowline( $inpoint, $outpoint, $namespace = NS_MAIN, $invert ) {
        global $wgOut, $wgLang, $wgUser;
        $sk = $wgUser->getSkin();
        $dbr =& wfGetDB( DB_SLAVE );
 
        $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
        $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
-       $queryparams = $namespace ? ('namespace='.intval($namespace)) : '';
+       $queryparams = ($namespace ? "namespace=$namespace" : '') . ($invert ? "&invert=$invert" : '');
        $special = Title::makeTitle( NS_SPECIAL, 'Allpages/' . $inpoint );
        $link = $special->escapeLocalUrl( $queryparams );
        
@@ -209,11 +209,15 @@ function indexShowline( $inpoint, $outpoint, $namespace = NS_MAIN ) {
        return '<tr><td align="right">'.$out.'</td></tr>';
 }
 
+/**
+ * @param integer $namespace (Default NS_MAIN)
+ * @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 ) {
        global $wgOut, $wgUser, $indexMaxperpage, $wgContLang;
        $sk = $wgUser->getSkin();
        $maxPlusOne = $indexMaxperpage + 1;
-       $namespacee = intval($namespace);
 
        $out = '';
        $dbr =& wfGetDB( DB_SLAVE );
@@ -222,8 +226,8 @@ function indexShowChunk( $namespace = NS_MAIN, $from, $invert ) {
        $fromTitle = Title::newFromURL( $from );
        $fromKey = is_null( $fromTitle ) ? '' : $fromTitle->getDBkey();
        
-       $invsql = ($invert) ? '!' : '';
-       $sql = "SELECT page_title FROM $page WHERE page_namespace$invsql=$namespacee" .
+       $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace" .
+               ($invert ? '!' : '') . "=$namespace" .
                " AND page_title >= ".  $dbr->addQuotes( $fromKey ) .
                " ORDER BY page_title LIMIT " . $maxPlusOne;
        $res = $dbr->query( $sql, 'indexShowChunk' );
@@ -232,10 +236,18 @@ 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]);
+       }
        while( ($n < $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
-               $t = Title::makeTitle( $namespacee, $s->page_title );
+               $t = Title::makeTitle( $s->page_namespace, $s->page_title );
                if( $t ) {
-                       $link = $sk->makeKnownLinkObj( $t, $t->getText() );
+                       $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 ); 
                } else {
                        $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
                }