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' )
61 } elseif( $prefix != '' ){
63 } elseif( $from != '' ){
64 // For back-compat with Special:Allpages
67 if ($showme != '' ||
$namespace) {
68 $this->showPrefixChunk( $namespace, $showme, $from );
70 $wgOut->addHTML( $this->namespacePrefixForm( $namespace, null ) );
75 * HTML for the top form
76 * @param $namespace Integer: a namespace constant (default NS_MAIN).
77 * @param $from String: dbKey we are starting listing at.
79 function namespacePrefixForm( $namespace = NS_MAIN
, $from = '' ) {
81 $t = $this->getTitle();
83 $out = Xml
::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
84 $out .= Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
85 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
86 $out .= Xml
::openElement( 'fieldset' );
87 $out .= Xml
::element( 'legend', null, wfMsg( 'allpages' ) );
88 $out .= Xml
::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
90 <td class='mw-label'>" .
91 Xml
::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
93 <td class='mw-input'>" .
94 Xml
::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
98 <td class='mw-label'>" .
99 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
101 <td class='mw-input'>" .
102 Xml
::namespaceSelector( $namespace, null ) . ' ' .
103 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
106 $out .= Xml
::closeElement( 'table' );
107 $out .= Xml
::closeElement( 'fieldset' );
108 $out .= Xml
::closeElement( 'form' );
109 $out .= Xml
::closeElement( 'div' );
114 * @param $namespace Integer, default NS_MAIN
115 * @param $prefix String
116 * @param $from String: list all pages from this name (default FALSE)
118 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $from = null ) {
119 global $wgOut, $wgUser, $wgContLang, $wgLang;
121 $sk = $wgUser->getSkin();
123 if (!isset($from)) $from = $prefix;
125 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
126 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
127 $namespaces = $wgContLang->getNamespaces();
129 if ( !$prefixList ||
!$fromList ) {
130 $out = wfMsgExt( 'allpagesbadtitle', 'parse' );
131 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
132 // Show errormessage and reset to NS_MAIN
133 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
134 $namespace = NS_MAIN
;
136 list( $namespace, $prefixKey, $prefix ) = $prefixList;
137 list( /* $fromNS */, $fromKey, ) = $fromList;
139 ### FIXME: should complain if $fromNs != $namespace
141 $dbr = wfGetDB( DB_SLAVE
);
143 $res = $dbr->select( 'page',
144 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
146 'page_namespace' => $namespace,
147 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
148 'page_title >= ' . $dbr->addQuotes( $fromKey ),
152 'ORDER BY' => 'page_title',
153 'LIMIT' => $this->maxPerPage +
1,
154 'USE INDEX' => 'name_title',
158 ### FIXME: side link to previous
161 if( $res->numRows() > 0 ) {
162 $out = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
164 while( ( $n < $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
165 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
167 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
170 htmlspecialchars( $t->getText() )
172 ($s->page_is_redirect ?
'</div>' : '' );
174 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
179 $out .= "<td>$link</td>";
185 if( ($n %
3) != 0 ) {
188 $out .= Xml
::closeElement( 'table' );
194 if ( $this->including() ) {
197 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
198 $self = $this->getTitle();
199 $out2 = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
204 <td id="mw-prefixindex-nav-form">' .
205 $sk->linkKnown( $self, wfMsgHtml( 'allpages' ) );
207 if( isset( $res ) && $res && ( $n == $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
209 'from' => $s->page_title
,
214 $query['namespace'] = $namespace;
217 $out2 = $wgLang->pipeList( array(
221 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title
) ) ),
227 $out2 .= "</td></tr>" .
228 Xml
::closeElement( 'table' );
231 $wgOut->addHTML( $out2 . $out );