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