4 * @subpackage SpecialPage
8 * Entry point : initialise variables and call subfunctions.
9 * @param string $par Becomes "FOO" when called like Special:Allpages/FOO (default NULL)
11 function wfSpecialAllpages( $par=NULL ) {
12 global $indexMaxperpage, $toplevelMaxperpage, $wgRequest, $wgOut, $wgContLang;
14 $indexMaxperpage = 480;
15 $toplevelMaxperpage = 50;
17 $from = $wgRequest->getVal( 'from' );
18 $namespace = $wgRequest->getInt( 'namespace' );
19 $invert = $wgRequest->getBool( 'invert' );
21 $namespaces = $wgContLang->getNamespaces();
23 if( !in_array($namespace, array_keys($namespaces)) )
27 $wgOut->setPagetitle( $namespace > 0 ?
28 wfMsg( 'allnotinnamespace', $namespaces[$namespace] ) :
29 wfMsg( 'allnonarticles' )
32 $wgOut->setPagetitle( $namespace > 0 ?
33 wfMsg( 'allinnamespace', $namespaces[$namespace] ) :
34 wfMsg( 'allarticles' )
39 indexShowChunk( $namespace, $par, $invert );
40 } elseif ( isset($from) ) {
41 indexShowChunk( $namespace, $from, $invert );
43 indexShowToplevel ( $namespace, $invert );
48 * HTML for the top form
49 * @param integer $namespace A namespace constant (default NS_MAIN).
50 * @param string $from Article name we are starting listing at.
51 * @param bool $invert true if we want the namespaces inverted (default false)
53 function namespaceForm ( $namespace = NS_MAIN
, $from = '', $invert ) {
54 global $wgContLang, $wgScript;
55 $t = Title
::makeTitle( NS_SPECIAL
, "Allpages" );
57 $namespaceselect = "<select name='namespace' id='nsselectbox'>";
58 $arr = $wgContLang->getFormattedNamespaces();
59 foreach ( $arr as $ns => $name ) {
62 $n = $ns == 0 ?
wfMsg ( 'blanknamespace' ) : $name;
63 $sel = $ns == $namespace ?
' selected="selected"' : '';
64 $namespaceselect .= "<option value='$ns'$sel>$n</option>";
66 $namespaceselect .= '</select>';
68 $frombox = "<input type='text' size='20' name='from' id='nsfrom' value=\""
69 . htmlspecialchars ( $from ) . '"/>';
70 $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
72 $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ?
' checked="checked"' : '' ) . ' />';
74 $out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>";
75 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
77 <table id='nsselect' class='allpages'>
79 <td align='right'>" . wfMsg('allpagesfrom') . "</td>
80 <td align='left'><label for='nsfrom'>$frombox</label></td>
83 <td align='right'><label for='nsselectbox'>" . wfMsg('namespace') . "</label></td>
84 <td align='left'>$namespaceselect $submitbutton</td>
87 <td align='right'>$invertbox</td>
88 <td align='left'><label for='nsinvert'>" . wfMsg('invert') . "</label></td>
92 $out .= '</form></div>';
97 * @param integer $namespace (default NS_MAIN)
98 * @param bool $invert true if we want the namespaces inverted (default false)
100 function indexShowToplevel ( $namespace = NS_MAIN
, $invert ) {
101 global $wgOut, $indexMaxperpage, $toplevelMaxperpage, $wgContLang, $wgRequest, $wgUser;
102 $sk = $wgUser->getSkin();
103 $fname = "indexShowToplevel";
105 # TODO: Either make this *much* faster or cache the title index points
106 # in the querycache table.
108 $dbr =& wfGetDB( DB_SLAVE
);
109 $page = $dbr->tableName( 'page' );
110 $fromwhere = "FROM $page WHERE page_namespace" .
111 ($invert ?
'!' : '') . "=$namespace";
112 $order_arr = array ( 'ORDER BY' => 'page_title' );
113 $order_str = 'ORDER BY page_title';
115 $where = array( 'page_namespace' => $namespace );
117 $count = $dbr->selectField( 'page', 'COUNT(*)', $where, $fname );
118 $sections = ceil( $count / $indexMaxperpage );
120 if ( $sections < 3 ) {
121 # If there are only two or less sections, don't even display them.
122 # Instead, display the first section directly.
123 indexShowChunk( $namespace, '', $invert );
127 # We want to display $toplevelMaxperpage lines starting at $offset.
128 # NOTICE: $offset starts at 0
129 $offset = intval ( $wgRequest->getVal( 'offset' ) );
130 if ( $offset < 0 ) { $offset = 0; }
131 if ( $offset >= $sections ) { $offset = $sections - 1; }
133 # Where to stop? Notice that this can take the value of $sections, but $offset can't, because if
134 # we're displaying only the very last section, we still need two DB queries to find the titles
135 $stopat = ( $offset +
$toplevelMaxperpage < $sections )
136 ?
$offset +
$toplevelMaxperpage : $sections ;
138 # This array is going to hold the page_titles in order.
141 # If we are going to show n rows, we need n+1 queries to find the relevant titles.
142 for ( $i = $offset; $i <= $stopat; ++
$i ) {
143 if ( $i == $sections ) # if we're displaying the last section, we need to
144 $from = $count-1; # find the last page_title in the DB
145 else if ( $i > $offset )
146 $from = $i * $indexMaxperpage - 1;
148 $from = $i * $indexMaxperpage;
149 $limit = ( $i == $offset ||
$i == $stopat ) ?
1 : 2;
150 $sql = "SELECT page_title $fromwhere $order_str " . $dbr->limitResult ( $limit, $from );
151 $res = $dbr->query( $sql, $fname );
152 if ( $s = $dbr->fetchObject( $res ) ) {
153 array_push ( $lines, $s->page_title
);
154 if ( $s = $dbr->fetchObject( $res ) ) {
155 array_push ( $lines, $s->page_title
);
158 $dbr->freeResult( $res );
161 # At this point, $lines should contain an even number of elements.
162 $out .= "<table style='background: inherit;'>";
163 while ( count ( $lines ) > 0 ) {
164 $inpoint = array_shift ( $lines );
165 $outpoint = array_shift ( $lines );
166 $out .= indexShowline ( $inpoint, $outpoint, $namespace, $invert );
170 $nsForm = namespaceForm ( $namespace, '', $invert );
175 $morelinks = $sk->makeKnownLink (
176 $wgContLang->specialPage ( 'Allpages' ),
177 wfMsg ( 'allpagesprev' ),
178 ( $offset > $toplevelMaxperpage ) ?
'offset='.($offset-$toplevelMaxperpage) : ''
181 if ( $stopat < $sections-1 ) {
182 if ( $morelinks != '' ) { $morelinks .= " | "; }
183 $morelinks .= $sk->makeKnownLink (
184 $wgContLang->specialPage ( 'Allpages' ),
185 wfMsg ( 'allpagesnext' ),
186 'offset=' . ($offset +
$toplevelMaxperpage)
190 if ( $morelinks != '' ) {
191 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
192 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
193 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">';
194 $out2 .= $morelinks . '</td></tr></table><hr />';
196 $out2 = $nsForm . '<hr />';
199 $wgOut->addHtml( $out2 . $out );
204 * @param string $from
205 * @param integer $namespace (Default NS_MAIN)
206 * @param bool $invert true if we want the namespaces inverted (default false)
208 function indexShowline( $inpoint, $outpoint, $namespace = NS_MAIN
, $invert ) {
209 global $wgOut, $wgLang, $wgUser;
210 $sk = $wgUser->getSkin();
211 $dbr =& wfGetDB( DB_SLAVE
);
213 $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
214 $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
215 $queryparams = ($namespace ?
"namespace=$namespace" : '') . ($invert ?
"&invert=$invert" : '');
216 $special = Title
::makeTitle( NS_SPECIAL
, 'Allpages/' . $inpoint );
217 $link = $special->escapeLocalUrl( $queryparams );
221 "<a href=\"$link\">$inpointf</a></td><td><a href=\"$link\">",
222 "</a></td><td align=\"left\"><a href=\"$link\">$outpointf</a>"
224 return '<tr><td align="right">'.$out.'</td></tr>';
228 * @param integer $namespace (Default NS_MAIN)
229 * @param string $from list all pages from this name (default FALSE)
230 * @param bool $invert true if we want the namespaces inverted (default false)
232 function indexShowChunk( $namespace = NS_MAIN
, $from, $invert ) {
233 global $wgOut, $wgUser, $indexMaxperpage, $wgContLang;
234 $sk = $wgUser->getSkin();
235 $maxPlusOne = $indexMaxperpage +
1;
238 $dbr =& wfGetDB( DB_SLAVE
);
239 $page = $dbr->tableName( 'page' );
241 $fromTitle = Title
::newFromURL( $from );
242 $fromKey = is_null( $fromTitle ) ?
'' : $fromTitle->getDBkey();
244 $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace" .
245 ($invert ?
'!' : '') . "=$namespace" .
246 " AND page_title >= ". $dbr->addQuotes( $fromKey ) .
247 " ORDER BY page_title LIMIT " . $maxPlusOne;
248 $res = $dbr->query( $sql, 'indexShowChunk' );
250 ### FIXME: side link to previous
253 $out = '<table style="background: inherit;" border="0" width="100%">';
255 $namespaces = $wgContLang->getFormattedNamespaces();
256 while( ($n < $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
257 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
259 $ns = $s->page_namespace
;
260 $prefix = $invert ?
$namespaces[$ns] : '';
261 $prefix .= $invert && $namespaces[$ns] != $wgContLang->getNsText(NS_MAIN
) ?
':' : '';
262 $link = $sk->makeKnownLinkObj( $t, $t->getText(), false, false, $prefix );
264 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
269 $out .= "<td>$link</td>";
275 if( ($n %
3) != 0 ) {
280 $nsForm = namespaceForm ( $namespace, $from, $invert );
281 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
282 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
283 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
284 $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
285 wfMsg ( 'allpages' ) );
286 if ( ($n == $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
287 $namespaceparam = $namespace ?
"&namespace=$namespace" : "";
288 $invertparam = $invert ?
"&invert=$invert" : '';
289 $out2 .= " | " . $sk->makeKnownLink(
290 $wgContLang->specialPage( "Allpages" ),
291 wfMsg ( 'nextpage', $s->page_title
),
292 "from=" . wfUrlEncode ( $s->page_title
) . $namespaceparam . $invertparam );
294 $out2 .= "</td></tr></table><hr />";
296 $wgOut->addHtml( $out2 . $out );