Fix for compatibility with short_open_tag = Off
[lhc/web/wiklou.git] / includes / SpecialAllpages.php
1 <?php
2
3 function wfSpecialAllpages( $par=NULL )
4 {
5 global $from, $indexMaxperpage;
6 $indexMaxperpage = 480;
7
8 if( $par ) {
9 indexShowChunk( $par );
10 } elseif( isset( $from ) ) {
11 indexShowChunk( $from );
12 } else {
13 indexShowToplevel();
14 }
15 }
16
17 function indexShowToplevel()
18 {
19 global $wgOut, $indexMaxperpage, $wgLang;
20 $fname = "indexShowToplevel";
21
22 # Cache
23 $vsp = $wgLang->getValidSpecialPages();
24 $log = new LogPage( $vsp["Allpages"] );
25 $log->mUpdateRecentChanges = false;
26
27 global $wgMiserMode;
28 if ( $wgMiserMode ) {
29 $log->showAsDisabledPage();
30 return;
31 }
32
33
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 = "";
38
39 $sql = "SELECT COUNT(*) AS count $fromwhere";
40 $res = wfQuery( $sql, DB_READ, $fname );
41 $s = wfFetchObject( $res );
42 $count = $s->count;
43 $sections = ceil( $count / $indexMaxperpage );
44
45 $sql = "SELECT cur_title $fromwhere $order LIMIT 1";
46 $res = wfQuery( $sql, DB_READ, $fname );
47 $s = wfFetchObject( $res );
48 $inpoint = $s->cur_title;
49
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, DB_READ, $fname );
56
57 $s = wfFetchObject( $res );
58 $outpoint = $s->cur_title;
59 $out .= indexShowline( $inpoint, $outpoint );
60
61 $s = wfFetchObject( $res );
62 $inpoint = $s->cur_title;
63
64 wfFreeResult( $res );
65 }
66
67 $from = $i * $indexMaxperpage;
68 $sql = "SELECT cur_title $fromwhere $order LIMIT " . ($count-1) . ",1";
69 $res = wfQuery( $sql, DB_READ, $fname );
70 $s = wfFetchObject( $res );
71 $outpoint = $s->cur_title;
72 $out .= indexShowline( $inpoint, $outpoint );
73 $out .= "</table>\n";
74
75 # Saving cache
76 $log->replaceContent( $out );
77
78 $wgOut->addHtml( $out );
79 }
80
81 function indexShowline( $inpoint, $outpoint )
82 {
83 global $wgOut, $wgLang, $wgUser;
84 $sk = $wgUser->getSkin();
85
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 )
94 );
95 return "<tr><td align=\"right\">{$out}</td></tr>\n";
96 }
97
98 function indexShowChunk( $from )
99 {
100 global $wgOut, $wgUser, $indexMaxperpage;
101 $sk = $wgUser->getSkin();
102
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, DB_READ, "indexShowChunk" );
110
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<tr>";
115 while( $s = wfFetchObject( $res ) ) {
116 $t = Title::makeTitle( 0, $s->cur_title );
117 if( $t ) {
118 $link = $sk->makeKnownLinkObj( $t );
119 } else {
120 $link = "[[" . htmlspecialchars( $s->cur_title ) . "]]";
121 }
122 $out .= "<td width=\"33%\">$link</td>";
123 $n = ++$n % 3;
124 if( $n == 0 ) {
125 $out .= "</tr>\n<tr>";
126 }
127 }
128 if( $n != 0 ) {
129 $out .= "</tr>\n";
130 }
131 $out .= "</table>";
132 #return $out;
133 $wgOut->addHtml( $out );
134 }
135
136 ?>