2005-08-10 21:14:38 +00:00
|
|
|
<?php
|
2010-06-21 12:59:04 +00:00
|
|
|
/**
|
2010-08-15 07:16:58 +00:00
|
|
|
* Implements Special:Prefixindex
|
2010-06-21 12:59:04 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:16:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-06-21 12:59:04 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-15 07:16:58 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup SpecialPage
|
2010-06-21 12:59:04 +00:00
|
|
|
*/
|
2016-05-20 01:58:12 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2005-08-10 21:14:38 +00:00
|
|
|
|
2007-04-20 08:55:14 +00:00
|
|
|
/**
|
2010-08-15 07:16:58 +00:00
|
|
|
* Implements Special:Prefixindex
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup SpecialPage
|
2007-04-20 08:55:14 +00:00
|
|
|
*/
|
2014-06-16 17:36:04 +00:00
|
|
|
class SpecialPrefixindex extends SpecialAllPages {
|
2013-07-03 19:49:29 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether to remove the searched prefix from the displayed link. Useful
|
|
|
|
|
* for inclusion of a set of sub pages in a root page.
|
|
|
|
|
*/
|
|
|
|
|
protected $stripPrefix = false;
|
|
|
|
|
|
2013-07-24 10:08:52 +00:00
|
|
|
protected $hideRedirects = false;
|
|
|
|
|
|
2007-12-24 17:08:05 +00:00
|
|
|
// Inherit $maxPerPage
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2020-05-18 00:17:37 +00:00
|
|
|
public function __construct() {
|
2008-09-28 09:31:24 +00:00
|
|
|
parent::__construct( 'Prefixindex' );
|
2008-08-23 20:32:46 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2008-08-23 20:32:46 +00:00
|
|
|
/**
|
|
|
|
|
* Entry point : initialise variables and call subfunctions.
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param string $par Becomes "FOO" when called like Special:Prefixindex/FOO (default null)
|
2008-08-23 20:32:46 +00:00
|
|
|
*/
|
2020-05-18 00:17:37 +00:00
|
|
|
public function execute( $par ) {
|
2008-08-23 20:32:46 +00:00
|
|
|
$this->setHeaders();
|
|
|
|
|
$this->outputHeader();
|
2011-08-04 15:48:36 +00:00
|
|
|
|
|
|
|
|
$out = $this->getOutput();
|
|
|
|
|
$out->addModuleStyles( 'mediawiki.special' );
|
2008-08-23 20:32:46 +00:00
|
|
|
|
|
|
|
|
# GET values
|
2011-08-04 15:48:36 +00:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
$from = $request->getVal( 'from', '' );
|
|
|
|
|
$prefix = $request->getVal( 'prefix', '' );
|
|
|
|
|
$ns = $request->getIntOrNull( 'namespace' );
|
2011-06-24 19:22:50 +00:00
|
|
|
$namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN).
|
2013-07-24 10:08:52 +00:00
|
|
|
$this->hideRedirects = $request->getBool( 'hideredirects', $this->hideRedirects );
|
2013-07-03 19:49:29 +00:00
|
|
|
$this->stripPrefix = $request->getBool( 'stripprefix', $this->stripPrefix );
|
2008-08-23 20:32:46 +00:00
|
|
|
|
2018-07-29 12:24:54 +00:00
|
|
|
$namespaces = MediaWikiServices::getInstance()->getContentLanguage()->getNamespaces();
|
2011-10-27 20:23:16 +00:00
|
|
|
$out->setPageTitle(
|
2014-04-01 21:44:03 +00:00
|
|
|
( $namespace > 0 && array_key_exists( $namespace, $namespaces ) )
|
2011-12-20 07:55:44 +00:00
|
|
|
? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
|
2011-10-27 20:23:16 +00:00
|
|
|
: $this->msg( 'prefixindex' )
|
2008-08-23 20:32:46 +00:00
|
|
|
);
|
|
|
|
|
|
2011-01-07 23:52:19 +00:00
|
|
|
$showme = '';
|
2014-05-24 05:45:33 +00:00
|
|
|
if ( $par !== null ) {
|
2011-01-07 23:52:19 +00:00
|
|
|
$showme = $par;
|
2013-04-19 20:55:47 +00:00
|
|
|
} elseif ( $prefix != '' ) {
|
2011-01-07 23:52:19 +00:00
|
|
|
$showme = $prefix;
|
2013-04-19 20:55:47 +00:00
|
|
|
} elseif ( $from != '' && $ns === null ) {
|
2011-01-07 23:52:19 +00:00
|
|
|
// For back-compat with Special:Allpages
|
2011-11-30 22:38:39 +00:00
|
|
|
// Don't do this if namespace is passed, so paging works when doing NS views.
|
2011-01-07 23:52:19 +00:00
|
|
|
$showme = $from;
|
|
|
|
|
}
|
2011-06-24 19:22:50 +00:00
|
|
|
|
2017-02-20 22:31:04 +00:00
|
|
|
// T29864: if transcluded, show all pages instead of the form.
|
2011-06-24 19:22:50 +00:00
|
|
|
if ( $this->including() || $showme != '' || $ns !== null ) {
|
2013-07-24 10:08:52 +00:00
|
|
|
$this->showPrefixChunk( $namespace, $showme, $from );
|
2008-08-23 20:32:46 +00:00
|
|
|
} else {
|
2013-07-24 10:08:52 +00:00
|
|
|
$out->addHTML( $this->namespacePrefixForm( $namespace, null ) );
|
2008-08-23 20:32:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2008-08-15 19:02:48 +00:00
|
|
|
/**
|
2012-03-28 20:28:31 +00:00
|
|
|
* HTML for the top form
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param int $namespace A namespace constant (default NS_MAIN).
|
|
|
|
|
* @param string $from DbKey we are starting listing at.
|
2012-02-09 21:36:14 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2013-07-24 10:08:52 +00:00
|
|
|
protected function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) {
|
2018-04-16 04:33:44 +00:00
|
|
|
$formDescriptor = [
|
|
|
|
|
'prefix' => [
|
|
|
|
|
'label-message' => 'allpagesprefix',
|
|
|
|
|
'name' => 'prefix',
|
2018-05-05 23:19:08 +00:00
|
|
|
'id' => 'nsfrom',
|
2018-04-16 04:33:44 +00:00
|
|
|
'type' => 'text',
|
|
|
|
|
'size' => '30',
|
2018-05-05 23:19:08 +00:00
|
|
|
'default' => str_replace( '_', ' ', $from ),
|
2018-04-16 04:33:44 +00:00
|
|
|
],
|
|
|
|
|
'namespace' => [
|
|
|
|
|
'type' => 'namespaceselect',
|
2013-05-09 14:51:30 +00:00
|
|
|
'name' => 'namespace',
|
|
|
|
|
'id' => 'namespace',
|
2018-04-16 04:33:44 +00:00
|
|
|
'label-message' => 'namespace',
|
|
|
|
|
'all' => null,
|
2018-05-05 23:19:08 +00:00
|
|
|
'default' => $namespace,
|
2018-04-16 04:33:44 +00:00
|
|
|
],
|
|
|
|
|
'hidedirects' => [
|
|
|
|
|
'class' => 'HTMLCheckField',
|
|
|
|
|
'name' => 'hideredirects',
|
|
|
|
|
'label-message' => 'allpages-hide-redirects',
|
|
|
|
|
],
|
|
|
|
|
'stripprefix' => [
|
|
|
|
|
'class' => 'HTMLCheckField',
|
|
|
|
|
'name' => 'stripprefix',
|
|
|
|
|
'label-message' => 'prefixindex-strip',
|
|
|
|
|
],
|
|
|
|
|
];
|
2018-05-05 23:19:08 +00:00
|
|
|
$context = new DerivativeContext( $this->getContext() );
|
|
|
|
|
$context->setTitle( $this->getPageTitle() ); // Remove subpage
|
2018-04-21 13:24:16 +00:00
|
|
|
$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $context );
|
2018-04-16 04:33:44 +00:00
|
|
|
$htmlForm
|
|
|
|
|
->setMethod( 'get' )
|
2018-04-22 02:13:22 +00:00
|
|
|
->setWrapperLegendMsg( 'prefixindex' )
|
2018-04-16 04:33:44 +00:00
|
|
|
->setSubmitTextMsg( 'prefixindex-submit' );
|
|
|
|
|
|
|
|
|
|
return $htmlForm->prepareForm()->getHTML( false );
|
2008-08-15 19:02:48 +00:00
|
|
|
}
|
2005-08-10 21:14:38 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
/**
|
2018-06-08 21:42:27 +00:00
|
|
|
* @param int $namespace
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param string $prefix
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $from List all pages from this name (default false)
|
2008-04-14 07:45:50 +00:00
|
|
|
*/
|
2018-06-08 21:42:27 +00:00
|
|
|
protected function showPrefixChunk( $namespace, $prefix, $from = null ) {
|
2011-08-04 15:48:36 +00:00
|
|
|
if ( $from === null ) {
|
|
|
|
|
$from = $prefix;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2013-01-28 21:11:10 +00:00
|
|
|
$fromList = $this->getNamespaceKeyAndText( $namespace, $from );
|
|
|
|
|
$prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
|
2018-07-29 12:24:54 +00:00
|
|
|
$namespaces = MediaWikiServices::getInstance()->getContentLanguage()->getNamespaces();
|
2014-05-24 05:45:33 +00:00
|
|
|
$res = null;
|
2016-06-01 20:59:35 +00:00
|
|
|
$n = 0;
|
|
|
|
|
$nextRow = null;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
|
|
|
if ( !$prefixList || !$fromList ) {
|
2012-04-11 19:47:48 +00:00
|
|
|
$out = $this->msg( 'allpagesbadtitle' )->parseAsBlock();
|
2014-04-01 21:44:03 +00:00
|
|
|
} elseif ( !array_key_exists( $namespace, $namespaces ) ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
// Show errormessage and reset to NS_MAIN
|
2012-04-11 19:47:48 +00:00
|
|
|
$out = $this->msg( 'allpages-bad-ns', $namespace )->parse();
|
2008-04-14 07:45:50 +00:00
|
|
|
$namespace = NS_MAIN;
|
|
|
|
|
} else {
|
|
|
|
|
list( $namespace, $prefixKey, $prefix ) = $prefixList;
|
2010-11-29 00:41:56 +00:00
|
|
|
list( /* $fromNS */, $fromKey, ) = $fromList;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
# ## @todo FIXME: Should complain if $fromNs != $namespace
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2016-09-05 19:55:19 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$conds = [
|
2012-03-28 20:28:31 +00:00
|
|
|
'page_namespace' => $namespace,
|
|
|
|
|
'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
|
|
|
|
|
'page_title >= ' . $dbr->addQuotes( $fromKey ),
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-03-28 20:28:31 +00:00
|
|
|
|
2013-07-24 10:08:52 +00:00
|
|
|
if ( $this->hideRedirects ) {
|
2012-03-28 20:28:31 +00:00
|
|
|
$conds['page_is_redirect'] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
$res = $dbr->select( 'page',
|
2016-05-20 01:58:12 +00:00
|
|
|
array_merge(
|
|
|
|
|
[ 'page_namespace', 'page_title' ],
|
|
|
|
|
LinkCache::getSelectFields()
|
|
|
|
|
),
|
2012-03-28 20:28:31 +00:00
|
|
|
$conds,
|
2008-08-23 20:32:46 +00:00
|
|
|
__METHOD__,
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2013-04-19 20:55:47 +00:00
|
|
|
'ORDER BY' => 'page_title',
|
|
|
|
|
'LIMIT' => $this->maxPerPage + 1,
|
2008-04-14 07:45:50 +00:00
|
|
|
'USE INDEX' => 'name_title',
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2008-04-14 07:45:50 +00:00
|
|
|
);
|
|
|
|
|
|
2015-10-19 18:00:44 +00:00
|
|
|
// @todo FIXME: Side link to previous
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $res->numRows() > 0 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$out = Html::openElement( 'ul', [ 'class' => 'mw-prefixindex-list' ] );
|
2016-05-20 01:58:12 +00:00
|
|
|
$linkCache = MediaWikiServices::getInstance()->getLinkCache();
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2013-07-03 19:49:29 +00:00
|
|
|
$prefixLength = strlen( $prefix );
|
2016-05-20 01:58:12 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
if ( $n >= $this->maxPerPage ) {
|
2016-06-01 20:59:35 +00:00
|
|
|
$nextRow = $row;
|
2016-05-20 01:58:12 +00:00
|
|
|
break;
|
2008-05-01 22:07:24 +00:00
|
|
|
}
|
2016-05-20 01:58:12 +00:00
|
|
|
$title = Title::newFromRow( $row );
|
|
|
|
|
// Make sure it gets into LinkCache
|
|
|
|
|
$linkCache->addGoodLinkObjFromRow( $title, $row );
|
|
|
|
|
$displayed = $title->getText();
|
|
|
|
|
// Try not to generate unclickable links
|
|
|
|
|
if ( $this->stripPrefix && $prefixLength !== strlen( $displayed ) ) {
|
|
|
|
|
$displayed = substr( $displayed, $prefixLength );
|
|
|
|
|
}
|
|
|
|
|
$link = ( $title->isRedirect() ? '<div class="allpagesredirect">' : '' ) .
|
2016-12-02 15:43:12 +00:00
|
|
|
$this->getLinkRenderer()->makeKnownLink(
|
2016-05-20 01:58:12 +00:00
|
|
|
$title,
|
2016-12-02 15:43:12 +00:00
|
|
|
$displayed
|
2016-05-20 01:58:12 +00:00
|
|
|
) .
|
|
|
|
|
( $title->isRedirect() ? '</div>' : '' );
|
2015-10-17 17:02:49 +00:00
|
|
|
|
2015-11-09 16:50:53 +00:00
|
|
|
$out .= "<li>$link</li>\n";
|
2008-05-01 22:07:24 +00:00
|
|
|
$n++;
|
2013-05-09 14:51:30 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2015-10-17 17:02:49 +00:00
|
|
|
$out .= Html::closeElement( 'ul' );
|
2015-11-09 16:50:53 +00:00
|
|
|
|
|
|
|
|
if ( $res->numRows() > 2 ) {
|
|
|
|
|
// Only apply CSS column styles if there's more than 2 entries.
|
|
|
|
|
// Otherwise rendering is broken as "mw-prefixindex-body"'s CSS column count is 3.
|
2016-02-17 09:09:32 +00:00
|
|
|
$out = Html::rawElement( 'div', [ 'class' => 'mw-prefixindex-body' ], $out );
|
2015-11-09 16:50:53 +00:00
|
|
|
}
|
2008-05-01 22:07:24 +00:00
|
|
|
} else {
|
|
|
|
|
$out = '';
|
2006-07-02 14:39:47 +00:00
|
|
|
}
|
2005-08-10 21:14:38 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2015-10-19 18:00:44 +00:00
|
|
|
$output = $this->getOutput();
|
2009-06-07 18:45:52 +00:00
|
|
|
|
2015-10-19 18:00:44 +00:00
|
|
|
if ( $this->including() ) {
|
|
|
|
|
// We don't show the nav-links and the form when included into other
|
|
|
|
|
// pages so let's just finish here.
|
|
|
|
|
$output->addHTML( $out );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-05-09 14:51:30 +00:00
|
|
|
|
2015-10-19 18:00:44 +00:00
|
|
|
$topOut = $this->namespacePrefixForm( $namespace, $prefix );
|
2013-05-09 14:51:30 +00:00
|
|
|
|
2016-06-01 20:59:35 +00:00
|
|
|
if ( $res && ( $n == $this->maxPerPage ) && $nextRow ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$query = [
|
2016-06-01 20:59:35 +00:00
|
|
|
'from' => $nextRow->page_title,
|
2015-10-19 18:00:44 +00:00
|
|
|
'prefix' => $prefix,
|
|
|
|
|
'hideredirects' => $this->hideRedirects,
|
|
|
|
|
'stripprefix' => $this->stripPrefix,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-09-18 04:25:40 +00:00
|
|
|
|
2015-10-19 18:00:44 +00:00
|
|
|
if ( $namespace || $prefix == '' ) {
|
|
|
|
|
// Keep the namespace even if it's 0 for empty prefixes.
|
|
|
|
|
// This tells us we're not just a holdover from old links.
|
|
|
|
|
$query['namespace'] = $namespace;
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2015-10-19 18:00:44 +00:00
|
|
|
|
2016-12-02 15:43:12 +00:00
|
|
|
$nextLink = $this->getLinkRenderer()->makeKnownLink(
|
2015-10-19 18:00:44 +00:00
|
|
|
$this->getPageTitle(),
|
2016-12-02 15:43:12 +00:00
|
|
|
$this->msg( 'nextpage', str_replace( '_', ' ', $nextRow->page_title ) )->text(),
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
2015-10-19 18:00:44 +00:00
|
|
|
$query
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Link shown at the top of the page below the form
|
|
|
|
|
$topOut .= Html::rawElement( 'div',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => 'mw-prefixindex-nav' ],
|
2015-10-19 18:00:44 +00:00
|
|
|
$nextLink
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Link shown at the footer
|
|
|
|
|
$out .= "\n" . Html::element( 'hr' ) .
|
|
|
|
|
Html::rawElement(
|
|
|
|
|
'div',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => 'mw-prefixindex-nav' ],
|
2015-10-19 18:00:44 +00:00
|
|
|
$nextLink
|
|
|
|
|
);
|
|
|
|
|
|
2005-08-10 21:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-19 18:00:44 +00:00
|
|
|
$output->addHTML( $topOut . $out );
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2013-03-07 20:15:54 +00:00
|
|
|
|
2015-12-06 15:06:01 +00:00
|
|
|
/**
|
|
|
|
|
* Return an array of subpages beginning with $search that this special page will accept.
|
|
|
|
|
*
|
|
|
|
|
* @param string $search Prefix to search for
|
|
|
|
|
* @param int $limit Maximum number of results to return (usually 10)
|
|
|
|
|
* @param int $offset Number of results to skip (usually 0)
|
|
|
|
|
* @return string[] Matching subpages
|
|
|
|
|
*/
|
|
|
|
|
public function prefixSearchSubpages( $search, $limit, $offset ) {
|
2016-01-26 21:18:27 +00:00
|
|
|
return $this->prefixSearchString( $search, $limit, $offset );
|
2015-12-06 15:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-07 20:15:54 +00:00
|
|
|
protected function getGroupName() {
|
|
|
|
|
return 'pages';
|
|
|
|
|
}
|
2005-08-10 21:14:38 +00:00
|
|
|
}
|