bbd5fdc1ff280409da38391c675426dec70d03d8
[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, $wgLang;
18 $fname = "indexShowToplevel";
19
20 # Cache
21 $vsp = $wgLang->getValidSpecialPages();
22 $log = new LogPage( $vsp["Allpages"] );
23 $log->mUpdateRecentChanges = false;
24
25 global $wgMiserMode;
26 if ( $wgMiserMode ) {
27 $log->showAsDisabledPage();
28 return;
29 }
30
31
32 # $fromwhere = "FROM cur WHERE cur_namespace=0 AND cur_is_redirect=0";
33 $fromwhere = "FROM cur WHERE cur_namespace=0";
34 $order = "ORDER BY cur_title";
35 $out = "";
36
37 $sql = "SELECT COUNT(*) AS count $fromwhere";
38 $res = wfQuery( $sql, $fname );
39 $s = wfFetchObject( $res );
40 $count = $s->count;
41 $sections = ceil( $count / $indexMaxperpage );
42
43 $sql = "SELECT cur_title $fromwhere $order LIMIT 1";
44 $res = wfQuery( $sql, $fname );
45 $s = wfFetchObject( $res );
46 $inpoint = $s->cur_title;
47
48 $out .= "<table>\n";
49 # There's got to be a cleaner way to do this!
50 for( $i = 1; $i < $sections; $i++ ) {
51 $from = $i * $indexMaxperpage;
52 $sql = "SELECT cur_title $fromwhere $order LIMIT $from,2";
53 $res = wfQuery( $sql, $fname );
54
55 $s = wfFetchObject( $res );
56 $outpoint = $s->cur_title;
57 $out .= indexShowline( $inpoint, $outpoint );
58
59 $s = wfFetchObject( $res );
60 $inpoint = $s->cur_title;
61
62 wfFreeResult( $res );
63 }
64
65 $from = $i * $indexMaxperpage;
66 $sql = "SELECT cur_title $fromwhere $order LIMIT " . ($count-1) . ",1";
67 $res = wfQuery( $sql, $fname );
68 $s = wfFetchObject( $res );
69 $outpoint = $s->cur_title;
70 $out .= indexShowline( $inpoint, $outpoint );
71 $out .= "</table>\n";
72
73 # Saving cache
74 $log->replaceContent( $out );
75
76 $wgOut->addHtml( $out );
77 }
78
79 function indexShowline( $inpoint, $outpoint )
80 {
81 global $wgOut, $wgLang, $wgUser;
82 $sk = $wgUser->getSkin();
83
84 # Fixme: this is ugly
85 $out = wfMsg(
86 "alphaindexline",
87 $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
88 str_replace( "_", " ", $inpoint ),
89 "from=" . wfStrencode( $inpoint ) ) . "</td><td>",
90 "</td><td align=\"left\">" .
91 str_replace( "_", " ", $outpoint )
92 );
93 return "<tr><td align=\"right\">{$out}</td></tr>\n";
94 }
95
96 function indexShowChunk( $from )
97 {
98 global $wgOut, $wgUser, $indexMaxperpage;
99 $sk = $wgUser->getSkin();
100
101 $out = "";
102 $sql = "SELECT cur_title
103 FROM cur
104 WHERE cur_namespace=0 AND cur_title >= '" . wfStrencode( $from ) . "'
105 ORDER BY cur_title
106 LIMIT {$indexMaxperpage}";
107 $res = wfQuery( $sql, "indexShowChunk" );
108
109 # FIXME: Dynamic column widths, backlink to main list,
110 # side links to next and previous
111 $n = 0;
112 $out = "<table border=\"0\">\n";
113 while( $s = wfFetchObject( $res ) ) {
114 $out .= "<td width=\"33%\">" .
115 $sk->makeKnownLink( $s->cur_title ) .
116 "</td>";
117 $n = ++$n % 3;
118 if( $n == 0 ) {
119 $out .= "</tr>\n<tr>";
120 }
121 }
122 if( $n != 0 ) {
123 $out .= "</tr>\n";
124 }
125 $out .= "</table>";
126 #return $out;
127 $wgOut->addHtml( $out );
128 }
129
130 ?>