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' );
137 * @param $namespace Integer, default NS_MAIN
138 * @param $prefix String
139 * @param string $from list all pages from this name (default FALSE)
140 * @param bool $hideredirects hide redirects (default FALSE)
142 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $from = null, $hideredirects = false ) {
145 if ( $from === null ) {
149 $fromList = $this->getNamespaceKeyAndText( $namespace, $from );
150 $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
151 $namespaces = $wgContLang->getNamespaces();
153 if ( !$prefixList ||
!$fromList ) {
154 $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock();
155 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
156 // Show errormessage and reset to NS_MAIN
157 $out = $this->msg( 'allpages-bad-ns', $namespace )->parse();
158 $namespace = NS_MAIN
;
160 list( $namespace, $prefixKey, $prefix ) = $prefixList;
161 list( /* $fromNS */, $fromKey, ) = $fromList;
163 ### @todo FIXME: Should complain if $fromNs != $namespace
165 $dbr = wfGetDB( DB_SLAVE
);
168 'page_namespace' => $namespace,
169 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
170 'page_title >= ' . $dbr->addQuotes( $fromKey ),
173 if ( $hideredirects ) {
174 $conds['page_is_redirect'] = 0;
177 $res = $dbr->select( 'page',
178 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
182 'ORDER BY' => 'page_title',
183 'LIMIT' => $this->maxPerPage +
1,
184 'USE INDEX' => 'name_title',
188 ### @todo FIXME: Side link to previous
191 if ( $res->numRows() > 0 ) {
192 $out = Xml
::openElement( 'table', array( 'id' => 'mw-prefixindex-list-table' ) );
194 while ( ( $n < $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
195 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
197 $link = ( $s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
200 htmlspecialchars( $t->getText() ),
201 $s->page_is_redirect ?
array( 'class' => 'mw-redirect' ) : array()
203 ( $s->page_is_redirect ?
'</div>' : '' );
205 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
210 $out .= "<td>$link</td>";
221 $out .= Xml
::closeElement( 'table' );
228 if ( $this->including() ) {
231 $nsForm = $this->namespacePrefixForm( $namespace, $prefix, $hideredirects );
232 $self = $this->getTitle();
233 $out2 = Xml
::openElement( 'table', array( 'id' => 'mw-prefixindex-nav-table' ) ) .
238 <td id="mw-prefixindex-nav-form" class="mw-prefixindex-nav">';
240 if ( isset( $res ) && $res && ( $n == $this->maxPerPage
) &&
241 ( $s = $res->fetchObject() )
244 'from' => $s->page_title
,
246 'hideredirects' => $hideredirects,
249 if ( $namespace ||
$prefix == '' ) {
250 // Keep the namespace even if it's 0 for empty prefixes.
251 // This tells us we're not just a holdover from old links.
252 $query['namespace'] = $namespace;
255 $nextLink = Linker
::linkKnown(
257 $this->msg( 'nextpage', str_replace( '_', ' ', $s->page_title
) )->escaped(),
264 $footer = "\n" . Html
::element( 'hr' ) .
267 array( 'class' => 'mw-prefixindex-nav' ),
271 $out2 .= "</td></tr>" .
272 Xml
::closeElement( 'table' );
275 $this->getOutput()->addHTML( $out2 . $out . $footer );
278 protected function getGroupName() {