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
{
45 * HTML for the top form
46 * @param integer $namespace A namespace constant (default NS_MAIN).
47 * @param string $from Article name we are starting listing at.
49 function namespaceForm ( $namespace = NS_MAIN
, $from = '' ) {
50 global $wgContLang, $wgScript;
51 $t = Title
::makeTitle( NS_SPECIAL
, $this->name
);
53 $namespaceselect = HTMLnamespaceselector($namespace, null);
55 $frombox = "<input type='text' size='20' name='from' id='nsfrom' value=\""
56 . htmlspecialchars ( $from ) . '"/>';
57 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . '" />';
59 $out = "<div class='namespaceoptions'><form method='get' action='{$wgScript}'>";
60 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
62 <table id='nsselect' class='allpages'>
64 <td align='right'>" . wfMsgHtml('allpagesfrom') . "</td>
65 <td align='left'><label for='nsfrom'>$frombox</label></td>
68 <td align='right'><label for='namespace'>" . wfMsgHtml('namespace') . "</label></td>
70 $namespaceselect $submitbutton
75 $out .= '</form></div>';
80 * @param integer $namespace (default NS_MAIN)
82 function showToplevel ( $namespace = NS_MAIN
, $including = false ) {
83 global $wgOut, $wgContLang, $wgRequest, $wgUser;
84 $sk = $wgUser->getSkin();
85 $fname = "indexShowToplevel";
87 # TODO: Either make this *much* faster or cache the title index points
88 # in the querycache table.
90 $dbr =& wfGetDB( DB_SLAVE
);
91 $page = $dbr->tableName( 'page' );
92 $fromwhere = "FROM $page WHERE page_namespace=$namespace";
93 $order_arr = array ( 'ORDER BY' => 'page_title' );
94 $order_str = 'ORDER BY page_title';
96 $where = array( 'page_namespace' => $namespace );
98 global $wgMemc, $wgDBname;
99 $key = "$wgDBname:allpages:ns:$namespace";
100 $lines = $wgMemc->get( $key );
102 if( !is_array( $lines ) ) {
103 $firstTitle = $dbr->selectField( 'page', 'page_title', $where, $fname, array( 'LIMIT' => 1 ) );
104 $lastTitle = $firstTitle;
106 # This array is going to hold the page_titles in order.
107 $lines = array( $firstTitle );
109 # If we are going to show n rows, we need n+1 queries to find the relevant titles.
111 for( $i = 0; !$done; ++
$i ) {
112 // Fetch the last title of this chunk and the first of the next
113 $chunk = is_null( $lastTitle )
115 : 'page_title >= ' . $dbr->addQuotes( $lastTitle );
118 'page_title', /* WHAT */
119 $where +
array( $chunk),
121 array ('LIMIT' => 2, 'OFFSET' => $this->maxPerPage
- 1, 'ORDER BY' => 'page_title') );
123 if ( $s = $dbr->fetchObject( $res ) ) {
124 array_push( $lines, $s->page_title
);
126 // Final chunk, but ended prematurely. Go back and find the end.
127 $endTitle = $dbr->selectField( 'page', 'MAX(page_title)',
129 'page_namespace' => $namespace,
132 array_push( $lines, $endTitle );
135 if( $s = $dbr->fetchObject( $res ) ) {
136 array_push( $lines, $s->page_title
);
137 $lastTitle = $s->page_title
;
139 // This was a final chunk and ended exactly at the limit.
140 // Rare but convenient!
143 $dbr->freeResult( $res );
145 $wgMemc->add( $key, $lines, 3600 );
148 // If there are only two or less sections, don't even display them.
149 // Instead, display the first section directly.
150 if( count( $lines ) <= 2 ) {
151 $this->showChunk( $namespace, '', false, $including );
155 # At this point, $lines should contain an even number of elements.
156 $out .= "<table style='background: inherit;'>";
157 while ( count ( $lines ) > 0 ) {
158 $inpoint = array_shift ( $lines );
159 $outpoint = array_shift ( $lines );
160 $out .= $this->showline ( $inpoint, $outpoint, $namespace, false );
163 $nsForm = $this->namespaceForm ( $namespace, '', false );
170 if ( $morelinks != '' ) {
171 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
172 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
173 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">';
174 $out2 .= $morelinks . '</td></tr></table><hr />';
176 $out2 = $nsForm . '<hr />';
180 $wgOut->addHtml( $out2 . $out );
185 * @param string $from
186 * @param integer $namespace (Default NS_MAIN)
188 function showline( $inpoint, $outpoint, $namespace = NS_MAIN
) {
189 global $wgOut, $wgLang, $wgUser;
190 $sk = $wgUser->getSkin();
191 $dbr =& wfGetDB( DB_SLAVE
);
193 $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
194 $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
195 $queryparams = ($namespace ?
"namespace=$namespace" : '');
196 $special = Title
::makeTitle( NS_SPECIAL
, $this->name
. '/' . $inpoint );
197 $link = $special->escapeLocalUrl( $queryparams );
201 "<a href=\"$link\">$inpointf</a></td><td><a href=\"$link\">",
202 "</a></td><td align=\"left\"><a href=\"$link\">$outpointf</a>"
204 return '<tr><td align="right">'.$out.'</td></tr>';
208 * @param integer $namespace (Default NS_MAIN)
209 * @param string $from list all pages from this name (default FALSE)
211 function showChunk( $namespace = NS_MAIN
, $from, $including = false ) {
212 global $wgOut, $wgUser, $wgContLang;
214 $fname = 'indexShowChunk';
216 $sk = $wgUser->getSkin();
220 $fromTitle = Title
::newFromURL( $from );
224 $fromNS = $fromTitle->getNamespace();
225 if ($namespace == NS_MAIN
)
226 $namespace = $fromNS;
228 $fromKey = is_null( $fromTitle ) ?
'' : $fromTitle->getDBkey();
230 $dbr =& wfGetDB( DB_SLAVE
);
231 $res = $dbr->select( 'page',
232 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
234 'page_namespace' => $namespace,
235 'page_title >= ' . $dbr->addQuotes( $fromKey )
239 'ORDER BY' => 'page_title',
240 'LIMIT' => $this->maxPerPage +
1,
241 'USE INDEX' => 'name_title',
245 ### FIXME: side link to previous
248 $out = '<table style="background: inherit;" border="0" width="100%">';
250 $namespaces = $wgContLang->getFormattedNamespaces();
251 while( ($n < $this->maxPerPage
) && ($s = $dbr->fetchObject( $res )) ) {
252 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
254 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
255 $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
256 ($s->page_is_redirect ?
'</div>' : '' );
258 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
263 $out .= "<td>$link</td>";
269 if( ($n %
3) != 0 ) {
277 $nsForm = $this->namespaceForm ( $namespace, $from );
278 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
279 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
280 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
281 $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
282 wfMsgHtml ( 'allpages' ) );
283 if ( ($n == $this->maxPerPage
) && ($s = $dbr->fetchObject( $res )) ) {
284 $namespaceparam = $namespace ?
"&namespace=$namespace" : "";
285 $out2 .= " | " . $sk->makeKnownLink(
286 $wgContLang->specialPage( "Allpages" ),
287 wfMsgHtml ( 'nextpage', $s->page_title
),
288 "from=" . wfUrlEncode ( $s->page_title
) . $namespaceparam );
290 $out2 .= "</td></tr></table><hr />";
293 $wgOut->addHtml( $out2 . $out );