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, $specialPage ) {
12 global $indexMaxperpage, $toplevelMaxperpage, $wgRequest, $wgOut, $wgContLang;
14 $indexMaxperpage = 960;
15 $toplevelMaxperpage = 50;
17 $from = $wgRequest->getVal( 'from' );
18 $namespace = $wgRequest->getInt( 'namespace' );
20 $namespaces = $wgContLang->getNamespaces();
22 if( !in_array($namespace, array_keys($namespaces)) )
25 $wgOut->setPagetitle( $namespace > 0 ?
26 wfMsg( 'allinnamespace', $namespaces[$namespace] ) :
27 wfMsg( 'allarticles' )
31 indexShowChunk( $namespace, $par, $specialPage->including() );
32 } elseif ( isset($from) ) {
33 indexShowChunk( $namespace, $from, $specialPage->including() );
35 indexShowToplevel ( $namespace, $specialPage->including() );
40 * HTML for the top form
41 * @param integer $namespace A namespace constant (default NS_MAIN).
42 * @param string $from Article name we are starting listing at.
44 function indexNamespaceForm ( $namespace = NS_MAIN, $from = '' ) {
45 global $wgContLang, $wgScript;
46 $t = Title::makeTitle( NS_SPECIAL, "Allpages" );
48 $namespaceselect = HTMLnamespaceselector($namespace, null);
50 $frombox = "<input type='text' size='20' name='from' id='nsfrom' value=\""
51 . htmlspecialchars ( $from ) . '"/>';
52 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . '" />';
54 $out = "<div class='namespaceoptions'><form method='get' action='{$wgScript}'>";
55 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
57 <table id='nsselect' class='allpages'>
59 <td align='right'>" . wfMsgHtml('allpagesfrom') . "</td>
60 <td align='left'><label for='nsfrom'>$frombox</label></td>
63 <td align='right'><label for='namespace'>" . wfMsgHtml('namespace') . "</label></td>
65 $namespaceselect $submitbutton
70 $out .= '</form></div>';
75 * @param integer $namespace (default NS_MAIN)
77 function indexShowToplevel ( $namespace = NS_MAIN, $including = false ) {
78 global $wgOut, $indexMaxperpage, $toplevelMaxperpage, $wgContLang, $wgRequest, $wgUser;
79 $sk = $wgUser->getSkin();
80 $fname = "indexShowToplevel";
82 # TODO: Either make this *much* faster or cache the title index points
83 # in the querycache table.
85 $dbr =& wfGetDB( DB_SLAVE );
86 $page = $dbr->tableName( 'page' );
87 $fromwhere = "FROM $page WHERE page_namespace=$namespace";
88 $order_arr = array ( 'ORDER BY' => 'page_title' );
89 $order_str = 'ORDER BY page_title';
91 $where = array( 'page_namespace' => $namespace );
93 global $wgMemc, $wgDBname;
94 $key = "$wgDBname:allpages:ns:$namespace";
95 $lines = $wgMemc->get( $key );
97 if( !is_array( $lines ) ) {
98 $firstTitle = $dbr->selectField( 'page', 'page_title', $where, $fname, array( 'LIMIT' => 1 ) );
99 $lastTitle = $firstTitle;
101 # This array is going to hold the page_titles in order.
102 $lines = array( $firstTitle );
104 # If we are going to show n rows, we need n+1 queries to find the relevant titles.
106 for( $i = 0; !$done; ++$i ) {
107 // Fetch the last title of this chunk and the first of the next
108 $chunk = is_null( $lastTitle )
110 : 'page_title >= ' . $dbr->addQuotes( $lastTitle );
111 $sql = "SELECT page_title $fromwhere AND $chunk $order_str " .
112 $dbr->limitResult( 2, $indexMaxperpage - 1 );
113 $res = $dbr->query( $sql, $fname );
114 if ( $s = $dbr->fetchObject( $res ) ) {
115 array_push( $lines, $s->page_title );
117 // Final chunk, but ended prematurely. Go back and find the end.
118 $endTitle = $dbr->selectField( 'page', 'MAX(page_title)',
120 'page_namespace' => $namespace,
123 array_push( $lines, $endTitle );
126 if( $s = $dbr->fetchObject( $res ) ) {
127 array_push( $lines, $s->page_title );
128 $lastTitle = $s->page_title;
130 // This was a final chunk and ended exactly at the limit.
131 // Rare but convenient!
134 $dbr->freeResult( $res );
136 $wgMemc->add( $key, $lines, 3600 );
139 // If there are only two or less sections, don't even display them.
140 // Instead, display the first section directly.
141 if( count( $lines ) <= 2 ) {
142 indexShowChunk( $namespace, '', false, $including );
146 # At this point, $lines should contain an even number of elements.
147 $out .= "<table style='background: inherit;'>";
148 while ( count ( $lines ) > 0 ) {
149 $inpoint = array_shift ( $lines );
150 $outpoint = array_shift ( $lines );
151 $out .= indexShowline ( $inpoint, $outpoint, $namespace, false );
155 $nsForm = indexNamespaceForm ( $namespace, '', false );
162 if ( $morelinks != '' ) {
163 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
164 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
165 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">';
166 $out2 .= $morelinks . '</td></tr></table><hr />';
168 $out2 = $nsForm . '<hr />';
172 $wgOut->addHtml( $out2 . $out );
177 * @param string $from
178 * @param integer $namespace (Default NS_MAIN)
180 function indexShowline( $inpoint, $outpoint, $namespace = NS_MAIN ) {
181 global $wgOut, $wgLang, $wgUser;
182 $sk = $wgUser->getSkin();
183 $dbr =& wfGetDB( DB_SLAVE );
185 $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
186 $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
187 $queryparams = ($namespace ? "namespace=$namespace" : '');
188 $special = Title::makeTitle( NS_SPECIAL, 'Allpages/' . $inpoint );
189 $link = $special->escapeLocalUrl( $queryparams );
193 "<a href=\"$link\">$inpointf</a></td><td><a href=\"$link\">",
194 "</a></td><td align=\"left\"><a href=\"$link\">$outpointf</a>"
196 return '<tr><td align="right">'.$out.'</td></tr>';
200 * @param integer $namespace (Default NS_MAIN)
201 * @param string $from list all pages from this name (default FALSE)
203 function indexShowChunk( $namespace = NS_MAIN, $from, $including = false ) {
204 global $wgOut, $wgUser, $indexMaxperpage, $wgContLang;
206 $fname = 'indexShowChunk';
208 $sk = $wgUser->getSkin();
210 $fromTitle = Title::newFromURL( $from );
211 $fromKey = is_null( $fromTitle ) ? '' : $fromTitle->getDBkey();
213 $dbr =& wfGetDB( DB_SLAVE );
214 $res = $dbr->select( 'page',
215 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
217 'page_namespace' => $namespace,
218 'page_title >= ' . $dbr->addQuotes( $fromKey )
222 'ORDER BY' => 'page_title',
223 'LIMIT' => $indexMaxperpage + 1,
224 'USE INDEX' => 'name_title',
228 ### FIXME: side link to previous
231 $out = '<table style="background: inherit;" border="0" width="100%">';
233 $namespaces = $wgContLang->getFormattedNamespaces();
234 while( ($n < $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
235 $t = Title::makeTitle( $s->page_namespace, $s->page_title );
237 $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
238 $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
239 ($s->page_is_redirect ? '</div>' : '' );
241 $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
246 $out .= "<td>$link</td>";
252 if( ($n % 3) != 0 ) {
260 $nsForm = indexNamespaceForm ( $namespace, $from );
261 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
262 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
263 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
264 $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
265 wfMsg ( 'allpages' ) );
266 if ( ($n == $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
267 $namespaceparam = $namespace ? "&namespace=$namespace" : "";
268 $out2 .= " | " . $sk->makeKnownLink(
269 $wgContLang->specialPage( "Allpages" ),
270 wfMsg ( 'nextpage', $s->page_title ),
271 "from=" . wfUrlEncode ( $s->page_title ) . $namespaceparam );
273 $out2 .= "</td></tr></table><hr />";
276 $wgOut->addHtml( $out2 . $out );