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( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
60 : $this->msg( 'prefixindex' )
66 } elseif( $prefix != '' ) {
68 } elseif( $from != '' ) {
69 // For back-compat with Special:Allpages
73 // Bug 27864: if transcluded, show all pages instead of the form.
74 if ( $this->including() ||
$showme != '' ||
$ns !== null ) {
75 $this->showPrefixChunk( $namespace, $showme, $from );
77 $out->addHTML( $this->namespacePrefixForm( $namespace, null ) );
82 * HTML for the top form
83 * @param $namespace Integer: a namespace constant (default NS_MAIN).
84 * @param $from String: dbKey we are starting listing at.
86 function namespacePrefixForm( $namespace = NS_MAIN
, $from = '' ) {
89 $out = Xml
::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
90 $out .= Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
91 $out .= Html
::hidden( 'title', $this->getTitle()->getPrefixedText() );
92 $out .= Xml
::openElement( 'fieldset' );
93 $out .= Xml
::element( 'legend', null, wfMsg( 'allpages' ) );
94 $out .= Xml
::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
96 <td class='mw-label'>" .
97 Xml
::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
99 <td class='mw-input'>" .
100 Xml
::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
104 <td class='mw-label'>" .
105 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
107 <td class='mw-input'>" .
108 Xml
::namespaceSelector( $namespace, null ) . ' ' .
109 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
112 $out .= Xml
::closeElement( 'table' );
113 $out .= Xml
::closeElement( 'fieldset' );
114 $out .= Xml
::closeElement( 'form' );
115 $out .= Xml
::closeElement( 'div' );
120 * @param $namespace Integer, default NS_MAIN
121 * @param $prefix String
122 * @param $from String: list all pages from this name (default FALSE)
124 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $from = null ) {
127 if ( $from === null ) {
131 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
132 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
133 $namespaces = $wgContLang->getNamespaces();
135 if ( !$prefixList ||
!$fromList ) {
136 $out = wfMsgExt( 'allpagesbadtitle', 'parse' );
137 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
138 // Show errormessage and reset to NS_MAIN
139 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
140 $namespace = NS_MAIN
;
142 list( $namespace, $prefixKey, $prefix ) = $prefixList;
143 list( /* $fromNS */, $fromKey, ) = $fromList;
145 ### @todo FIXME: Should complain if $fromNs != $namespace
147 $dbr = wfGetDB( DB_SLAVE
);
149 $res = $dbr->select( 'page',
150 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
152 'page_namespace' => $namespace,
153 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
154 'page_title >= ' . $dbr->addQuotes( $fromKey ),
158 'ORDER BY' => 'page_title',
159 'LIMIT' => $this->maxPerPage +
1,
160 'USE INDEX' => 'name_title',
164 ### @todo FIXME: Side link to previous
167 if( $res->numRows() > 0 ) {
168 $out = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
170 while( ( $n < $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
171 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
173 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
176 htmlspecialchars( $t->getText() )
178 ($s->page_is_redirect ?
'</div>' : '' );
180 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
185 $out .= "<td>$link</td>";
191 if( ($n %
3) != 0 ) {
194 $out .= Xml
::closeElement( 'table' );
201 if ( $this->including() ) {
204 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
205 $self = $this->getTitle();
206 $out2 = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
211 <td id="mw-prefixindex-nav-form" class="mw-prefixindex-nav">';
213 if( isset( $res ) && $res && ( $n == $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
215 'from' => $s->page_title
,
220 $query['namespace'] = $namespace;
223 $nextLink = Linker
::linkKnown(
225 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title
) ) ),
231 $footer = "\n" . Html
::element( "hr" )
232 . Html
::rawElement( "div", array( "class" => "mw-prefixindex-nav" ), $nextLink );
234 $out2 .= "</td></tr>" .
235 Xml
::closeElement( 'table' );
238 $this->getOutput()->addHTML( $out2 . $out . $footer );