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 $wgRequest, $wgOut, $wgContLang;
15 $from = $wgRequest->getVal( 'from' );
16 $namespace = $wgRequest->getInt( 'namespace' );
18 $namespaces = $wgContLang->getNamespaces();
20 $indexPage = new SpecialAllpages();
22 if( !in_array($namespace, array_keys($namespaces)) )
25 $wgOut->setPagetitle( $namespace > 0 ?
26 wfMsg( 'allinnamespace', $namespaces[$namespace] ) :
27 wfMsg( 'allarticles' )
31 $indexPage->showChunk( $namespace, $par, $specialPage->including() );
32 } elseif ( isset($from) ) {
33 $indexPage->showChunk( $namespace, $from, $specialPage->including() );
35 $indexPage->showToplevel ( $namespace, $specialPage->including() );
39 class SpecialAllpages
{
43 # Determines, which message describes the input field 'nsfrom' (->SpecialPrefixindex.php)
44 var $nsfromMsg='allpagesfrom';
47 * HTML for the top form
48 * @param integer $namespace A namespace constant (default NS_MAIN).
49 * @param string $from Article name we are starting listing at.
51 function namespaceForm ( $namespace = NS_MAIN
, $from = '' ) {
53 $t = Title
::makeTitle( NS_SPECIAL
, $this->name
);
55 $namespaceselect = HTMLnamespaceselector($namespace, null);
57 $frombox = "<input type='text' size='20' name='from' id='nsfrom' value=\""
58 . htmlspecialchars ( $from ) . '"/>';
59 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . '" />';
61 $out = "<div class='namespaceoptions'><form method='get' action='{$wgScript}'>";
62 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
64 <table id='nsselect' class='allpages'>
66 <td align='right'>" . wfMsgHtml($this->nsfromMsg
) . "</td>
67 <td align='left'><label for='nsfrom'>$frombox</label></td>
70 <td align='right'><label for='namespace'>" . wfMsgHtml('namespace') . "</label></td>
72 $namespaceselect $submitbutton
77 $out .= '</form></div>';
82 * @param integer $namespace (default NS_MAIN)
84 function showToplevel ( $namespace = NS_MAIN
, $including = false ) {
85 global $wgOut, $wgUser;
86 $sk = $wgUser->getSkin();
87 $fname = "indexShowToplevel";
89 # TODO: Either make this *much* faster or cache the title index points
90 # in the querycache table.
92 $dbr =& wfGetDB( DB_SLAVE
);
93 $page = $dbr->tableName( 'page' );
94 $fromwhere = "FROM $page WHERE page_namespace=$namespace";
95 $order_arr = array ( 'ORDER BY' => 'page_title' );
96 $order_str = 'ORDER BY page_title';
98 $where = array( 'page_namespace' => $namespace );
100 global $wgMemc, $wgDBname;
101 $key = "$wgDBname:allpages:ns:$namespace";
102 $lines = $wgMemc->get( $key );
104 if( !is_array( $lines ) ) {
105 $firstTitle = $dbr->selectField( 'page', 'page_title', $where, $fname, array( 'LIMIT' => 1 ) );
106 $lastTitle = $firstTitle;
108 # This array is going to hold the page_titles in order.
109 $lines = array( $firstTitle );
111 # If we are going to show n rows, we need n+1 queries to find the relevant titles.
113 for( $i = 0; !$done; ++
$i ) {
114 // Fetch the last title of this chunk and the first of the next
115 $chunk = is_null( $lastTitle )
117 : 'page_title >= ' . $dbr->addQuotes( $lastTitle );
120 'page_title', /* WHAT */
121 $where +
array( $chunk),
123 array ('LIMIT' => 2, 'OFFSET' => $this->maxPerPage
- 1, 'ORDER BY' => 'page_title') );
125 if ( $s = $dbr->fetchObject( $res ) ) {
126 array_push( $lines, $s->page_title
);
128 // Final chunk, but ended prematurely. Go back and find the end.
129 $endTitle = $dbr->selectField( 'page', 'MAX(page_title)',
131 'page_namespace' => $namespace,
134 array_push( $lines, $endTitle );
137 if( $s = $dbr->fetchObject( $res ) ) {
138 array_push( $lines, $s->page_title
);
139 $lastTitle = $s->page_title
;
141 // This was a final chunk and ended exactly at the limit.
142 // Rare but convenient!
145 $dbr->freeResult( $res );
147 $wgMemc->add( $key, $lines, 3600 );
150 // If there are only two or less sections, don't even display them.
151 // Instead, display the first section directly.
152 if( count( $lines ) <= 2 ) {
153 $this->showChunk( $namespace, '', $including );
157 # At this point, $lines should contain an even number of elements.
158 $out .= "<table style='background: inherit;'>";
159 while ( count ( $lines ) > 0 ) {
160 $inpoint = array_shift ( $lines );
161 $outpoint = array_shift ( $lines );
162 $out .= $this->showline ( $inpoint, $outpoint, $namespace, false );
165 $nsForm = $this->namespaceForm ( $namespace, '', false );
172 if ( $morelinks != '' ) {
173 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
174 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
175 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">';
176 $out2 .= $morelinks . '</td></tr></table><hr />';
178 $out2 = $nsForm . '<hr />';
182 $wgOut->addHtml( $out2 . $out );
187 * @param string $from
188 * @param integer $namespace (Default NS_MAIN)
190 function showline( $inpoint, $outpoint, $namespace = NS_MAIN
) {
192 $sk = $wgUser->getSkin();
193 $dbr =& wfGetDB( DB_SLAVE
);
195 $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
196 $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
197 $queryparams = ($namespace ?
"namespace=$namespace" : '');
198 $special = Title
::makeTitle( NS_SPECIAL
, $this->name
. '/' . $inpoint );
199 $link = $special->escapeLocalUrl( $queryparams );
203 "<a href=\"$link\">$inpointf</a></td><td><a href=\"$link\">",
204 "</a></td><td align=\"left\"><a href=\"$link\">$outpointf</a>"
206 return '<tr><td align="right">'.$out.'</td></tr>';
210 * @param integer $namespace (Default NS_MAIN)
211 * @param string $from list all pages from this name (default FALSE)
213 function showChunk( $namespace = NS_MAIN
, $from, $including = false ) {
214 global $wgOut, $wgUser, $wgContLang;
216 $fname = 'indexShowChunk';
218 $sk = $wgUser->getSkin();
222 $fromTitle = Title
::newFromURL( $from );
226 $fromNS = $fromTitle->getNamespace();
227 if ($namespace == NS_MAIN
)
228 $namespace = $fromNS;
230 $fromKey = is_null( $fromTitle ) ?
'' : $fromTitle->getDBkey();
232 $dbr =& wfGetDB( DB_SLAVE
);
233 $res = $dbr->select( 'page',
234 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
236 'page_namespace' => $namespace,
237 'page_title >= ' . $dbr->addQuotes( $fromKey )
241 'ORDER BY' => 'page_title',
242 'LIMIT' => $this->maxPerPage +
1,
243 'USE INDEX' => 'name_title',
247 ### FIXME: side link to previous
250 $out = '<table style="background: inherit;" border="0" width="100%">';
252 $namespaces = $wgContLang->getFormattedNamespaces();
253 while( ($n < $this->maxPerPage
) && ($s = $dbr->fetchObject( $res )) ) {
254 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
256 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
257 $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
258 ($s->page_is_redirect ?
'</div>' : '' );
260 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
265 $out .= "<td>$link</td>";
271 if( ($n %
3) != 0 ) {
280 $nsForm = $this->namespaceForm ( $namespace, $from );
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 wfMsgHtml ( 'allpages' ) );
286 if ( ($n == $this->maxPerPage
) && ($s = $dbr->fetchObject( $res )) ) {
287 $namespaceparam = $namespace ?
"&namespace=$namespace" : "";
288 $out2 .= " | " . $sk->makeKnownLink(
289 $wgContLang->specialPage( "Allpages" ),
290 wfMsgHtml ( 'nextpage', $s->page_title
),
291 "from=" . wfUrlEncode ( $s->page_title
) . $namespaceparam );
293 $out2 .= "</td></tr></table><hr />";
296 $wgOut->addHtml( $out2 . $out );