Changing comments layout preparing for generated documentation with Phpdocumentor
[lhc/web/wiklou.git] / includes / SpecialAllpages.php
1 <?php
2 /**
3 *
4 */
5
6 /**
7 *
8 */
9 function wfSpecialAllpages( $par=NULL ) {
10 global $indexMaxperpage, $toplevelMaxperpage, $wgRequest, $wgOut, $wgLang;
11 $indexMaxperpage = 480;
12 $toplevelMaxperpage = 50;
13 $from = $wgRequest->getVal( 'from' );
14 $namespace = $wgRequest->getInt( 'namespace' );
15 $names = $wgLang->getNamespaces();
16 if( !isset( $names[$namespace] ) ) {
17 $namespace = 0;
18 }
19 $wgOut->setPagetitle ( $namespace > 0 ? wfMsg ( 'allpagesnamespace', $names[$namespace] )
20 : wfMsg ( 'allarticles' ) );
21
22 if ( $par ) {
23 indexShowChunk( $par, $namespace );
24 } elseif ( $from ) {
25 indexShowChunk( $from, $namespace );
26 } else {
27 indexShowToplevel ( $namespace );
28 }
29 }
30
31 function namespaceForm ( $namespace = 0, $from = '' ) {
32 global $wgLang, $wgScript;
33
34 $t = Title::makeTitle( NS_SPECIAL, "Allpages" );
35
36 $namespaceselect = '<select name="namespace">';
37 $arr = $wgLang->getNamespaces();
38 for ( $i = 0; $i < 14; $i++ ) {
39 $namespacename = str_replace ( "_", " ", $arr[$i] );
40 $n = ($i == 0) ? wfMsg ( 'articlenamespace' ) : $namespacename;
41 $sel = ($i == $namespace) ? ' selected="selected"' : '';
42 $namespaceselect .= "<option value='{$i}'{$sel}>{$n}</option>";
43 }
44 $namespaceselect .= '</select>';
45
46 $frombox = '<input type="text" size="20" name="from" value="'
47 . htmlspecialchars ( $from ) . '"/>';
48 $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
49
50 $out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>";
51 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
52 $out .= wfMsg ( 'allpagesformtext', $frombox, $namespaceselect, $submitbutton );
53 $out .= '</form></div>';
54 return $out;
55 }
56
57 function indexShowToplevel ( $namespace = 0 ) {
58 global $wgOut, $indexMaxperpage, $toplevelMaxperpage, $wgLang, $wgRequest, $wgUser;
59 $sk = $wgUser->getSkin();
60 $fname = "indexShowToplevel";
61 $namespace = intval ($namespace);
62
63 # TODO: Either make this *much* faster or cache the title index points
64 # in the querycache table.
65
66 $dbr =& wfGetDB( DB_SLAVE );
67 $cur = $dbr->tableName( 'cur' );
68 $fromwhere = "FROM $cur WHERE cur_namespace=$namespace";
69 $order_arr = array ( 'ORDER BY' => 'cur_title' );
70 $order_str = 'ORDER BY cur_title';
71 $out = "";
72 $where = array( 'cur_namespace' => $namespace );
73
74 $count = $dbr->selectField( 'cur', 'COUNT(*)', $where, $fname );
75 $sections = ceil( $count / $indexMaxperpage );
76
77 if ( $sections < 3 ) {
78 # If there are only two or less sections, don't even display them.
79 # Instead, display the first section directly.
80 indexShowChunk( '', $namespace );
81 return;
82 }
83
84 # We want to display $toplevelMaxperpage lines starting at $offset.
85 # NOTICE: $offset starts at 0
86 $offset = intval ( $wgRequest->getVal( 'offset' ) );
87 if ( $offset < 0 ) { $offset = 0; }
88 if ( $offset >= $sections ) { $offset = $sections - 1; }
89
90 # Where to stop? Notice that this can take the value of $sections, but $offset can't, because if
91 # we're displaying only the very last section, we still need two DB queries to find the titles
92 $stopat = ( $offset + $toplevelMaxperpage < $sections )
93 ? $offset + $toplevelMaxperpage : $sections ;
94
95 # This array is going to hold the cur_titles in order.
96 $lines = array();
97
98 # If we are going to show n rows, we need n+1 queries to find the relevant titles.
99 for ( $i = $offset; $i <= $stopat; $i++ ) {
100 if ( $i == $sections ) # if we're displaying the last section, we need to
101 $from = $count-1; # find the last cur_title in the DB
102 else if ( $i > $offset )
103 $from = $i * $indexMaxperpage - 1;
104 else
105 $from = $i * $indexMaxperpage;
106 $limit = ( $i == $offset || $i == $stopat ) ? 1 : 2;
107 $sql = "SELECT cur_title $fromwhere $order_str " . $dbr->limitResult ( $limit, $from );
108 $res = $dbr->query( $sql, $fname );
109 $s = $dbr->fetchObject( $res );
110 array_push ( $lines, $s->cur_title );
111 if ( $s = $dbr->fetchObject( $res ) ) {
112 array_push ( $lines, $s->cur_title );
113 }
114 $dbr->freeResult( $res );
115 }
116
117 # At this point, $lines should contain an even number of elements.
118 $out .= "<table style='background: inherit;'>";
119 while ( count ( $lines ) > 0 ) {
120 $inpoint = array_shift ( $lines );
121 $outpoint = array_shift ( $lines );
122 $out .= indexShowline ( $inpoint, $outpoint, $namespace );
123 }
124 $out .= "</table>";
125
126 $nsForm = namespaceForm ( $namespace );
127
128 # Is there more?
129 $morelinks = "";
130 if ( $offset > 0 ) {
131 $morelinks = $sk->makeKnownLink (
132 $wgLang->specialPage ( "Allpages" ),
133 wfMsg ( 'allpagesprev' ),
134 ( $offset > $toplevelMaxperpage ) ? 'offset='.($offset-$toplevelMaxperpage) : ''
135 );
136 }
137 if ( $stopat < $sections-1 ) {
138 if ( $morelinks != "" ) { $morelinks .= " | "; }
139 $morelinks .= $sk->makeKnownLink (
140 $wgLang->specialPage ( "Allpages" ),
141 wfMsg ( 'allpagesnext' ),
142 'offset=' . ($offset + $toplevelMaxperpage)
143 );
144 }
145
146 if ( $morelinks != "" ) {
147 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
148 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
149 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">';
150 $out2 .= $morelinks . '</td></tr></table><hr />';
151 } else {
152 $out2 = $nsForm . '<hr />';
153 }
154
155 $wgOut->addHtml( $out2 . $out );
156 }
157
158 function indexShowline( $inpoint, $outpoint, $namespace = 0 ) {
159 global $wgOut, $wgLang, $wgUser;
160 $sk = $wgUser->getSkin();
161 $dbr =& wfGetDB( DB_SLAVE );
162
163 $inpointf = htmlspecialchars( str_replace( "_", " ", $inpoint ) );
164 $outpointf = htmlspecialchars( str_replace( "_", " ", $outpoint ) );
165 $queryparams = $namespace ? ('namespace='.intval($namespace)) : '';
166 $special = Title::makeTitle( NS_SPECIAL, 'Allpages/' . $inpoint );
167 $link = $special->escapeLocalUrl( $queryparams );
168
169 $out = wfMsg(
170 'alphaindexline',
171 "<a href=\"$link\">$inpointf</a></td><td><a href=\"$link\">",
172 "</a></td><td align=\"left\"><a href=\"$link\">$outpointf</a>"
173 );
174 return '<tr><td align="right">'.$out.'</td></tr>';
175 }
176
177 function indexShowChunk( $from, $namespace = 0 ) {
178 global $wgOut, $wgUser, $indexMaxperpage, $wgLang;
179 $sk = $wgUser->getSkin();
180 $maxPlusOne = $indexMaxperpage + 1;
181 $namespacee = intval($namespace);
182
183 $out = "";
184 $dbr =& wfGetDB( DB_SLAVE );
185 $cur = $dbr->tableName( 'cur' );
186
187 $fromTitle = Title::newFromURL( $from );
188 $fromKey = is_null( $fromTitle ) ? '' : $fromTitle->getDBkey();
189
190 $sql = "SELECT cur_title FROM $cur WHERE cur_namespace=$namespacee" .
191 " AND cur_title >= ". $dbr->addQuotes( $fromKey ) .
192 " ORDER BY cur_title LIMIT " . $maxPlusOne;
193 $res = $dbr->query( $sql, "indexShowChunk" );
194
195 ### FIXME: side link to previous
196
197 $n = 0;
198 $out = '<table style="background: inherit;" border="0" width="100%">';
199 while( ($n < $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
200 $t = Title::makeTitle( $namespacee, $s->cur_title );
201 if( $t ) {
202 $link = $sk->makeKnownLinkObj( $t, $t->getText() );
203 } else {
204 $link = '[[' . htmlspecialchars( $s->cur_title ) . ']]';
205 }
206 if( $n % 3 == 0 ) {
207 $out .= '<tr>';
208 }
209 $out .= "<td>$link</td>";
210 $n++;
211 if( $n % 3 == 0 ) {
212 $out .= '</tr>';
213 }
214 }
215 if( ($n % 3) != 0 ) {
216 $out .= '</tr>';
217 }
218 $out .= '</table>';
219
220 $nsForm = namespaceForm ( $namespace, $from );
221 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
222 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
223 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
224 $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
225 wfMsg ( 'allpages' ) );
226 if ( ($n == $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
227 $out2 .= " | " . $sk->makeKnownLink(
228 $wgLang->specialPage( "Allpages" ),
229 wfMsg ( 'nextpage', $s->cur_title ),
230 "from=" . wfUrlEncode ( $s->cur_title ) );
231 }
232 $out2 .= "</td></tr></table><hr />";
233
234 $wgOut->addHtml( $out2 . $out );
235 }
236
237 ?>