wiki.techinc.nl/includes/SpecialAllpages.php

150 lines
3.8 KiB
PHP
Raw Normal View History

<?php
2003-04-14 23:10:40 +00:00
function wfSpecialAllpages( $par=NULL )
2003-04-14 23:10:40 +00:00
{
global $indexMaxperpage, $wgRequest;
2003-04-14 23:10:40 +00:00
$indexMaxperpage = 480;
2004-04-01 12:53:01 +00:00
$from = $wgRequest->getVal( 'from' );
$namespace = $wgRequest->getVal( 'namespace' );
if ( is_null($namespace) ) { $namespace = 0; }
if( $par ) {
indexShowChunk( $par, $namespace );
2004-04-01 12:53:01 +00:00
} elseif( !is_null( $from ) ) {
indexShowChunk( $from, $namespace );
2003-04-14 23:10:40 +00:00
} else {
indexShowToplevel();
}
}
function indexShowToplevel()
{
global $wgOut, $indexMaxperpage, $wgLang;
2003-04-14 23:10:40 +00:00
$fname = "indexShowToplevel";
# Cache
$vsp = $wgLang->getValidSpecialPages();
$log = new LogPage( $vsp["Allpages"] );
$log->mUpdateRecentChanges = false;
global $wgMiserMode;
if ( $wgMiserMode ) {
$log->showAsDisabledPage();
return;
}
$dbr =& wfGetDB( DB_SLAVE );
$cur = $dbr->tableName( 'cur' );
$fromwhere = "FROM $cur WHERE cur_namespace=0";
$order = 'ORDER BY cur_title';
2003-04-14 23:10:40 +00:00
$out = "";
$where = array( 'cur_namespace' => 0 );
$count = $dbr->selectField( 'cur', 'COUNT(*)', $where, $fname );
2003-04-14 23:10:40 +00:00
$sections = ceil( $count / $indexMaxperpage );
$inpoint = $dbr->selectField( 'cur', 'cur_title', $where, $fname, $order );
2003-04-14 23:10:40 +00:00
$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 ".$dbr->limitResult(2,$from);
$res = $dbr->query( $sql, $fname );
$s = $dbr->fetchObject( $res );
2003-04-14 23:10:40 +00:00
$outpoint = $s->cur_title;
$out .= indexShowline( $inpoint, $outpoint );
$s = $dbr->fetchObject( $res );
2003-04-14 23:10:40 +00:00
$inpoint = $s->cur_title;
$dbr->freeResult( $res );
2003-04-14 23:10:40 +00:00
}
2003-04-14 23:10:40 +00:00
$from = $i * $indexMaxperpage;
2004-06-11 16:37:15 +00:00
$sql = "SELECT cur_title $fromwhere $order ".wfLimitResult(1,$count-1);
$res = $dbr->query( $sql, $fname );
$s = $dbr->fetchObject( $res );
2003-04-14 23:10:40 +00:00
$outpoint = $s->cur_title;
$out .= indexShowline( $inpoint, $outpoint );
$out .= "</table>\n";
# Saving cache
$log->replaceContent( $out );
2003-04-14 23:10:40 +00:00
$wgOut->addHtml( $out );
}
function indexShowline( $inpoint, $outpoint )
{
global $wgOut, $wgLang, $wgUser;
$sk = $wgUser->getSkin();
$dbr =& wfGetDB( DB_SLAVE );
2003-04-14 23:10:40 +00:00
# Fixme: this is ugly
$out = wfMsg(
"alphaindexline",
$sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
str_replace( "_", " ", $inpoint ),
"from=" . $dbr->strencode( $inpoint ) ) . "</td><td>",
2003-04-14 23:10:40 +00:00
"</td><td align=\"left\">" .
str_replace( "_", " ", $outpoint )
);
return "<tr><td align=\"right\">{$out}</td></tr>\n";
}
function indexShowChunk( $from, $namespace = 0 )
2003-04-14 23:10:40 +00:00
{
global $wgOut, $wgUser, $indexMaxperpage, $wgLang;
2003-04-14 23:10:40 +00:00
$sk = $wgUser->getSkin();
$maxPlusOne = $indexMaxperpage + 1;
$namespacee = intval($namespace);
2003-04-14 23:10:40 +00:00
$out = "";
$dbr =& wfGetDB( DB_SLAVE );
$cur = $dbr->tableName( 'cur' );
$sql = "SELECT cur_title FROM $cur WHERE cur_namespace=$namespacee AND cur_title >= '"
. $dbr->strencode( $from ) . "' ORDER BY cur_title LIMIT " . $maxPlusOne;
$res = $dbr->query( $sql, "indexShowChunk" );
2003-04-14 23:10:40 +00:00
### FIXME: side link to previous
2003-04-14 23:10:40 +00:00
$n = 0;
$out = "<table border=\"0\" width=\"100%\">\n";
while( ($n < $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
$t = Title::makeTitle( $namespacee, $s->cur_title );
if( $t ) {
$link = $sk->makeKnownLinkObj( $t );
} else {
$link = "[[" . htmlspecialchars( $s->cur_title ) . "]]";
}
if( $n % 3 == 0 ) {
$out .= "<tr>\n";
}
$out .= "<td>$link</td>";
$n++;
if( $n % 3 == 0 ) {
$out .= "</tr>\n";
2003-04-14 23:10:40 +00:00
}
}
if( ($n % 3) != 0 ) {
2003-04-14 23:10:40 +00:00
$out .= "</tr>\n";
}
$out .= "</table>";
$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 );
2003-04-14 23:10:40 +00:00
}
?>