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
|
|
|
*/
|
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
|
|
|
*/
|
2005-08-10 21:14:38 +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;
|
|
|
|
|
|
2014-02-03 20:00:53 +00:00
|
|
|
// number of columns in output table
|
|
|
|
|
protected $columns = 3;
|
|
|
|
|
|
2007-12-24 17:08:05 +00:00
|
|
|
// Inherit $maxPerPage
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2013-01-26 18:15:35 +00:00
|
|
|
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
|
|
|
*/
|
|
|
|
|
function execute( $par ) {
|
2011-08-04 15:48:36 +00:00
|
|
|
global $wgContLang;
|
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 );
|
2014-02-03 20:00:53 +00:00
|
|
|
$this->columns = $request->getInt( 'columns', $this->columns );
|
2008-08-23 20:32:46 +00:00
|
|
|
|
2011-06-24 19:22:50 +00:00
|
|
|
$namespaces = $wgContLang->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 = '';
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( isset( $par ) ) {
|
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
|
|
|
|
|
|
|
|
// Bug 27864: if transcluded, show all pages instead of the form.
|
|
|
|
|
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 = '' ) {
|
2008-08-15 19:02:48 +00:00
|
|
|
global $wgScript;
|
|
|
|
|
|
2013-03-07 16:50:43 +00:00
|
|
|
$out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
|
2008-08-15 19:02:48 +00:00
|
|
|
$out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
|
2013-12-24 08:07:04 +00:00
|
|
|
$out .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
|
2008-08-15 19:02:48 +00:00
|
|
|
$out .= Xml::openElement( 'fieldset' );
|
2012-04-11 19:47:48 +00:00
|
|
|
$out .= Xml::element( 'legend', null, $this->msg( 'allpages' )->text() );
|
2008-08-15 19:02:48 +00:00
|
|
|
$out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
|
|
|
|
|
$out .= "<tr>
|
|
|
|
|
<td class='mw-label'>" .
|
2013-05-09 14:51:30 +00:00
|
|
|
Xml::label( $this->msg( 'allpagesprefix' )->text(), 'nsfrom' ) .
|
|
|
|
|
"</td>
|
2008-08-15 19:02:48 +00:00
|
|
|
<td class='mw-input'>" .
|
2013-05-09 14:51:30 +00:00
|
|
|
Xml::input( 'prefix', 30, str_replace( '_', ' ', $from ), array( 'id' => 'nsfrom' ) ) .
|
|
|
|
|
"</td>
|
2008-08-15 19:02:48 +00:00
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2013-05-09 14:51:30 +00:00
|
|
|
<td class='mw-label'>" .
|
|
|
|
|
Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) .
|
|
|
|
|
"</td>
|
2008-08-15 19:02:48 +00:00
|
|
|
<td class='mw-input'>" .
|
2013-05-09 14:51:30 +00:00
|
|
|
Html::namespaceSelector( array(
|
|
|
|
|
'selected' => $namespace,
|
|
|
|
|
), array(
|
|
|
|
|
'name' => 'namespace',
|
|
|
|
|
'id' => 'namespace',
|
|
|
|
|
'class' => 'namespaceselector',
|
|
|
|
|
) ) .
|
|
|
|
|
Xml::checkLabel(
|
|
|
|
|
$this->msg( 'allpages-hide-redirects' )->text(),
|
|
|
|
|
'hideredirects',
|
|
|
|
|
'hideredirects',
|
2013-07-24 10:08:52 +00:00
|
|
|
$this->hideRedirects
|
2013-05-09 14:51:30 +00:00
|
|
|
) . ' ' .
|
2013-07-03 19:49:29 +00:00
|
|
|
Xml::checkLabel(
|
|
|
|
|
$this->msg( 'prefixindex-strip' )->text(),
|
|
|
|
|
'stripprefix',
|
|
|
|
|
'stripprefix',
|
|
|
|
|
$this->stripPrefix
|
|
|
|
|
) . ' ' .
|
2013-05-09 14:51:30 +00:00
|
|
|
Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) .
|
|
|
|
|
"</td>
|
2012-03-28 20:28:31 +00:00
|
|
|
</tr>";
|
2008-08-15 19:02:48 +00:00
|
|
|
$out .= Xml::closeElement( 'table' );
|
|
|
|
|
$out .= Xml::closeElement( 'fieldset' );
|
|
|
|
|
$out .= Xml::closeElement( 'form' );
|
|
|
|
|
$out .= Xml::closeElement( 'div' );
|
2013-05-09 14:51:30 +00:00
|
|
|
|
2008-08-15 19:02:48 +00:00
|
|
|
return $out;
|
|
|
|
|
}
|
2005-08-10 21:14:38 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
/**
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param int $namespace Default NS_MAIN
|
|
|
|
|
* @param string $prefix
|
2014-04-23 11:39:49 +00:00
|
|
|
* @param string $from List all pages from this name (default false)
|
2008-04-14 07:45:50 +00:00
|
|
|
*/
|
2013-07-24 10:08:52 +00:00
|
|
|
protected function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) {
|
2011-08-04 15:48:36 +00:00
|
|
|
global $wgContLang;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
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 );
|
2008-04-14 07:45:50 +00:00
|
|
|
$namespaces = $wgContLang->getNamespaces();
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-05-17 22:03:20 +00:00
|
|
|
### @todo FIXME: Should complain if $fromNs != $namespace
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
|
2012-03-28 20:28:31 +00:00
|
|
|
$conds = array(
|
|
|
|
|
'page_namespace' => $namespace,
|
|
|
|
|
'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
|
|
|
|
|
'page_title >= ' . $dbr->addQuotes( $fromKey ),
|
|
|
|
|
);
|
|
|
|
|
|
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',
|
|
|
|
|
array( 'page_namespace', 'page_title', 'page_is_redirect' ),
|
2012-03-28 20:28:31 +00:00
|
|
|
$conds,
|
2008-08-23 20:32:46 +00:00
|
|
|
__METHOD__,
|
2008-04-14 07:45:50 +00:00
|
|
|
array(
|
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',
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2011-05-17 22:03:20 +00:00
|
|
|
### @todo FIXME: Side link to previous
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
|
|
|
$n = 0;
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $res->numRows() > 0 ) {
|
2013-12-07 02:57:16 +00:00
|
|
|
$out = Xml::openElement( 'table', array( 'class' => 'mw-prefixindex-list-table' ) );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2013-07-03 19:49:29 +00:00
|
|
|
$prefixLength = strlen( $prefix );
|
2013-04-19 20:55:47 +00:00
|
|
|
while ( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
|
2008-05-01 22:07:24 +00:00
|
|
|
$t = Title::makeTitle( $s->page_namespace, $s->page_title );
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $t ) {
|
2013-07-03 19:49:29 +00:00
|
|
|
$displayed = $t->getText();
|
2013-08-30 19:39:57 +00:00
|
|
|
// Try not to generate unclickable links
|
|
|
|
|
if ( $this->stripPrefix && $prefixLength !== strlen( $displayed ) ) {
|
2013-07-03 19:49:29 +00:00
|
|
|
$displayed = substr( $displayed, $prefixLength );
|
|
|
|
|
}
|
2013-04-27 12:02:08 +00:00
|
|
|
$link = ( $s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
|
2011-08-04 15:48:36 +00:00
|
|
|
Linker::linkKnown(
|
2009-06-07 18:45:52 +00:00
|
|
|
$t,
|
2013-07-03 19:49:29 +00:00
|
|
|
htmlspecialchars( $displayed ),
|
2012-06-11 00:29:41 +00:00
|
|
|
$s->page_is_redirect ? array( 'class' => 'mw-redirect' ) : array()
|
2009-06-07 18:45:52 +00:00
|
|
|
) .
|
2013-04-27 12:02:08 +00:00
|
|
|
( $s->page_is_redirect ? '</div>' : '' );
|
2008-05-01 22:07:24 +00:00
|
|
|
} else {
|
|
|
|
|
$link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
|
|
|
|
|
}
|
2014-02-03 20:00:53 +00:00
|
|
|
if ( $n % $this->columns == 0 ) {
|
2008-05-01 22:07:24 +00:00
|
|
|
$out .= '<tr>';
|
|
|
|
|
}
|
|
|
|
|
$out .= "<td>$link</td>";
|
|
|
|
|
$n++;
|
2014-02-03 20:00:53 +00:00
|
|
|
if ( $n % $this->columns == 0 ) {
|
2008-05-01 22:07:24 +00:00
|
|
|
$out .= '</tr>';
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2013-05-09 14:51:30 +00:00
|
|
|
|
2014-02-03 20:00:53 +00:00
|
|
|
if ( $n % $this->columns != 0 ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
$out .= '</tr>';
|
|
|
|
|
}
|
2013-05-09 14:51:30 +00:00
|
|
|
|
2009-02-15 21:25:06 +00:00
|
|
|
$out .= Xml::closeElement( 'table' );
|
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
|
|
|
|
2011-09-18 04:25:40 +00:00
|
|
|
$footer = '';
|
2008-08-23 20:32:46 +00:00
|
|
|
if ( $this->including() ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
$out2 = '';
|
|
|
|
|
} else {
|
2013-07-24 10:08:52 +00:00
|
|
|
$nsForm = $this->namespacePrefixForm( $namespace, $prefix );
|
2013-12-24 08:07:04 +00:00
|
|
|
$self = $this->getPageTitle();
|
2013-01-28 21:11:10 +00:00
|
|
|
$out2 = Xml::openElement( 'table', array( 'id' => 'mw-prefixindex-nav-table' ) ) .
|
2009-02-15 21:25:06 +00:00
|
|
|
'<tr>
|
|
|
|
|
<td>' .
|
2013-05-09 14:51:30 +00:00
|
|
|
$nsForm .
|
|
|
|
|
'</td>
|
|
|
|
|
<td id="mw-prefixindex-nav-form" class="mw-prefixindex-nav">';
|
2009-02-15 21:25:06 +00:00
|
|
|
|
2013-05-09 14:51:30 +00:00
|
|
|
if ( isset( $res ) && $res && ( $n == $this->maxPerPage ) &&
|
|
|
|
|
( $s = $res->fetchObject() )
|
|
|
|
|
) {
|
2009-06-07 18:45:52 +00:00
|
|
|
$query = array(
|
|
|
|
|
'from' => $s->page_title,
|
2012-03-28 20:28:31 +00:00
|
|
|
'prefix' => $prefix,
|
2013-07-24 10:08:52 +00:00
|
|
|
'hideredirects' => $this->hideRedirects,
|
2014-01-29 12:21:45 +00:00
|
|
|
'stripprefix' => $this->stripPrefix,
|
2014-02-03 20:00:53 +00:00
|
|
|
'columns' => $this->columns,
|
2009-06-07 18:45:52 +00:00
|
|
|
);
|
|
|
|
|
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $namespace || $prefix == '' ) {
|
2011-11-30 22:38:39 +00:00
|
|
|
// Keep the namespace even if it's 0 for empty prefixes.
|
|
|
|
|
// This tells us we're not just a holdover from old links.
|
2009-06-07 18:45:52 +00:00
|
|
|
$query['namespace'] = $namespace;
|
|
|
|
|
}
|
2013-05-09 14:51:30 +00:00
|
|
|
|
2011-09-18 04:25:40 +00:00
|
|
|
$nextLink = Linker::linkKnown(
|
2013-05-09 14:51:30 +00:00
|
|
|
$self,
|
|
|
|
|
$this->msg( 'nextpage', str_replace( '_', ' ', $s->page_title ) )->escaped(),
|
|
|
|
|
array(),
|
|
|
|
|
$query
|
|
|
|
|
);
|
|
|
|
|
|
2011-09-18 04:25:40 +00:00
|
|
|
$out2 .= $nextLink;
|
|
|
|
|
|
2013-05-09 14:51:30 +00:00
|
|
|
$footer = "\n" . Html::element( 'hr' ) .
|
|
|
|
|
Html::rawElement(
|
|
|
|
|
'div',
|
|
|
|
|
array( 'class' => 'mw-prefixindex-nav' ),
|
|
|
|
|
$nextLink
|
|
|
|
|
);
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2009-02-15 21:25:06 +00:00
|
|
|
$out2 .= "</td></tr>" .
|
|
|
|
|
Xml::closeElement( 'table' );
|
2005-08-10 21:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-18 04:25:40 +00:00
|
|
|
$this->getOutput()->addHTML( $out2 . $out . $footer );
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2013-03-07 20:15:54 +00:00
|
|
|
|
|
|
|
|
protected function getGroupName() {
|
|
|
|
|
return 'pages';
|
|
|
|
|
}
|
2005-08-10 21:14:38 +00:00
|
|
|
}
|