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 $par String: 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).
56 $namespaces = $wgContLang->getNamespaces();
58 ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
59 ?
$this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
60 : $this->msg( 'prefixindex' )
66 } elseif( $prefix != '' ) {
68 } elseif( $from != '' && $ns === null ) {
69 // For back-compat with Special:Allpages
70 // Don't do this if namespace is passed, so paging works when doing NS views.
74 // Bug 27864: if transcluded, show all pages instead of the form.
75 if ( $this->including() ||
$showme != '' ||
$ns !== null ) {
76 $this->showPrefixChunk( $namespace, $showme, $from );
78 $out->addHTML( $this->namespacePrefixForm( $namespace, null ) );
83 * HTML for the top form
84 * @param $namespace Integer: a namespace constant (default NS_MAIN).
85 * @param $from String: dbKey we are starting listing at.
88 function namespacePrefixForm( $namespace = NS_MAIN
, $from = '' ) {
91 $out = Xml
::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
92 $out .= Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
93 $out .= Html
::hidden( 'title', $this->getTitle()->getPrefixedText() );
94 $out .= Xml
::openElement( 'fieldset' );
95 $out .= Xml
::element( 'legend', null, wfMsg( 'allpages' ) );
96 $out .= Xml
::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
98 <td class='mw-label'>" .
99 Xml
::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
101 <td class='mw-input'>" .
102 Xml
::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
106 <td class='mw-label'>" .
107 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
109 <td class='mw-input'>" .
110 Html
::namespaceSelector( array(
111 'selected' => $namespace,
113 'name' => 'namespace',
115 'class' => 'namespaceselector',
117 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
120 $out .= Xml
::closeElement( 'table' );
121 $out .= Xml
::closeElement( 'fieldset' );
122 $out .= Xml
::closeElement( 'form' );
123 $out .= Xml
::closeElement( 'div' );
128 * @param $namespace Integer, default NS_MAIN
129 * @param $prefix String
130 * @param $from String: list all pages from this name (default FALSE)
132 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $from = null ) {
135 if ( $from === null ) {
139 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
140 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
141 $namespaces = $wgContLang->getNamespaces();
143 if ( !$prefixList ||
!$fromList ) {
144 $out = wfMsgExt( 'allpagesbadtitle', 'parse' );
145 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
146 // Show errormessage and reset to NS_MAIN
147 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
148 $namespace = NS_MAIN
;
150 list( $namespace, $prefixKey, $prefix ) = $prefixList;
151 list( /* $fromNS */, $fromKey, ) = $fromList;
153 ### @todo FIXME: Should complain if $fromNs != $namespace
155 $dbr = wfGetDB( DB_SLAVE
);
157 $res = $dbr->select( 'page',
158 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
160 'page_namespace' => $namespace,
161 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
162 'page_title >= ' . $dbr->addQuotes( $fromKey ),
166 'ORDER BY' => 'page_title',
167 'LIMIT' => $this->maxPerPage +
1,
168 'USE INDEX' => 'name_title',
172 ### @todo FIXME: Side link to previous
175 if( $res->numRows() > 0 ) {
176 $out = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
178 while( ( $n < $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
179 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
181 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
184 htmlspecialchars( $t->getText() )
186 ($s->page_is_redirect ?
'</div>' : '' );
188 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
193 $out .= "<td>$link</td>";
199 if( ($n %
3) != 0 ) {
202 $out .= Xml
::closeElement( 'table' );
209 if ( $this->including() ) {
212 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
213 $self = $this->getTitle();
214 $out2 = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
219 <td id="mw-prefixindex-nav-form" class="mw-prefixindex-nav">';
221 if( isset( $res ) && $res && ( $n == $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
223 'from' => $s->page_title
,
227 if( $namespace ||
($prefix == '')) {
228 // Keep the namespace even if it's 0 for empty prefixes.
229 // This tells us we're not just a holdover from old links.
230 $query['namespace'] = $namespace;
232 $nextLink = Linker
::linkKnown(
234 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title
) ) ),
240 $footer = "\n" . Html
::element( "hr" )
241 . Html
::rawElement( "div", array( "class" => "mw-prefixindex-nav" ), $nextLink );
243 $out2 .= "</td></tr>" .
244 Xml
::closeElement( 'table' );
247 $this->getOutput()->addHTML( $out2 . $out . $footer );