3 * Implements Special:Prefixindex
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * Implements Special:Prefixindex
27 * @ingroup SpecialPage
29 class SpecialPrefixindex
extends SpecialAllpages
{
30 // Inherit $maxPerPage
32 function __construct() {
33 parent
::__construct( 'Prefixindex' );
37 * Entry point : initialise variables and call subfunctions.
38 * @param string $par becomes "FOO" when called like Special:Prefixindex/FOO (default null)
40 function execute( $par ) {
44 $this->outputHeader();
46 $out = $this->getOutput();
47 $out->addModuleStyles( 'mediawiki.special' );
50 $request = $this->getRequest();
51 $from = $request->getVal( 'from', '' );
52 $prefix = $request->getVal( 'prefix', '' );
53 $ns = $request->getIntOrNull( 'namespace' );
54 $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN).
55 $hideredirects = $request->getBool( 'hideredirects', false );
57 $namespaces = $wgContLang->getNamespaces();
59 ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
60 ?
$this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
61 : $this->msg( 'prefixindex' )
65 if ( isset( $par ) ) {
67 } elseif ( $prefix != '' ) {
69 } elseif ( $from != '' && $ns === null ) {
70 // For back-compat with Special:Allpages
71 // Don't do this if namespace is passed, so paging works when doing NS views.
75 // Bug 27864: if transcluded, show all pages instead of the form.
76 if ( $this->including() ||
$showme != '' ||
$ns !== null ) {
77 $this->showPrefixChunk( $namespace, $showme, $from, $hideredirects );
79 $out->addHTML( $this->namespacePrefixForm( $namespace, null, $hideredirects ) );
84 * HTML for the top form
85 * @param $namespace Integer: a namespace constant (default NS_MAIN).
86 * @param string $from dbKey we are starting listing at.
87 * @param bool $hideredirects hide redirects (default FALSE)
90 function namespacePrefixForm( $namespace = NS_MAIN
, $from = '', $hideredirects = false ) {
93 $out = Xml
::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
94 $out .= Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
95 $out .= Html
::hidden( 'title', $this->getTitle()->getPrefixedText() );
96 $out .= Xml
::openElement( 'fieldset' );
97 $out .= Xml
::element( 'legend', null, $this->msg( 'allpages' )->text() );
98 $out .= Xml
::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
100 <td class='mw-label'>" .
101 Xml
::label( $this->msg( 'allpagesprefix' )->text(), 'nsfrom' ) .
103 <td class='mw-input'>" .
104 Xml
::input( 'prefix', 30, str_replace( '_', ' ', $from ), array( 'id' => 'nsfrom' ) ) .
108 <td class='mw-label'>" .
109 Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' ) .
111 <td class='mw-input'>" .
112 Html
::namespaceSelector( array(
113 'selected' => $namespace,
115 'name' => 'namespace',
117 'class' => 'namespaceselector',
120 $this->msg( 'allpages-hide-redirects' )->text(),
125 Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) .
128 $out .= Xml
::closeElement( 'table' );
129 $out .= Xml
::closeElement( 'fieldset' );
130 $out .= Xml
::closeElement( 'form' );
131 $out .= Xml
::closeElement( 'div' );
136 * @param $namespace Integer, default NS_MAIN
137 * @param $prefix String
138 * @param string $from list all pages from this name (default FALSE)
139 * @param bool $hideredirects hide redirects (default FALSE)
141 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $from = null, $hideredirects = false ) {
144 if ( $from === null ) {
148 $fromList = $this->getNamespaceKeyAndText( $namespace, $from );
149 $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
150 $namespaces = $wgContLang->getNamespaces();
152 if ( !$prefixList ||
!$fromList ) {
153 $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock();
154 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
155 // Show errormessage and reset to NS_MAIN
156 $out = $this->msg( 'allpages-bad-ns', $namespace )->parse();
157 $namespace = NS_MAIN
;
159 list( $namespace, $prefixKey, $prefix ) = $prefixList;
160 list( /* $fromNS */, $fromKey, ) = $fromList;
162 ### @todo FIXME: Should complain if $fromNs != $namespace
164 $dbr = wfGetDB( DB_SLAVE
);
167 'page_namespace' => $namespace,
168 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
169 'page_title >= ' . $dbr->addQuotes( $fromKey ),
172 if ( $hideredirects ) {
173 $conds['page_is_redirect'] = 0;
176 $res = $dbr->select( 'page',
177 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
181 'ORDER BY' => 'page_title',
182 'LIMIT' => $this->maxPerPage +
1,
183 'USE INDEX' => 'name_title',
187 ### @todo FIXME: Side link to previous
190 if ( $res->numRows() > 0 ) {
191 $out = Xml
::openElement( 'table', array( 'id' => 'mw-prefixindex-list-table' ) );
193 while ( ( $n < $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
194 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
196 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
199 htmlspecialchars( $t->getText() ),
200 $s->page_is_redirect ?
array( 'class' => 'mw-redirect' ) : array()
202 ($s->page_is_redirect ?
'</div>' : '' );
204 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
209 $out .= "<td>$link</td>";
215 if ( ($n %
3) != 0 ) {
218 $out .= Xml
::closeElement( 'table' );
225 if ( $this->including() ) {
228 $nsForm = $this->namespacePrefixForm( $namespace, $prefix, $hideredirects );
229 $self = $this->getTitle();
230 $out2 = Xml
::openElement( 'table', array( 'id' => 'mw-prefixindex-nav-table' ) ) .
235 <td id="mw-prefixindex-nav-form" class="mw-prefixindex-nav">';
237 if ( isset( $res ) && $res && ( $n == $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
239 'from' => $s->page_title
,
241 'hideredirects' => $hideredirects,
244 if ( $namespace ||
$prefix == '' ) {
245 // Keep the namespace even if it's 0 for empty prefixes.
246 // This tells us we're not just a holdover from old links.
247 $query['namespace'] = $namespace;
249 $nextLink = Linker
::linkKnown(
251 $this->msg( 'nextpage', str_replace( '_', ' ', $s->page_title
) )->escaped(),
257 $footer = "\n" . Html
::element( "hr" )
258 . Html
::rawElement( "div", array( "class" => "mw-prefixindex-nav" ), $nextLink );
260 $out2 .= "</td></tr>" .
261 Xml
::closeElement( 'table' );
264 $this->getOutput()->addHTML( $out2 . $out . $footer );
267 protected function getGroupName() {