Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save whym/3337993 to your computer and use it in GitHub Desktop.

Select an option

Save whym/3337993 to your computer and use it in GitHub Desktop.
diff --git a/includes/specials/SpecialAllpages.php b/includes/specials/SpecialAllpages.php
index 0f8b255..42dd40e 100644
--- a/includes/specials/SpecialAllpages.php
+++ b/includes/specials/SpecialAllpages.php
@@ -84,6 +84,7 @@ class SpecialAllpages extends IncludableSpecialPage {
$to = $request->getVal( 'to', null );
$namespace = $request->getInt( 'namespace' );
$hideredirects = $request->getBool( 'hideredirects', false );
+ $usesortkey = $request->getBool( 'usesortkey', false );
$namespaces = $wgContLang->getNamespaces();
@@ -95,11 +96,11 @@ class SpecialAllpages extends IncludableSpecialPage {
$out->addModuleStyles( 'mediawiki.special' );
if( $par !== null ) {
- $this->showChunk( $namespace, $par, $to, $hideredirects );
+ $this->showChunk( $namespace, $par, $to, $hideredirects, $usesortkey );
} elseif( $from !== null && $to === null ) {
- $this->showChunk( $namespace, $from, $to, $hideredirects );
+ $this->showChunk( $namespace, $from, $to, $hideredirects, $usesortkey );
} else {
- $this->showToplevel( $namespace, $from, $to, $hideredirects );
+ $this->showToplevel( $namespace, $from, $to, $hideredirects, $usesortkey );
}
}
@@ -112,7 +113,7 @@ class SpecialAllpages extends IncludableSpecialPage {
* @param $hideredirects Bool: dont show redirects (default FALSE)
* @return string
*/
- function namespaceForm( $namespace = NS_MAIN, $from = '', $to = '', $hideredirects = false ) {
+ function namespaceForm( $namespace = NS_MAIN, $from = '', $to = '', $hideredirects = false, $usesortkey = false ) {
global $wgScript;
$t = $this->getTitle();
@@ -153,6 +154,12 @@ class SpecialAllpages extends IncludableSpecialPage {
'hideredirects',
$hideredirects
) . ' ' .
+ Xml::checkLabel(
+ $this->msg( 'allpages-use-sortkey' )->text(),
+ 'usesortkey',
+ 'usesortkey',
+ $usesortkey
+ ) . ' ' .
Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) .
" </td>
</tr>";
@@ -169,7 +176,7 @@ class SpecialAllpages extends IncludableSpecialPage {
* @param $to String: list all pages to this name
* @param $hideredirects Bool: dont show redirects (default FALSE)
*/
- function showToplevel( $namespace = NS_MAIN, $from = '', $to = '', $hideredirects = false ) {
+ function showToplevel( $namespace = NS_MAIN, $from = '', $to = '', $hideredirects = false, $usesortkey = false ) {
$output = $this->getOutput();
# TODO: Either make this *much* faster or cache the title index points
@@ -251,9 +258,9 @@ class SpecialAllpages extends IncludableSpecialPage {
// Instead, display the first section directly.
if( count( $lines ) <= 2 ) {
if( !empty($lines) ) {
- $this->showChunk( $namespace, $from, $to, $hideredirects );
+ $this->showChunk( $namespace, $from, $to, $hideredirects, $usesortkey );
} else {
- $output->addHTML( $this->namespaceForm( $namespace, $from, $to, $hideredirects ) );
+ $output->addHTML( $this->namespaceForm( $namespace, $from, $to, $hideredirects, $usesortkey ) );
}
return;
}
@@ -263,10 +270,10 @@ class SpecialAllpages extends IncludableSpecialPage {
while( count ( $lines ) > 0 ) {
$inpoint = array_shift( $lines );
$outpoint = array_shift( $lines );
- $out .= $this->showline( $inpoint, $outpoint, $namespace, $hideredirects );
+ $out .= $this->showline( $inpoint, $outpoint, $namespace, $hideredirects, $usesortkey );
}
$out .= Xml::closeElement( 'table' );
- $nsForm = $this->namespaceForm( $namespace, $from, $to, $hideredirects );
+ $nsForm = $this->namespaceForm( $namespace, $from, $to, $hideredirects, $usesortkey );
# Is there more?
if( $this->including() ) {
@@ -300,7 +307,7 @@ class SpecialAllpages extends IncludableSpecialPage {
* @param $hideredirects Bool: dont show redirects (default FALSE)
* @return string
*/
- function showline( $inpoint, $outpoint, $namespace = NS_MAIN, $hideredirects ) {
+ function showline( $inpoint, $outpoint, $namespace = NS_MAIN, $hideredirects, $usesortkey ) {
global $wgContLang;
$inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
$outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
@@ -331,7 +338,7 @@ class SpecialAllpages extends IncludableSpecialPage {
* @param $to String: list all pages to this name (default FALSE)
* @param $hideredirects Bool: dont show redirects (default FALSE)
*/
- function showChunk( $namespace = NS_MAIN, $from = false, $to = false, $hideredirects = false ) {
+ function showChunk( $namespace = NS_MAIN, $from = false, $to = false, $hideredirects = false, $usesortkey = false ) {
global $wgContLang;
$output = $this->getOutput();
@@ -351,28 +358,52 @@ class SpecialAllpages extends IncludableSpecialPage {
list( , $toKey, $to ) = $toList;
$dbr = wfGetDB( DB_SLAVE );
+ $tables = 'page';
$conds = array(
'page_namespace' => $namespace,
'page_title >= ' . $dbr->addQuotes( $fromKey )
);
-
+ $joinConds = array();
+ if ( $usesortkey ) {
+ $tables = array('page', 'categorylinks');
+ $conds = array(
+ 'page_namespace' => $namespace,
+ 'cl_sortkey >= ' . $dbr->addQuotes( $fromKey )
+ );
+ $joinConds = array(
+ 'categorylinks' => array( 'JOIN', array(
+ 'cl_from = page_id'
+ )));
+ }
if ( $hideredirects ) {
$conds[ 'page_is_redirect' ] = 0;
}
if( $toKey !== "" ) {
- $conds[] = 'page_title <= ' . $dbr->addQuotes( $toKey );
+ if ( $usesortkey ) {
+ $conds[] = 'cl_sortkey <= ' . $dbr->addQuotes( $toKey );
+ } else {
+ $conds[] = 'page_title <= ' . $dbr->addQuotes( $toKey );
+ }
}
- $res = $dbr->select( 'page',
+ $conds2 = $usesortkey ? array(
+ 'ORDER BY' => 'cl_sortkey',
+ 'LIMIT' => $this->maxPerPage + 1,
+ 'GROUP BY' => 'cl_sortkey',
+ 'USE INDEX' => array('categorylinks' => 'cl_sortkey')
+ ) : array(
+ 'ORDER BY' => 'page_title',
+ 'LIMIT' => $this->maxPerPage + 1,
+ 'USE INDEX' => array('page' => 'name_title')
+ );
+
+ $res = $dbr->select( $tables,
array( 'page_namespace', 'page_title', 'page_is_redirect', 'page_id' ),
$conds,
__METHOD__,
- array(
- 'ORDER BY' => 'page_title',
- 'LIMIT' => $this->maxPerPage + 1,
- 'USE INDEX' => 'name_title',
- )
+ $conds2,
+ $joinConds
);
if( $res->numRows() > 0 ) {
@@ -447,7 +478,7 @@ class SpecialAllpages extends IncludableSpecialPage {
$self = $this->getTitle();
- $nsForm = $this->namespaceForm( $namespace, $from, $to, $hideredirects );
+ $nsForm = $this->namespaceForm( $namespace, $from, $to, $hideredirects, $usesortkey );
$out2 = Xml::openElement( 'table', array( 'class' => 'mw-allpages-table-form' ) ).
'<tr>
<td>' .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment