325236585f246bb089f340e50910ca9c811fc3f0
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 != '' && $ns === null ) {
69 // For back-compat with Special:Allpages
70 // Don't do this if namespace is passed, so paging works when doing NS views.
74 // Bug 27864: if transcluded, show all pages instead of the form.
75 if ( $this->including() ||
$showme != '' ||
$ns !== null ) {
76 $this->showPrefixChunk( $namespace, $showme, $from );
78 $out->addHTML( $this->namespacePrefixForm( $namespace, null ) );
83 * HTML for the top form
84 * @param $namespace Integer: a namespace constant (default NS_MAIN).
85 * @param $from String: dbKey we are starting listing at.
87 function namespacePrefixForm( $namespace = NS_MAIN
, $from = '' ) {
90 $out = Xml
::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
91 $out .= Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
92 $out .= Html
::hidden( 'title', $this->getTitle()->getPrefixedText() );
93 $out .= Xml
::openElement( 'fieldset' );
94 $out .= Xml
::element( 'legend', null, wfMsg( 'allpages' ) );
95 $out .= Xml
::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
97 <td class='mw-label'>" .
98 Xml
::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
100 <td class='mw-input'>" .
101 Xml
::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
105 <td class='mw-label'>" .
106 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
108 <td class='mw-input'>" .
109 Xml
::namespaceSelector( $namespace, null ) . ' ' .
110 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
113 $out .= Xml
::closeElement( 'table' );
114 $out .= Xml
::closeElement( 'fieldset' );
115 $out .= Xml
::closeElement( 'form' );
116 $out .= Xml
::closeElement( 'div' );
121 * @param $namespace Integer, default NS_MAIN
122 * @param $prefix String
123 * @param $from String: list all pages from this name (default FALSE)
125 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $from = null ) {
128 if ( $from === null ) {
132 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
133 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
134 $namespaces = $wgContLang->getNamespaces();
136 if ( !$prefixList ||
!$fromList ) {
137 $out = wfMsgExt( 'allpagesbadtitle', 'parse' );
138 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
139 // Show errormessage and reset to NS_MAIN
140 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
141 $namespace = NS_MAIN
;
143 list( $namespace, $prefixKey, $prefix ) = $prefixList;
144 list( /* $fromNS */, $fromKey, ) = $fromList;
146 ### @todo FIXME: Should complain if $fromNs != $namespace
148 $dbr = wfGetDB( DB_SLAVE
);
150 $res = $dbr->select( 'page',
151 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
153 'page_namespace' => $namespace,
154 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
155 'page_title >= ' . $dbr->addQuotes( $fromKey ),
159 'ORDER BY' => 'page_title',
160 'LIMIT' => $this->maxPerPage +
1,
161 'USE INDEX' => 'name_title',
165 ### @todo FIXME: Side link to previous
168 if( $res->numRows() > 0 ) {
169 $out = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
171 while( ( $n < $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
172 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
174 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
177 htmlspecialchars( $t->getText() )
179 ($s->page_is_redirect ?
'</div>' : '' );
181 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
186 $out .= "<td>$link</td>";
192 if( ($n %
3) != 0 ) {
195 $out .= Xml
::closeElement( 'table' );
202 if ( $this->including() ) {
205 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
206 $self = $this->getTitle();
207 $out2 = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
212 <td id="mw-prefixindex-nav-form" class="mw-prefixindex-nav">';
214 if( isset( $res ) && $res && ( $n == $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
216 'from' => $s->page_title
,
220 if( $namespace ||
($prefix == '')) {
221 // Keep the namespace even if it's 0 for empty prefixes.
222 // This tells us we're not just a holdover from old links.
223 $query['namespace'] = $namespace;
225 $nextLink = Linker
::linkKnown(
227 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title
) ) ),
233 $footer = "\n" . Html
::element( "hr" )
234 . Html
::rawElement( "div", array( "class" => "mw-prefixindex-nav" ), $nextLink );
236 $out2 .= "</td></tr>" .
237 Xml
::closeElement( 'table' );
240 $this->getOutput()->addHTML( $out2 . $out . $footer );