use Database::timestamp() for cutoff
[lhc/web/wiklou.git] / includes / SpecialAllpages.php
index 54b6442..32dcb6e 100644 (file)
@@ -2,12 +2,13 @@
 
 function wfSpecialAllpages( $par=NULL )
 {
-       global $from, $indexMaxperpage;
+       global $indexMaxperpage, $wgRequest;
        $indexMaxperpage = 480;
-
+       $from = $wgRequest->getVal( 'from' );
+       
        if( $par ) {
                indexShowChunk( $par );
-       } elseif( isset( $from ) ) {
+       } elseif( !is_null( $from ) ) {
                indexShowChunk( $from );
        } else {
                indexShowToplevel();
@@ -29,52 +30,46 @@ function indexShowToplevel()
                $log->showAsDisabledPage();
                return;
        }
-
-
-#      $fromwhere = "FROM cur WHERE cur_namespace=0 AND cur_is_redirect=0";
-       $fromwhere = "FROM cur WHERE cur_namespace=0";
-       $order = "ORDER BY cur_title";
-       $out = "";
        
-       $sql = "SELECT COUNT(*) AS count $fromwhere";
-       $res = wfQuery( $sql, DB_READ, $fname );
-       $s = wfFetchObject( $res );
-       $count = $s->count;
+       $dbr =& wfGetDB( DB_SLAVE );
+       $cur = $dbr->tableName( 'cur' );
+       $fromwhere = "FROM $cur WHERE cur_namespace=0";
+       $order = 'ORDER BY cur_title';
+       $out = "";
+       $where = array( 'cur_namespace' => 0 );
+
+       $count = $dbr->selectField( 'cur', 'COUNT(*)', $where, $fname );
        $sections = ceil( $count / $indexMaxperpage );
-       
-       $sql = "SELECT cur_title $fromwhere $order LIMIT 1";
-       $res = wfQuery( $sql, DB_READ, $fname );
-       $s = wfFetchObject( $res );
-       $inpoint = $s->cur_title;
+       $inpoint = $dbr->selectField( 'cur', 'cur_title', $where, $fname, $order );
        
        $out .= "<table>\n";
        # There's got to be a cleaner way to do this!
        for( $i = 1; $i < $sections; $i++ ) {
                $from = $i * $indexMaxperpage;
-               $sql = "SELECT cur_title $fromwhere $order LIMIT $from,2";
-               $res = wfQuery( $sql, DB_READ, $fname );
-       
-               $s = wfFetchObject( $res );
+               $sql = "SELECT cur_title $fromwhere $order ".wfLimitResult(2,$from);
+               $res = $dbr->query( $sql, $fname );
+
+               $s = $dbr->fetchObject( $res );
                $outpoint = $s->cur_title;
                $out .= indexShowline( $inpoint, $outpoint );
-       
-               $s = wfFetchObject( $res );
+
+               $s = $dbr->fetchObject( $res );
                $inpoint = $s->cur_title;
-               
-               wfFreeResult( $res );
+
+               $dbr->freeResult( $res );
        }
-       
+
        $from = $i * $indexMaxperpage;
-       $sql = "SELECT cur_title $fromwhere $order LIMIT " . ($count-1) . ",1";
-       $res = wfQuery( $sql, DB_READ, $fname );
-       $s = wfFetchObject( $res );
+       $sql = "SELECT cur_title $fromwhere $order ".wfLimitResult(1,$count-1);
+       $res = $dbr->query( $sql, $fname );
+       $s = $dbr->fetchObject( $res );
        $outpoint = $s->cur_title;
        $out .= indexShowline( $inpoint, $outpoint );
        $out .= "</table>\n";
 
        # Saving cache
        $log->replaceContent( $out );
-       
+
        $wgOut->addHtml( $out );
 }
 
@@ -82,13 +77,14 @@ function indexShowline( $inpoint, $outpoint )
 {
        global $wgOut, $wgLang, $wgUser;
        $sk = $wgUser->getSkin();
+       $dbr =& wfGetDB( DB_SLAVE );
 
        # Fixme: this is ugly
        $out = wfMsg(
                "alphaindexline",
                $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
                        str_replace( "_", " ", $inpoint ),
-                       "from=" . wfStrencode( $inpoint ) ) . "</td><td>",
+                       "from=" . $dbr->strencode( $inpoint ) ) . "</td><td>",
                "</td><td align=\"left\">" .
                str_replace( "_", " ", $outpoint )
                );
@@ -97,40 +93,54 @@ function indexShowline( $inpoint, $outpoint )
 
 function indexShowChunk( $from )
 {
-       global $wgOut, $wgUser, $indexMaxperpage;
+       global $wgOut, $wgUser, $indexMaxperpage, $wgLang;
        $sk = $wgUser->getSkin();
-       
+       $maxPlusOne = $indexMaxperpage + 1;
+
        $out = "";
-       $sql = "SELECT cur_title
-FROM cur
-WHERE cur_namespace=0 AND cur_title >= '" . wfStrencode( $from ) . "'
-ORDER BY cur_title
-LIMIT {$indexMaxperpage}";
-       $res = wfQuery( $sql, DB_READ, "indexShowChunk" );
-
-# FIXME: Dynamic column widths, backlink to main list,
-# side links to next and previous
+       $dbr =& wfGetDB( DB_SLAVE );
+       $cur = $dbr->tableName( 'cur' );
+       $sql = "SELECT cur_title FROM $cur WHERE cur_namespace=0 AND cur_title >= '"
+               . $dbr->strencode( $from ) . "' ORDER BY cur_title LIMIT " . $maxPlusOne;
+       $res = $dbr->query( $sql, "indexShowChunk" );
+
+       ### FIXME: side link to previous
+
        $n = 0;
-       $out = "<table border=\"0\">\n<tr>";
-       while( $s = wfFetchObject( $res ) ) {
+       $out = "<table border=\"0\" width=\"100%\">\n";
+       while( ($n < $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
                $t = Title::makeTitle( 0, $s->cur_title );
                if( $t ) {
                        $link = $sk->makeKnownLinkObj( $t );
                } else {
                        $link = "[[" . htmlspecialchars( $s->cur_title ) . "]]";
                }
-               $out .= "<td width=\"33%\">$link</td>";
-               $n = ++$n % 3;
-               if( $n == 0 ) {
-                       $out .= "</tr>\n<tr>";
+               if( $n % 3 == 0 ) {
+                       $out .= "<tr>\n";
+               }
+               $out .= "<td>$link</td>";
+               $n++;
+               if( $n % 3 == 0 ) {
+                       $out .= "</tr>\n";
                }
        }
-       if( $n != 0 ) {
+       if( ($n % 3) != 0 ) {
                $out .= "</tr>\n";
        }
        $out .= "</table>";
-#return $out;
-       $wgOut->addHtml( $out );
+
+       $out2 = "<div style='text-align: right; font-size: smaller; margin-bottom: 1em;'>" .
+                       $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
+                               wfMsg ( 'allpages' ) );
+       if ( ($n == $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
+               $out2 .= " | " . $sk->makeKnownLink(
+                       $wgLang->specialPage( "Allpages" ),
+                       wfMsg ( 'nextpage', $s->cur_title ),
+                       "from=" . $dbr->strencode( $s->cur_title ) );
+       }
+       $out2 .= "</div>";
+
+       $wgOut->addHtml( $out2 . $out );
 }
 
 ?>