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 ) {
41 global $wgRequest, $wgOut, $wgContLang;
44 $this->outputHeader();
45 $wgOut->addModuleStyles( 'mediawiki.special' );
48 $from = $wgRequest->getVal( 'from', '' );
49 $prefix = $wgRequest->getVal( 'prefix', '' );
50 $ns = $wgRequest->getIntOrNull( 'namespace' );
51 $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN).
53 $namespaces = $wgContLang->getNamespaces();
55 ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
56 ?
wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
57 : wfMsg( 'prefixindex' )
63 } elseif( $prefix != '' ) {
65 } elseif( $from != '' ) {
66 // For back-compat with Special:Allpages
70 // Bug 27864: if transcluded, show all pages instead of the form.
71 if ( $this->including() ||
$showme != '' ||
$ns !== null ) {
72 $this->showPrefixChunk( $namespace, $showme, $from );
74 $wgOut->addHTML( $this->namespacePrefixForm( $namespace, null ) );
79 * HTML for the top form
80 * @param $namespace Integer: a namespace constant (default NS_MAIN).
81 * @param $from String: dbKey we are starting listing at.
83 function namespacePrefixForm( $namespace = NS_MAIN
, $from = '' ) {
85 $t = $this->getTitle();
87 $out = Xml
::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
88 $out .= Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
89 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
90 $out .= Xml
::openElement( 'fieldset' );
91 $out .= Xml
::element( 'legend', null, wfMsg( 'allpages' ) );
92 $out .= Xml
::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
94 <td class='mw-label'>" .
95 Xml
::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
97 <td class='mw-input'>" .
98 Xml
::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
102 <td class='mw-label'>" .
103 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
105 <td class='mw-input'>" .
106 Xml
::namespaceSelector( $namespace, null ) . ' ' .
107 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
110 $out .= Xml
::closeElement( 'table' );
111 $out .= Xml
::closeElement( 'fieldset' );
112 $out .= Xml
::closeElement( 'form' );
113 $out .= Xml
::closeElement( 'div' );
118 * @param $namespace Integer, default NS_MAIN
119 * @param $prefix String
120 * @param $from String: list all pages from this name (default FALSE)
122 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $from = null ) {
123 global $wgOut, $wgUser, $wgContLang, $wgLang;
125 $sk = $wgUser->getSkin();
127 if (!isset($from)) $from = $prefix;
129 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
130 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
131 $namespaces = $wgContLang->getNamespaces();
133 if ( !$prefixList ||
!$fromList ) {
134 $out = wfMsgExt( 'allpagesbadtitle', 'parse' );
135 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
136 // Show errormessage and reset to NS_MAIN
137 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
138 $namespace = NS_MAIN
;
140 list( $namespace, $prefixKey, $prefix ) = $prefixList;
141 list( /* $fromNS */, $fromKey, ) = $fromList;
143 ### @todo FIXME: Should complain if $fromNs != $namespace
145 $dbr = wfGetDB( DB_SLAVE
);
147 $res = $dbr->select( 'page',
148 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
150 'page_namespace' => $namespace,
151 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
152 'page_title >= ' . $dbr->addQuotes( $fromKey ),
156 'ORDER BY' => 'page_title',
157 'LIMIT' => $this->maxPerPage +
1,
158 'USE INDEX' => 'name_title',
162 ### @todo FIXME: Side link to previous
165 if( $res->numRows() > 0 ) {
166 $out = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
168 while( ( $n < $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
169 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
171 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
174 htmlspecialchars( $t->getText() )
176 ($s->page_is_redirect ?
'</div>' : '' );
178 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
183 $out .= "<td>$link</td>";
189 if( ($n %
3) != 0 ) {
192 $out .= Xml
::closeElement( 'table' );
198 if ( $this->including() ) {
201 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
202 $self = $this->getTitle();
203 $out2 = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
208 <td id="mw-prefixindex-nav-form">';
210 if( isset( $res ) && $res && ( $n == $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
212 'from' => $s->page_title
,
217 $query['namespace'] = $namespace;
220 $out2 = $wgLang->pipeList( array(
224 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title
) ) ),
230 $out2 .= "</td></tr>" .
231 Xml
::closeElement( 'table' );
234 $wgOut->addHTML( $out2 . $out );