2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2005-01-19 14:05:40 +00:00
|
|
|
* Entry point : initialise variables and call subfunctions.
|
2005-04-01 16:24:04 +00:00
|
|
|
* @param string $par Becomes "FOO" when called like Special:Allpages/FOO (default NULL)
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2005-05-28 11:09:22 +00:00
|
|
|
function wfSpecialAllpages( $par=NULL, $specialPage ) {
|
2005-08-01 19:25:44 +00:00
|
|
|
global $wgRequest, $wgOut, $wgContLang;
|
|
|
|
|
|
2005-04-01 11:09:47 +00:00
|
|
|
# GET values
|
2004-04-01 12:53:01 +00:00
|
|
|
$from = $wgRequest->getVal( 'from' );
|
2004-08-14 08:57:51 +00:00
|
|
|
$namespace = $wgRequest->getInt( 'namespace' );
|
2005-04-01 11:09:47 +00:00
|
|
|
|
2005-05-03 18:27:40 +00:00
|
|
|
$namespaces = $wgContLang->getNamespaces();
|
2005-04-01 11:09:47 +00:00
|
|
|
|
2005-08-01 19:25:44 +00:00
|
|
|
$indexPage = new SpecialAllpages();
|
|
|
|
|
|
2005-05-03 18:27:40 +00:00
|
|
|
if( !in_array($namespace, array_keys($namespaces)) )
|
2004-08-14 08:57:51 +00:00
|
|
|
$namespace = 0;
|
2004-08-13 00:56:03 +00:00
|
|
|
|
2005-07-18 22:15:05 +00:00
|
|
|
$wgOut->setPagetitle( $namespace > 0 ?
|
|
|
|
|
wfMsg( 'allinnamespace', $namespaces[$namespace] ) :
|
|
|
|
|
wfMsg( 'allarticles' )
|
|
|
|
|
);
|
2005-04-01 11:09:47 +00:00
|
|
|
|
2005-05-06 05:48:57 +00:00
|
|
|
if ( isset($par) ) {
|
2005-08-01 19:25:44 +00:00
|
|
|
$indexPage->showChunk( $namespace, $par, $specialPage->including() );
|
2005-05-06 05:48:57 +00:00
|
|
|
} elseif ( isset($from) ) {
|
2005-08-01 19:25:44 +00:00
|
|
|
$indexPage->showChunk( $namespace, $from, $specialPage->including() );
|
2003-04-14 23:10:40 +00:00
|
|
|
} else {
|
2005-08-01 19:25:44 +00:00
|
|
|
$indexPage->showToplevel ( $namespace, $specialPage->including() );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-01 19:25:44 +00:00
|
|
|
class SpecialAllpages {
|
|
|
|
|
var $maxPerPage=960;
|
|
|
|
|
var $topLevelMax=50;
|
|
|
|
|
|
2005-01-19 14:05:40 +00:00
|
|
|
/**
|
|
|
|
|
* HTML for the top form
|
|
|
|
|
* @param integer $namespace A namespace constant (default NS_MAIN).
|
|
|
|
|
* @param string $from Article name we are starting listing at.
|
|
|
|
|
*/
|
2005-08-01 19:25:44 +00:00
|
|
|
function namespaceForm ( $namespace = NS_MAIN, $from = '' ) {
|
2004-09-24 16:24:43 +00:00
|
|
|
global $wgContLang, $wgScript;
|
2004-08-13 07:46:33 +00:00
|
|
|
$t = Title::makeTitle( NS_SPECIAL, "Allpages" );
|
|
|
|
|
|
2005-08-01 23:47:22 +00:00
|
|
|
$namespaceselect = HTMLnamespaceselector($namespace, null);
|
2004-08-13 07:46:33 +00:00
|
|
|
|
2005-05-03 18:27:40 +00:00
|
|
|
$frombox = "<input type='text' size='20' name='from' id='nsfrom' value=\""
|
2004-08-13 07:46:33 +00:00
|
|
|
. htmlspecialchars ( $from ) . '"/>';
|
2005-08-01 20:48:29 +00:00
|
|
|
$submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . '" />';
|
2005-04-01 11:09:47 +00:00
|
|
|
|
2004-08-13 07:46:33 +00:00
|
|
|
$out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>";
|
|
|
|
|
$out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
|
2005-05-03 18:27:40 +00:00
|
|
|
$out .= "
|
|
|
|
|
<table id='nsselect' class='allpages'>
|
|
|
|
|
<tr>
|
2005-08-01 20:48:29 +00:00
|
|
|
<td align='right'>" . wfMsgHtml('allpagesfrom') . "</td>
|
2005-05-03 18:27:40 +00:00
|
|
|
<td align='left'><label for='nsfrom'>$frombox</label></td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2005-08-01 20:48:29 +00:00
|
|
|
<td align='right'><label for='nsselectbox'>" . wfMsgHtml('namespace') . "</label></td>
|
2005-06-24 23:19:57 +00:00
|
|
|
<td align='left'>
|
2005-07-18 22:15:05 +00:00
|
|
|
$namespaceselect $submitbutton
|
2005-06-24 23:19:57 +00:00
|
|
|
</td>
|
2005-05-03 18:27:40 +00:00
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
";
|
2004-08-13 07:46:33 +00:00
|
|
|
$out .= '</form></div>';
|
2005-05-03 18:27:40 +00:00
|
|
|
return $out;
|
2004-08-13 07:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-19 14:05:40 +00:00
|
|
|
/**
|
|
|
|
|
* @param integer $namespace (default NS_MAIN)
|
|
|
|
|
*/
|
2005-08-01 19:25:44 +00:00
|
|
|
function showToplevel ( $namespace = NS_MAIN, $including = false ) {
|
|
|
|
|
global $wgOut, $wgContLang, $wgRequest, $wgUser;
|
2004-08-13 07:46:33 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
2003-04-14 23:10:40 +00:00
|
|
|
$fname = "indexShowToplevel";
|
2003-05-16 11:19:06 +00:00
|
|
|
|
2004-08-30 08:22:15 +00:00
|
|
|
# TODO: Either make this *much* faster or cache the title index points
|
|
|
|
|
# in the querycache table.
|
2004-08-13 00:56:03 +00:00
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
2004-12-19 08:00:50 +00:00
|
|
|
$page = $dbr->tableName( 'page' );
|
2005-07-18 22:15:05 +00:00
|
|
|
$fromwhere = "FROM $page WHERE page_namespace=$namespace";
|
2004-12-19 08:00:50 +00:00
|
|
|
$order_arr = array ( 'ORDER BY' => 'page_title' );
|
|
|
|
|
$order_str = 'ORDER BY page_title';
|
2003-04-14 23:10:40 +00:00
|
|
|
$out = "";
|
2004-12-19 08:00:50 +00:00
|
|
|
$where = array( 'page_namespace' => $namespace );
|
2004-07-08 16:50:22 +00:00
|
|
|
|
2005-07-18 22:15:05 +00:00
|
|
|
global $wgMemc, $wgDBname;
|
|
|
|
|
$key = "$wgDBname:allpages:ns:$namespace";
|
|
|
|
|
$lines = $wgMemc->get( $key );
|
2005-04-01 11:09:47 +00:00
|
|
|
|
2005-07-18 22:15:05 +00:00
|
|
|
if( !is_array( $lines ) ) {
|
|
|
|
|
$firstTitle = $dbr->selectField( 'page', 'page_title', $where, $fname, array( 'LIMIT' => 1 ) );
|
|
|
|
|
$lastTitle = $firstTitle;
|
|
|
|
|
|
|
|
|
|
# This array is going to hold the page_titles in order.
|
|
|
|
|
$lines = array( $firstTitle );
|
|
|
|
|
|
|
|
|
|
# If we are going to show n rows, we need n+1 queries to find the relevant titles.
|
|
|
|
|
$done = false;
|
|
|
|
|
for( $i = 0; !$done; ++$i ) {
|
|
|
|
|
// Fetch the last title of this chunk and the first of the next
|
|
|
|
|
$chunk = is_null( $lastTitle )
|
|
|
|
|
? '1=1'
|
|
|
|
|
: 'page_title >= ' . $dbr->addQuotes( $lastTitle );
|
|
|
|
|
$sql = "SELECT page_title $fromwhere AND $chunk $order_str " .
|
2005-08-01 19:25:44 +00:00
|
|
|
$dbr->limitResult( 2, $this->topLevelMax - 1 );
|
2005-07-18 22:15:05 +00:00
|
|
|
$res = $dbr->query( $sql, $fname );
|
2005-04-25 15:35:02 +00:00
|
|
|
if ( $s = $dbr->fetchObject( $res ) ) {
|
2005-07-18 22:15:05 +00:00
|
|
|
array_push( $lines, $s->page_title );
|
|
|
|
|
} else {
|
|
|
|
|
// Final chunk, but ended prematurely. Go back and find the end.
|
|
|
|
|
$endTitle = $dbr->selectField( 'page', 'MAX(page_title)',
|
|
|
|
|
array(
|
|
|
|
|
'page_namespace' => $namespace,
|
|
|
|
|
$chunk
|
|
|
|
|
), $fname );
|
|
|
|
|
array_push( $lines, $endTitle );
|
|
|
|
|
$done = true;
|
|
|
|
|
}
|
|
|
|
|
if( $s = $dbr->fetchObject( $res ) ) {
|
|
|
|
|
array_push( $lines, $s->page_title );
|
|
|
|
|
$lastTitle = $s->page_title;
|
|
|
|
|
} else {
|
|
|
|
|
// This was a final chunk and ended exactly at the limit.
|
|
|
|
|
// Rare but convenient!
|
|
|
|
|
$done = true;
|
2005-04-25 15:35:02 +00:00
|
|
|
}
|
2005-07-18 22:15:05 +00:00
|
|
|
$dbr->freeResult( $res );
|
2004-08-13 07:46:33 +00:00
|
|
|
}
|
2005-07-18 22:15:05 +00:00
|
|
|
$wgMemc->add( $key, $lines, 3600 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If there are only two or less sections, don't even display them.
|
|
|
|
|
// Instead, display the first section directly.
|
|
|
|
|
if( count( $lines ) <= 2 ) {
|
2005-08-01 19:25:44 +00:00
|
|
|
$this->showChunk( $namespace, '', false, $including );
|
2005-07-18 22:15:05 +00:00
|
|
|
return;
|
2004-08-13 07:46:33 +00:00
|
|
|
}
|
2004-07-08 16:50:22 +00:00
|
|
|
|
2004-08-13 07:46:33 +00:00
|
|
|
# At this point, $lines should contain an even number of elements.
|
|
|
|
|
$out .= "<table style='background: inherit;'>";
|
|
|
|
|
while ( count ( $lines ) > 0 ) {
|
|
|
|
|
$inpoint = array_shift ( $lines );
|
|
|
|
|
$outpoint = array_shift ( $lines );
|
2005-08-01 19:25:44 +00:00
|
|
|
$out .= $this->showline ( $inpoint, $outpoint, $namespace, false );
|
2004-08-13 07:46:33 +00:00
|
|
|
}
|
2005-01-19 14:05:40 +00:00
|
|
|
$out .= '</table>';
|
2005-08-01 19:25:44 +00:00
|
|
|
$nsForm = $this->namespaceForm ( $namespace, '', false );
|
2005-05-28 11:09:22 +00:00
|
|
|
|
2004-08-13 07:46:33 +00:00
|
|
|
# Is there more?
|
2005-05-28 11:09:22 +00:00
|
|
|
if ( $including ) {
|
|
|
|
|
$out2 = '';
|
2004-08-13 07:46:33 +00:00
|
|
|
} else {
|
2005-05-28 11:09:22 +00:00
|
|
|
$morelinks = '';
|
|
|
|
|
if ( $morelinks != '' ) {
|
|
|
|
|
$out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
|
|
|
|
|
$out2 .= '<tr valign="top"><td align="left">' . $nsForm;
|
|
|
|
|
$out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">';
|
|
|
|
|
$out2 .= $morelinks . '</td></tr></table><hr />';
|
|
|
|
|
} else {
|
|
|
|
|
$out2 = $nsForm . '<hr />';
|
|
|
|
|
}
|
2004-08-13 07:46:33 +00:00
|
|
|
}
|
2003-05-16 11:19:06 +00:00
|
|
|
|
2004-08-13 07:46:33 +00:00
|
|
|
$wgOut->addHtml( $out2 . $out );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-19 14:05:40 +00:00
|
|
|
/**
|
|
|
|
|
* @todo Document
|
2005-08-02 13:35:19 +00:00
|
|
|
* @param string $from
|
2005-01-19 14:05:40 +00:00
|
|
|
* @param integer $namespace (Default NS_MAIN)
|
|
|
|
|
*/
|
2005-08-01 19:25:44 +00:00
|
|
|
function showline( $inpoint, $outpoint, $namespace = NS_MAIN ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
global $wgOut, $wgLang, $wgUser;
|
|
|
|
|
$sk = $wgUser->getSkin();
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2005-01-19 14:05:40 +00:00
|
|
|
$inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
|
|
|
|
|
$outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
|
2005-07-18 22:15:05 +00:00
|
|
|
$queryparams = ($namespace ? "namespace=$namespace" : '');
|
2004-08-30 08:22:15 +00:00
|
|
|
$special = Title::makeTitle( NS_SPECIAL, 'Allpages/' . $inpoint );
|
|
|
|
|
$link = $special->escapeLocalUrl( $queryparams );
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$out = wfMsg(
|
2004-08-13 07:46:33 +00:00
|
|
|
'alphaindexline',
|
2004-08-30 08:22:15 +00:00
|
|
|
"<a href=\"$link\">$inpointf</a></td><td><a href=\"$link\">",
|
|
|
|
|
"</a></td><td align=\"left\"><a href=\"$link\">$outpointf</a>"
|
2004-08-13 07:46:33 +00:00
|
|
|
);
|
|
|
|
|
return '<tr><td align="right">'.$out.'</td></tr>';
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2005-04-01 11:57:44 +00:00
|
|
|
/**
|
|
|
|
|
* @param integer $namespace (Default NS_MAIN)
|
|
|
|
|
* @param string $from list all pages from this name (default FALSE)
|
|
|
|
|
*/
|
2005-08-01 19:25:44 +00:00
|
|
|
function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
|
|
|
|
|
global $wgOut, $wgUser, $wgContLang;
|
2004-07-08 16:50:22 +00:00
|
|
|
|
2005-07-19 02:55:56 +00:00
|
|
|
$fname = 'indexShowChunk';
|
2004-09-02 02:22:42 +00:00
|
|
|
|
2005-07-19 02:55:56 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
|
|
|
|
|
2005-08-01 23:47:22 +00:00
|
|
|
$fromTitle = null;
|
2005-08-01 23:30:48 +00:00
|
|
|
if ($from!="") {
|
|
|
|
|
$fromTitle = Title::newFromURL( $from );
|
|
|
|
|
$fromNS = $fromTitle->getNamespace();
|
|
|
|
|
if ($namespace == NS_MAIN)
|
|
|
|
|
$namespace = $fromNS;
|
|
|
|
|
}
|
2004-09-02 02:22:42 +00:00
|
|
|
$fromKey = is_null( $fromTitle ) ? '' : $fromTitle->getDBkey();
|
|
|
|
|
|
2005-07-19 02:55:56 +00:00
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
$res = $dbr->select( 'page',
|
2005-07-19 03:08:02 +00:00
|
|
|
array( 'page_namespace', 'page_title', 'page_is_redirect' ),
|
2005-07-19 02:55:56 +00:00
|
|
|
array(
|
|
|
|
|
'page_namespace' => $namespace,
|
|
|
|
|
'page_title >= ' . $dbr->addQuotes( $fromKey )
|
|
|
|
|
),
|
|
|
|
|
$fname,
|
|
|
|
|
array(
|
2005-07-21 12:53:29 +00:00
|
|
|
'ORDER BY' => 'page_title',
|
2005-08-01 19:25:44 +00:00
|
|
|
'LIMIT' => $this->maxPerPage + 1,
|
2005-07-21 12:53:29 +00:00
|
|
|
'USE INDEX' => 'name_title',
|
2005-07-19 02:55:56 +00:00
|
|
|
)
|
|
|
|
|
);
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-07-08 16:50:22 +00:00
|
|
|
### FIXME: side link to previous
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$n = 0;
|
2004-08-13 07:46:33 +00:00
|
|
|
$out = '<table style="background: inherit;" border="0" width="100%">';
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-05-03 13:17:54 +00:00
|
|
|
$namespaces = $wgContLang->getFormattedNamespaces();
|
2005-08-01 19:25:44 +00:00
|
|
|
while( ($n < $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
|
2005-04-01 15:46:25 +00:00
|
|
|
$t = Title::makeTitle( $s->page_namespace, $s->page_title );
|
2003-11-12 10:21:28 +00:00
|
|
|
if( $t ) {
|
2005-07-19 03:08:02 +00:00
|
|
|
$link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
|
|
|
|
|
$sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
|
|
|
|
|
($s->page_is_redirect ? '</div>' : '' );
|
2003-11-12 10:21:28 +00:00
|
|
|
} else {
|
2004-12-19 08:00:50 +00:00
|
|
|
$link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
|
2003-11-12 10:21:28 +00:00
|
|
|
}
|
2004-07-08 16:50:22 +00:00
|
|
|
if( $n % 3 == 0 ) {
|
2004-08-13 07:46:33 +00:00
|
|
|
$out .= '<tr>';
|
2004-04-09 08:27:00 +00:00
|
|
|
}
|
2004-07-08 16:50:22 +00:00
|
|
|
$out .= "<td>$link</td>";
|
|
|
|
|
$n++;
|
|
|
|
|
if( $n % 3 == 0 ) {
|
2004-08-13 07:46:33 +00:00
|
|
|
$out .= '</tr>';
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-07-08 16:50:22 +00:00
|
|
|
if( ($n % 3) != 0 ) {
|
2004-08-13 07:46:33 +00:00
|
|
|
$out .= '</tr>';
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2004-08-13 07:46:33 +00:00
|
|
|
$out .= '</table>';
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-05-28 11:09:22 +00:00
|
|
|
if ( $including ) {
|
|
|
|
|
$out2 = '';
|
|
|
|
|
} else {
|
2005-08-01 19:25:44 +00:00
|
|
|
$nsForm = $this->namespaceForm ( $namespace, $from );
|
2005-05-28 11:09:22 +00:00
|
|
|
$out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
|
|
|
|
|
$out2 .= '<tr valign="top"><td align="left">' . $nsForm;
|
|
|
|
|
$out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
|
|
|
|
|
$sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
|
|
|
|
|
wfMsg ( 'allpages' ) );
|
2005-08-01 19:25:44 +00:00
|
|
|
if ( ($n == $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
|
2005-05-28 11:09:22 +00:00
|
|
|
$namespaceparam = $namespace ? "&namespace=$namespace" : "";
|
|
|
|
|
$out2 .= " | " . $sk->makeKnownLink(
|
|
|
|
|
$wgContLang->specialPage( "Allpages" ),
|
|
|
|
|
wfMsg ( 'nextpage', $s->page_title ),
|
2005-07-18 22:15:05 +00:00
|
|
|
"from=" . wfUrlEncode ( $s->page_title ) . $namespaceparam );
|
2005-05-28 11:09:22 +00:00
|
|
|
}
|
|
|
|
|
$out2 .= "</td></tr></table><hr />";
|
2004-07-08 16:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$wgOut->addHtml( $out2 . $out );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2005-08-01 19:25:44 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
?>
|