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
{
44 * HTML for the top form
45 * @param integer $namespace A namespace constant (default NS_MAIN).
46 * @param string $from Article name we are starting listing at.
48 function namespaceForm ( $namespace = NS_MAIN
, $from = '' ) {
49 global $wgContLang, $wgScript;
50 $t = Title
::makeTitle( NS_SPECIAL
, "Allpages" );
52 $namespaceselect = HTMLnamespaceselector($namespace, null);
54 $frombox = "<input type='text' size='20' name='from' id='nsfrom' value=\""
55 . htmlspecialchars ( $from ) . '"/>';
56 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . '" />';
58 $out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>";
59 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
61 <table id='nsselect' class='allpages'>
63 <td align='right'>" . wfMsgHtml('allpagesfrom') . "</td>
64 <td align='left'><label for='nsfrom'>$frombox</label></td>
67 <td align='right'><label for='nsselectbox'>" . wfMsgHtml('namespace') . "</label></td>
69 $namespaceselect $submitbutton
74 $out .= '</form></div>';
79 * @param integer $namespace (default NS_MAIN)
81 function showToplevel ( $namespace = NS_MAIN
, $including = false ) {
82 global $wgOut, $wgContLang, $wgRequest, $wgUser;
83 $sk = $wgUser->getSkin();
84 $fname = "indexShowToplevel";
86 # TODO: Either make this *much* faster or cache the title index points
87 # in the querycache table.
89 $dbr =& wfGetDB( DB_SLAVE
);
90 $page = $dbr->tableName( 'page' );
91 $fromwhere = "FROM $page WHERE page_namespace=$namespace";
92 $order_arr = array ( 'ORDER BY' => 'page_title' );
93 $order_str = 'ORDER BY page_title';
95 $where = array( 'page_namespace' => $namespace );
97 global $wgMemc, $wgDBname;
98 $key = "$wgDBname:allpages:ns:$namespace";
99 $lines = $wgMemc->get( $key );
101 if( !is_array( $lines ) ) {
102 $firstTitle = $dbr->selectField( 'page', 'page_title', $where, $fname, array( 'LIMIT' => 1 ) );
103 $lastTitle = $firstTitle;
105 # This array is going to hold the page_titles in order.
106 $lines = array( $firstTitle );
108 # If we are going to show n rows, we need n+1 queries to find the relevant titles.
110 for( $i = 0; !$done; ++
$i ) {
111 // Fetch the last title of this chunk and the first of the next
112 $chunk = is_null( $lastTitle )
114 : 'page_title >= ' . $dbr->addQuotes( $lastTitle );
115 $sql = "SELECT page_title $fromwhere AND $chunk $order_str " .
116 $dbr->limitResult( 2, $this->topLevelMax
- 1 );
117 $res = $dbr->query( $sql, $fname );
118 if ( $s = $dbr->fetchObject( $res ) ) {
119 array_push( $lines, $s->page_title
);
121 // Final chunk, but ended prematurely. Go back and find the end.
122 $endTitle = $dbr->selectField( 'page', 'MAX(page_title)',
124 'page_namespace' => $namespace,
127 array_push( $lines, $endTitle );
130 if( $s = $dbr->fetchObject( $res ) ) {
131 array_push( $lines, $s->page_title
);
132 $lastTitle = $s->page_title
;
134 // This was a final chunk and ended exactly at the limit.
135 // Rare but convenient!
138 $dbr->freeResult( $res );
140 $wgMemc->add( $key, $lines, 3600 );
143 // If there are only two or less sections, don't even display them.
144 // Instead, display the first section directly.
145 if( count( $lines ) <= 2 ) {
146 $this->showChunk( $namespace, '', false, $including );
150 # At this point, $lines should contain an even number of elements.
151 $out .= "<table style='background: inherit;'>";
152 while ( count ( $lines ) > 0 ) {
153 $inpoint = array_shift ( $lines );
154 $outpoint = array_shift ( $lines );
155 $out .= $this->showline ( $inpoint, $outpoint, $namespace, false );
158 $nsForm = $this->namespaceForm ( $namespace, '', false );
165 if ( $morelinks != '' ) {
166 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
167 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
168 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">';
169 $out2 .= $morelinks . '</td></tr></table><hr />';
171 $out2 = $nsForm . '<hr />';
175 $wgOut->addHtml( $out2 . $out );
180 * @param string $from
181 * @param integer $namespace (Default NS_MAIN)
183 function showline( $inpoint, $outpoint, $namespace = NS_MAIN
) {
184 global $wgOut, $wgLang, $wgUser;
185 $sk = $wgUser->getSkin();
186 $dbr =& wfGetDB( DB_SLAVE
);
188 $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
189 $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
190 $queryparams = ($namespace ?
"namespace=$namespace" : '');
191 $special = Title
::makeTitle( NS_SPECIAL
, 'Allpages/' . $inpoint );
192 $link = $special->escapeLocalUrl( $queryparams );
196 "<a href=\"$link\">$inpointf</a></td><td><a href=\"$link\">",
197 "</a></td><td align=\"left\"><a href=\"$link\">$outpointf</a>"
199 return '<tr><td align="right">'.$out.'</td></tr>';
203 * @param integer $namespace (Default NS_MAIN)
204 * @param string $from list all pages from this name (default FALSE)
206 function showChunk( $namespace = NS_MAIN
, $from, $including = false ) {
207 global $wgOut, $wgUser, $wgContLang;
209 $fname = 'indexShowChunk';
211 $sk = $wgUser->getSkin();
215 $fromTitle = Title
::newFromURL( $from );
216 $fromNS = $fromTitle->getNamespace();
217 if ($namespace == NS_MAIN
)
218 $namespace = $fromNS;
220 $fromKey = is_null( $fromTitle ) ?
'' : $fromTitle->getDBkey();
222 $dbr =& wfGetDB( DB_SLAVE
);
223 $res = $dbr->select( 'page',
224 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
226 'page_namespace' => $namespace,
227 'page_title >= ' . $dbr->addQuotes( $fromKey )
231 'ORDER BY' => 'page_title',
232 'LIMIT' => $this->maxPerPage +
1,
233 'USE INDEX' => 'name_title',
237 ### FIXME: side link to previous
240 $out = '<table style="background: inherit;" border="0" width="100%">';
242 $namespaces = $wgContLang->getFormattedNamespaces();
243 while( ($n < $this->maxPerPage
) && ($s = $dbr->fetchObject( $res )) ) {
244 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
246 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
247 $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
248 ($s->page_is_redirect ?
'</div>' : '' );
250 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
255 $out .= "<td>$link</td>";
261 if( ($n %
3) != 0 ) {
269 $nsForm = $this->namespaceForm ( $namespace, $from );
270 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
271 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
272 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
273 $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
274 wfMsg ( 'allpages' ) );
275 if ( ($n == $this->maxPerPage
) && ($s = $dbr->fetchObject( $res )) ) {
276 $namespaceparam = $namespace ?
"&namespace=$namespace" : "";
277 $out2 .= " | " . $sk->makeKnownLink(
278 $wgContLang->specialPage( "Allpages" ),
279 wfMsg ( 'nextpage', $s->page_title
),
280 "from=" . wfUrlEncode ( $s->page_title
) . $namespaceparam );
282 $out2 .= "</td></tr></table><hr />";
285 $wgOut->addHtml( $out2 . $out );