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
62 } elseif( isset( $par ) ){
64 } elseif( $prefix != '' ){
66 } elseif( $from != '' ){
67 // For back-compat with Special:Allpages
70 if ($showme != '' ||
$namespace) {
71 $this->showPrefixChunk( $namespace, $showme, $from );
73 $wgOut->addHTML( $this->namespacePrefixForm( $namespace, null ) );
78 * HTML for the top form
79 * @param $namespace Integer: a namespace constant (default NS_MAIN).
80 * @param $from String: dbKey we are starting listing at.
82 function namespacePrefixForm( $namespace = NS_MAIN
, $from = '' ) {
84 $t = $this->getTitle();
86 $out = Xml
::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
87 $out .= Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
88 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
89 $out .= Xml
::openElement( 'fieldset' );
90 $out .= Xml
::element( 'legend', null, wfMsg( 'allpages' ) );
91 $out .= Xml
::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
93 <td class='mw-label'>" .
94 Xml
::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
96 <td class='mw-input'>" .
97 Xml
::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
101 <td class='mw-label'>" .
102 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
104 <td class='mw-input'>" .
105 Xml
::namespaceSelector( $namespace, null ) . ' ' .
106 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
109 $out .= Xml
::closeElement( 'table' );
110 $out .= Xml
::closeElement( 'fieldset' );
111 $out .= Xml
::closeElement( 'form' );
112 $out .= Xml
::closeElement( 'div' );
117 * @param $namespace Integer, default NS_MAIN
118 * @param $prefix String
119 * @param $from String: list all pages from this name (default FALSE)
121 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $from = null ) {
122 global $wgOut, $wgUser, $wgContLang, $wgLang;
124 $sk = $wgUser->getSkin();
126 if (!isset($from)) $from = $prefix;
128 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
129 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
130 $namespaces = $wgContLang->getNamespaces();
132 if ( !$prefixList ||
!$fromList ) {
133 $out = wfMsgExt( 'allpagesbadtitle', 'parse' );
134 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
135 // Show errormessage and reset to NS_MAIN
136 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
137 $namespace = NS_MAIN
;
139 list( $namespace, $prefixKey, $prefix ) = $prefixList;
140 list( /* $fromNS */, $fromKey, ) = $fromList;
142 ### @todo FIXME: Should complain if $fromNs != $namespace
144 $dbr = wfGetDB( DB_SLAVE
);
146 $res = $dbr->select( 'page',
147 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
149 'page_namespace' => $namespace,
150 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
151 'page_title >= ' . $dbr->addQuotes( $fromKey ),
155 'ORDER BY' => 'page_title',
156 'LIMIT' => $this->maxPerPage +
1,
157 'USE INDEX' => 'name_title',
161 ### @todo FIXME: Side link to previous
164 if( $res->numRows() > 0 ) {
165 $out = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
167 while( ( $n < $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
168 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
170 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
173 htmlspecialchars( $t->getText() )
175 ($s->page_is_redirect ?
'</div>' : '' );
177 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
182 $out .= "<td>$link</td>";
188 if( ($n %
3) != 0 ) {
191 $out .= Xml
::closeElement( 'table' );
197 if ( $this->including() ) {
200 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
201 $self = $this->getTitle();
202 $out2 = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
207 <td id="mw-prefixindex-nav-form">';
209 if( isset( $res ) && $res && ( $n == $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
211 'from' => $s->page_title
,
216 $query['namespace'] = $namespace;
219 $out2 = $wgLang->pipeList( array(
223 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title
) ) ),
229 $out2 .= "</td></tr>" .
230 Xml
::closeElement( 'table' );
233 $wgOut->addHTML( $out2 . $out );