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 $namespace = $wgRequest->getInt( 'namespace' );
51 $namespaces = $wgContLang->getNamespaces();
53 $wgOut->setPagetitle( ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
54 ?
wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
55 : wfMsg( 'prefixindex' )
59 if ( $this->including() && $par == '' ) {
60 // Bug 27864: if transcluded, show all pages instead of the form
61 } elseif( isset( $par ) ) {
63 } elseif( $prefix != '' ) {
65 } elseif( $from != '' ) {
66 // For back-compat with Special:Allpages
69 if ( $showme != '' ||
$namespace ) {
70 $this->showPrefixChunk( $namespace, $showme, $from );
72 $wgOut->addHTML( $this->namespacePrefixForm( $namespace, null ) );
77 * HTML for the top form
78 * @param $namespace Integer: a namespace constant (default NS_MAIN).
79 * @param $from String: dbKey we are starting listing at.
81 function namespacePrefixForm( $namespace = NS_MAIN
, $from = '' ) {
83 $t = $this->getTitle();
85 $out = Xml
::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
86 $out .= Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
87 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
88 $out .= Xml
::openElement( 'fieldset' );
89 $out .= Xml
::element( 'legend', null, wfMsg( 'allpages' ) );
90 $out .= Xml
::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
92 <td class='mw-label'>" .
93 Xml
::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
95 <td class='mw-input'>" .
96 Xml
::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
100 <td class='mw-label'>" .
101 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
103 <td class='mw-input'>" .
104 Xml
::namespaceSelector( $namespace, null ) . ' ' .
105 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
108 $out .= Xml
::closeElement( 'table' );
109 $out .= Xml
::closeElement( 'fieldset' );
110 $out .= Xml
::closeElement( 'form' );
111 $out .= Xml
::closeElement( 'div' );
116 * @param $namespace Integer, default NS_MAIN
117 * @param $prefix String
118 * @param $from String: list all pages from this name (default FALSE)
120 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $from = null ) {
121 global $wgOut, $wgUser, $wgContLang, $wgLang;
123 $sk = $wgUser->getSkin();
125 if (!isset($from)) $from = $prefix;
127 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
128 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
129 $namespaces = $wgContLang->getNamespaces();
131 if ( !$prefixList ||
!$fromList ) {
132 $out = wfMsgExt( 'allpagesbadtitle', 'parse' );
133 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
134 // Show errormessage and reset to NS_MAIN
135 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
136 $namespace = NS_MAIN
;
138 list( $namespace, $prefixKey, $prefix ) = $prefixList;
139 list( /* $fromNS */, $fromKey, ) = $fromList;
141 ### @todo FIXME: Should complain if $fromNs != $namespace
143 $dbr = wfGetDB( DB_SLAVE
);
145 $res = $dbr->select( 'page',
146 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
148 'page_namespace' => $namespace,
149 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
150 'page_title >= ' . $dbr->addQuotes( $fromKey ),
154 'ORDER BY' => 'page_title',
155 'LIMIT' => $this->maxPerPage +
1,
156 'USE INDEX' => 'name_title',
160 ### @todo FIXME: Side link to previous
163 if( $res->numRows() > 0 ) {
164 $out = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
166 while( ( $n < $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
167 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
169 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
172 htmlspecialchars( $t->getText() )
174 ($s->page_is_redirect ?
'</div>' : '' );
176 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
181 $out .= "<td>$link</td>";
187 if( ($n %
3) != 0 ) {
190 $out .= Xml
::closeElement( 'table' );
196 if ( $this->including() ) {
199 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
200 $self = $this->getTitle();
201 $out2 = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
206 <td id="mw-prefixindex-nav-form">';
208 if( isset( $res ) && $res && ( $n == $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
210 'from' => $s->page_title
,
215 $query['namespace'] = $namespace;
218 $out2 = $wgLang->pipeList( array(
222 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title
) ) ),
228 $out2 .= "</td></tr>" .
229 Xml
::closeElement( 'table' );
232 $wgOut->addHTML( $out2 . $out );