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
{
32 * Whether to remove the searched prefix from the displayed link. Useful
33 * for inclusion of a set of sub pages in a root page.
35 protected $stripPrefix = false;
37 // Inherit $maxPerPage
39 function __construct() {
40 parent
::__construct( 'Prefixindex' );
44 * Entry point : initialise variables and call subfunctions.
45 * @param string $par becomes "FOO" when called like Special:Prefixindex/FOO (default null)
47 function execute( $par ) {
51 $this->outputHeader();
53 $out = $this->getOutput();
54 $out->addModuleStyles( 'mediawiki.special' );
57 $request = $this->getRequest();
58 $from = $request->getVal( 'from', '' );
59 $prefix = $request->getVal( 'prefix', '' );
60 $ns = $request->getIntOrNull( 'namespace' );
61 $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN).
62 $hideredirects = $request->getBool( 'hideredirects', false );
63 $this->stripPrefix
= $request->getBool( 'stripprefix', $this->stripPrefix
);
65 $namespaces = $wgContLang->getNamespaces();
67 ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
68 ?
$this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
69 : $this->msg( 'prefixindex' )
73 if ( isset( $par ) ) {
75 } elseif ( $prefix != '' ) {
77 } elseif ( $from != '' && $ns === null ) {
78 // For back-compat with Special:Allpages
79 // Don't do this if namespace is passed, so paging works when doing NS views.
83 // Bug 27864: if transcluded, show all pages instead of the form.
84 if ( $this->including() ||
$showme != '' ||
$ns !== null ) {
85 $this->showPrefixChunk( $namespace, $showme, $from, $hideredirects );
87 $out->addHTML( $this->namespacePrefixForm( $namespace, null, $hideredirects ) );
92 * HTML for the top form
93 * @param $namespace Integer: a namespace constant (default NS_MAIN).
94 * @param string $from dbKey we are starting listing at.
95 * @param bool $hideredirects hide redirects (default FALSE)
98 function namespacePrefixForm( $namespace = NS_MAIN
, $from = '', $hideredirects = false ) {
101 $out = Xml
::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
102 $out .= Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
103 $out .= Html
::hidden( 'title', $this->getTitle()->getPrefixedText() );
104 $out .= Xml
::openElement( 'fieldset' );
105 $out .= Xml
::element( 'legend', null, $this->msg( 'allpages' )->text() );
106 $out .= Xml
::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
108 <td class='mw-label'>" .
109 Xml
::label( $this->msg( 'allpagesprefix' )->text(), 'nsfrom' ) .
111 <td class='mw-input'>" .
112 Xml
::input( 'prefix', 30, str_replace( '_', ' ', $from ), array( 'id' => 'nsfrom' ) ) .
116 <td class='mw-label'>" .
117 Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' ) .
119 <td class='mw-input'>" .
120 Html
::namespaceSelector( array(
121 'selected' => $namespace,
123 'name' => 'namespace',
125 'class' => 'namespaceselector',
128 $this->msg( 'allpages-hide-redirects' )->text(),
134 $this->msg( 'prefixindex-strip' )->text(),
139 Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) .
142 $out .= Xml
::closeElement( 'table' );
143 $out .= Xml
::closeElement( 'fieldset' );
144 $out .= Xml
::closeElement( 'form' );
145 $out .= Xml
::closeElement( 'div' );
151 * @param $namespace Integer, default NS_MAIN
152 * @param $prefix String
153 * @param string $from list all pages from this name (default FALSE)
154 * @param bool $hideredirects hide redirects (default FALSE)
156 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $from = null, $hideredirects = false ) {
159 if ( $from === null ) {
163 $fromList = $this->getNamespaceKeyAndText( $namespace, $from );
164 $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
165 $namespaces = $wgContLang->getNamespaces();
167 if ( !$prefixList ||
!$fromList ) {
168 $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock();
169 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
170 // Show errormessage and reset to NS_MAIN
171 $out = $this->msg( 'allpages-bad-ns', $namespace )->parse();
172 $namespace = NS_MAIN
;
174 list( $namespace, $prefixKey, $prefix ) = $prefixList;
175 list( /* $fromNS */, $fromKey, ) = $fromList;
177 ### @todo FIXME: Should complain if $fromNs != $namespace
179 $dbr = wfGetDB( DB_SLAVE
);
182 'page_namespace' => $namespace,
183 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
184 'page_title >= ' . $dbr->addQuotes( $fromKey ),
187 if ( $hideredirects ) {
188 $conds['page_is_redirect'] = 0;
191 $res = $dbr->select( 'page',
192 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
196 'ORDER BY' => 'page_title',
197 'LIMIT' => $this->maxPerPage +
1,
198 'USE INDEX' => 'name_title',
202 ### @todo FIXME: Side link to previous
205 if ( $res->numRows() > 0 ) {
206 $out = Xml
::openElement( 'table', array( 'id' => 'mw-prefixindex-list-table' ) );
208 $prefixLength = strlen( $prefix );
209 while ( ( $n < $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
210 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
212 $displayed = $t->getText();
213 if ( $this->stripPrefix
) {
214 $displayed = substr( $displayed, $prefixLength );
216 $link = ( $s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
219 htmlspecialchars( $displayed ),
220 $s->page_is_redirect ?
array( 'class' => 'mw-redirect' ) : array()
222 ( $s->page_is_redirect ?
'</div>' : '' );
224 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
229 $out .= "<td>$link</td>";
240 $out .= Xml
::closeElement( 'table' );
247 if ( $this->including() ) {
250 $nsForm = $this->namespacePrefixForm( $namespace, $prefix, $hideredirects );
251 $self = $this->getTitle();
252 $out2 = Xml
::openElement( 'table', array( 'id' => 'mw-prefixindex-nav-table' ) ) .
257 <td id="mw-prefixindex-nav-form" class="mw-prefixindex-nav">';
259 if ( isset( $res ) && $res && ( $n == $this->maxPerPage
) &&
260 ( $s = $res->fetchObject() )
263 'from' => $s->page_title
,
265 'hideredirects' => $hideredirects,
268 if ( $namespace ||
$prefix == '' ) {
269 // Keep the namespace even if it's 0 for empty prefixes.
270 // This tells us we're not just a holdover from old links.
271 $query['namespace'] = $namespace;
274 $nextLink = Linker
::linkKnown(
276 $this->msg( 'nextpage', str_replace( '_', ' ', $s->page_title
) )->escaped(),
283 $footer = "\n" . Html
::element( 'hr' ) .
286 array( 'class' => 'mw-prefixindex-nav' ),
290 $out2 .= "</td></tr>" .
291 Xml
::closeElement( 'table' );
294 $this->getOutput()->addHTML( $out2 . $out . $footer );
297 protected function getGroupName() {