Special:Allpages now has a "next page" and a "back to index" link
[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 $fromwhere = "FROM cur WHERE cur_namespace=0";
35 $order = "ORDER BY cur_title";
36 $out = "";
37
38 $sql = "SELECT COUNT(*) AS count $fromwhere";
39 $res = wfQuery( $sql, DB_READ, $fname );
40 $s = wfFetchObject( $res );
41 $count = $s->count;
42 $sections = ceil( $count / $indexMaxperpage );
43
44 $sql = "SELECT cur_title $fromwhere $order LIMIT 1";
45 $res = wfQuery( $sql, DB_READ, $fname );
46 $s = wfFetchObject( $res );
47 $inpoint = $s->cur_title;
48
49 $out .= "<table>\n";
50 # There's got to be a cleaner way to do this!
51 for( $i = 1; $i < $sections; $i++ ) {
52 $from = $i * $indexMaxperpage;
53 $sql = "SELECT cur_title $fromwhere $order ".wfLimitResult(2,$from);
54 $res = wfQuery( $sql, DB_READ, $fname );
55
56 $s = wfFetchObject( $res );
57 $outpoint = $s->cur_title;
58 $out .= indexShowline( $inpoint, $outpoint );
59
60 $s = wfFetchObject( $res );
61 $inpoint = $s->cur_title;
62
63 wfFreeResult( $res );
64 }
65
66 $from = $i * $indexMaxperpage;
67 $sql = "SELECT cur_title $fromwhere $order ".wfLimitResult(1,$count-1);
68 $res = wfQuery( $sql, DB_READ, $fname );
69 $s = wfFetchObject( $res );
70 $outpoint = $s->cur_title;
71 $out .= indexShowline( $inpoint, $outpoint );
72 $out .= "</table>\n";
73
74 # Saving cache
75 $log->replaceContent( $out );
76
77 $wgOut->addHtml( $out );
78 }
79
80 function indexShowline( $inpoint, $outpoint )
81 {
82 global $wgOut, $wgLang, $wgUser;
83 $sk = $wgUser->getSkin();
84
85 # Fixme: this is ugly
86 $out = wfMsg(
87 "alphaindexline",
88 $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
89 str_replace( "_", " ", $inpoint ),
90 "from=" . wfStrencode( $inpoint ) ) . "</td><td>",
91 "</td><td align=\"left\">" .
92 str_replace( "_", " ", $outpoint )
93 );
94 return "<tr><td align=\"right\">{$out}</td></tr>\n";
95 }
96
97 function indexShowChunk( $from )
98 {
99 global $wgOut, $wgUser, $indexMaxperpage, $wgLang;
100 $sk = $wgUser->getSkin();
101 $maxPlusOne = $indexMaxperpage + 1;
102
103 $out = "";
104 $sql = "SELECT cur_title FROM cur WHERE cur_namespace=0 AND cur_title >= '"
105 . wfStrencode( $from ) . "' ORDER BY cur_title LIMIT " . $maxPlusOne;
106 $res = wfQuery( $sql, DB_READ, "indexShowChunk" );
107
108 ### FIXME: side link to previous
109
110 $n = 0;
111 $out = "<table border=\"0\" width=\"100%\">\n";
112 while( ($n < $indexMaxperpage) && ($s = wfFetchObject( $res )) ) {
113 $t = Title::makeTitle( 0, $s->cur_title );
114 if( $t ) {
115 $link = $sk->makeKnownLinkObj( $t );
116 } else {
117 $link = "[[" . htmlspecialchars( $s->cur_title ) . "]]";
118 }
119 if( $n % 3 == 0 ) {
120 $out .= "<tr>\n";
121 }
122 $out .= "<td>$link</td>";
123 $n++;
124 if( $n % 3 == 0 ) {
125 $out .= "</tr>\n";
126 }
127 }
128 if( ($n % 3) != 0 ) {
129 $out .= "</tr>\n";
130 }
131 $out .= "</table>";
132
133 $out2 = "<div style='text-align: right; font-size: smaller; margin-bottom: 1em;'>" .
134 $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
135 wfMsg ( 'allpages' ) );
136 if ( ($n == $indexMaxperpage) && ($s = wfFetchObject( $res )) ) {
137 $out2 .= " | " . $sk->makeKnownLink(
138 $wgLang->specialPage( "Allpages" ),
139 wfMsg ( 'nextpage', $s->cur_title ),
140 "from=" . wfStrencode( $s->cur_title ) );
141 }
142 $out2 .= "</div>";
143
144 $wgOut->addHtml( $out2 . $out );
145 }
146
147 ?>