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