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