a3b7aafb5d71faf1f8a2cfcc2cb9d5b0ac235a9f
[lhc/web/wiklou.git] / includes / SpecialAllpages.php
1 <?
2
3 function wfSpecialAllpages()
4 {
5 global $from, $indexMaxperpage;
6 $indexMaxperpage = 480;
7
8 if( isset( $from ) ) {
9 indexShowChunk( $from );
10 } else {
11 indexShowToplevel();
12 }
13 }
14
15 function indexShowToplevel()
16 {
17 global $wgOut, $indexMaxperpage;
18 $fname = "indexShowToplevel";
19 # FIXME: This may be slow; we may need to cache it
20
21 # $fromwhere = "FROM cur WHERE cur_namespace=0 AND cur_is_redirect=0";
22 $fromwhere = "FROM cur WHERE cur_namespace=0";
23 $order = "ORDER BY cur_title";
24 $out = "";
25
26 $sql = "SELECT COUNT(*) AS count $fromwhere";
27 $res = wfQuery( $sql, $fname );
28 $s = wfFetchObject( $res );
29 $count = $s->count;
30 $sections = ceil( $count / $indexMaxperpage );
31
32 $sql = "SELECT cur_title $fromwhere $order LIMIT 1";
33 $res = wfQuery( $sql, $fname );
34 $s = wfFetchObject( $res );
35 $inpoint = $s->cur_title;
36
37 $out .= "<table>\n";
38 # There's got to be a cleaner way to do this!
39 for( $i = 1; $i < $sections; $i++ ) {
40 $from = $i * $indexMaxperpage;
41 $sql = "SELECT cur_title $fromwhere $order LIMIT $from,2";
42 $res = wfQuery( $sql, $fname );
43
44 $s = wfFetchObject( $res );
45 $outpoint = $s->cur_title;
46 $out .= indexShowline( $inpoint, $outpoint );
47
48 $s = wfFetchObject( $res );
49 $inpoint = $s->cur_title;
50
51 wfFreeResult( $res );
52 }
53
54 $from = $i * $indexMaxperpage;
55 $sql = "SELECT cur_title $fromwhere $order LIMIT " . ($count-1) . ",1";
56 $res = wfQuery( $sql, $fname );
57 $s = wfFetchObject( $res );
58 $outpoint = $s->cur_title;
59 $out .= indexShowline( $inpoint, $outpoint );
60 $out .= "</table>\n";
61
62 $wgOut->addHtml( $out );
63 }
64
65 function indexShowline( $inpoint, $outpoint )
66 {
67 global $wgOut, $wgLang, $wgUser;
68 $sk = $wgUser->getSkin();
69
70 # Fixme: this is ugly
71 $out = wfMsg(
72 "alphaindexline",
73 $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
74 str_replace( "_", " ", $inpoint ),
75 "from=" . wfStrencode( $inpoint ) ) . "</td><td>",
76 "</td><td align=\"left\">" .
77 str_replace( "_", " ", $outpoint )
78 );
79 return "<tr><td align=\"right\">{$out}</td></tr>\n";
80 }
81
82 function indexShowChunk( $from )
83 {
84 global $wgOut, $wgUser, $indexMaxperpage;
85 $sk = $wgUser->getSkin();
86
87 $out = "";
88 $sql = "SELECT cur_title
89 FROM cur
90 WHERE cur_namespace=0 AND cur_title >= '" . wfStrencode( $from ) . "'
91 ORDER BY cur_title
92 LIMIT {$indexMaxperpage}";
93 $res = wfQuery( $sql, "indexShowChunk" );
94
95 # FIXME: Dynamic column widths, backlink to main list,
96 # side links to next and previous
97 $n = 0;
98 $out = "<table border=\"0\">\n";
99 while( $s = wfFetchObject( $res ) ) {
100 $out .= "<td width=\"33%\">" .
101 $sk->makeKnownLink( $s->cur_title ) .
102 "</td>";
103 $n = ++$n % 3;
104 if( $n == 0 ) {
105 $out .= "</tr>\n<tr>";
106 }
107 }
108 if( $n != 0 ) {
109 $out .= "</tr>\n";
110 }
111 $out .= "</table>";
112 #return $out;
113 $wgOut->addHtml( $out );
114 }
115
116 ?>