Various additions and fixes
[mediawiki.git] / includes / SpecialAllpages.php
blob8ba82258f41a7e027a569bb388ede7b89a144284
1 <?
3 function wfSpecialAllpages( $par=NULL )
5 global $from, $indexMaxperpage;
6 $indexMaxperpage = 480;
8 if( $par ) {
9 indexShowChunk( $par );
10 } elseif( isset( $from ) ) {
11 indexShowChunk( $from );
12 } else {
13 indexShowToplevel();
17 function indexShowToplevel()
19 global $wgOut, $indexMaxperpage, $wgLang;
20 $fname = "indexShowToplevel";
22 # Cache
23 $vsp = $wgLang->getValidSpecialPages();
24 $log = new LogPage( $vsp["Allpages"] );
25 $log->mUpdateRecentChanges = false;
27 global $wgMiserMode;
28 if ( $wgMiserMode ) {
29 $log->showAsDisabledPage();
30 return;
34 # $fromwhere = "FROM cur WHERE cur_namespace=0 AND cur_is_redirect=0";
35 $fromwhere = "FROM cur WHERE cur_namespace=0";
36 $order = "ORDER BY cur_title";
37 $out = "";
39 $sql = "SELECT COUNT(*) AS count $fromwhere";
40 $res = wfQuery( $sql, $fname );
41 $s = wfFetchObject( $res );
42 $count = $s->count;
43 $sections = ceil( $count / $indexMaxperpage );
45 $sql = "SELECT cur_title $fromwhere $order LIMIT 1";
46 $res = wfQuery( $sql, $fname );
47 $s = wfFetchObject( $res );
48 $inpoint = $s->cur_title;
50 $out .= "<table>\n";
51 # There's got to be a cleaner way to do this!
52 for( $i = 1; $i < $sections; $i++ ) {
53 $from = $i * $indexMaxperpage;
54 $sql = "SELECT cur_title $fromwhere $order LIMIT $from,2";
55 $res = wfQuery( $sql, $fname );
57 $s = wfFetchObject( $res );
58 $outpoint = $s->cur_title;
59 $out .= indexShowline( $inpoint, $outpoint );
61 $s = wfFetchObject( $res );
62 $inpoint = $s->cur_title;
64 wfFreeResult( $res );
67 $from = $i * $indexMaxperpage;
68 $sql = "SELECT cur_title $fromwhere $order LIMIT " . ($count-1) . ",1";
69 $res = wfQuery( $sql, $fname );
70 $s = wfFetchObject( $res );
71 $outpoint = $s->cur_title;
72 $out .= indexShowline( $inpoint, $outpoint );
73 $out .= "</table>\n";
75 # Saving cache
76 $log->replaceContent( $out );
78 $wgOut->addHtml( $out );
81 function indexShowline( $inpoint, $outpoint )
83 global $wgOut, $wgLang, $wgUser;
84 $sk = $wgUser->getSkin();
86 # Fixme: this is ugly
87 $out = wfMsg(
88 "alphaindexline",
89 $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
90 str_replace( "_", " ", $inpoint ),
91 "from=" . wfStrencode( $inpoint ) ) . "</td><td>",
92 "</td><td align=\"left\">" .
93 str_replace( "_", " ", $outpoint )
95 return "<tr><td align=\"right\">{$out}</td></tr>\n";
98 function indexShowChunk( $from )
100 global $wgOut, $wgUser, $indexMaxperpage;
101 $sk = $wgUser->getSkin();
103 $out = "";
104 $sql = "SELECT cur_title
105 FROM cur
106 WHERE cur_namespace=0 AND cur_title >= '" . wfStrencode( $from ) . "'
107 ORDER BY cur_title
108 LIMIT {$indexMaxperpage}";
109 $res = wfQuery( $sql, "indexShowChunk" );
111 # FIXME: Dynamic column widths, backlink to main list,
112 # side links to next and previous
113 $n = 0;
114 $out = "<table border=\"0\">\n";
115 while( $s = wfFetchObject( $res ) ) {
116 $out .= "<td width=\"33%\">" .
117 $sk->makeKnownLink( $s->cur_title ) .
118 "</td>";
119 $n = ++$n % 3;
120 if( $n == 0 ) {
121 $out .= "</tr>\n<tr>";
124 if( $n != 0 ) {
125 $out .= "</tr>\n";
127 $out .= "</table>";
128 #return $out;
129 $wgOut->addHtml( $out );