4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * http://www.gnu.org/copyleft/gpl.html
21 * implements Special:Prefixindex
22 * @ingroup SpecialPage
24 class SpecialPrefixindex
extends SpecialAllpages
{
25 // Inherit $maxPerPage
27 function __construct(){
28 parent
::__construct( 'Prefixindex' );
32 * Entry point : initialise variables and call subfunctions.
33 * @param $par String: becomes "FOO" when called like Special:Prefixindex/FOO (default null)
35 function execute( $par ) {
36 global $wgRequest, $wgOut, $wgContLang;
39 $this->outputHeader();
42 $from = $wgRequest->getVal( 'from' );
43 $prefix = $wgRequest->getVal( 'prefix', '' );
44 $namespace = $wgRequest->getInt( 'namespace' );
45 $namespaces = $wgContLang->getNamespaces();
47 $wgOut->setPagetitle( ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
48 ?
wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
49 : wfMsg( 'prefixindex' )
53 $this->showPrefixChunk( $namespace, $par, $from );
54 } elseif( isset( $prefix ) ){
55 $this->showPrefixChunk( $namespace, $prefix, $from );
56 } elseif( isset( $from ) ){
57 $this->showPrefixChunk( $namespace, $from, $from );
59 $wgOut->addHTML( $this->namespacePrefixForm( $namespace, null ) );
64 * HTML for the top form
65 * @param $namespace Integer: a namespace constant (default NS_MAIN).
66 * @param $from String: dbKey we are starting listing at.
68 function namespacePrefixForm( $namespace = NS_MAIN
, $from = '' ) {
70 $t = $this->getTitle();
72 $out = Xml
::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
73 $out .= Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
74 $out .= Xml
::hidden( 'title', $t->getPrefixedText() );
75 $out .= Xml
::openElement( 'fieldset' );
76 $out .= Xml
::element( 'legend', null, wfMsg( 'allpages' ) );
77 $out .= Xml
::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
79 <td class='mw-label'>" .
80 Xml
::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
82 <td class='mw-input'>" .
83 Xml
::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
87 <td class='mw-label'>" .
88 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
90 <td class='mw-input'>" .
91 Xml
::namespaceSelector( $namespace, null ) . ' ' .
92 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
95 $out .= Xml
::closeElement( 'table' );
96 $out .= Xml
::closeElement( 'fieldset' );
97 $out .= Xml
::closeElement( 'form' );
98 $out .= Xml
::closeElement( 'div' );
103 * @param $namespace Integer, default NS_MAIN
104 * @param $prefix String
105 * @param $from String: list all pages from this name (default FALSE)
107 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $from = null ) {
108 global $wgOut, $wgUser, $wgContLang, $wgLang;
110 $sk = $wgUser->getSkin();
112 if (!isset($from)) $from = $prefix;
114 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
115 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
116 $namespaces = $wgContLang->getNamespaces();
118 if ( !$prefixList ||
!$fromList ) {
119 $out = wfMsgWikiHtml( 'allpagesbadtitle' );
120 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
121 // Show errormessage and reset to NS_MAIN
122 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
123 $namespace = NS_MAIN
;
125 list( $namespace, $prefixKey, $prefix ) = $prefixList;
126 list( /* $fromNs */, $fromKey, $from ) = $fromList;
128 ### FIXME: should complain if $fromNs != $namespace
130 $dbr = wfGetDB( DB_SLAVE
);
132 $res = $dbr->select( 'page',
133 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
135 'page_namespace' => $namespace,
136 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
137 'page_title >= ' . $dbr->addQuotes( $fromKey ),
141 'ORDER BY' => 'page_title',
142 'LIMIT' => $this->maxPerPage +
1,
143 'USE INDEX' => 'name_title',
147 ### FIXME: side link to previous
150 if( $res->numRows() > 0 ) {
151 $out = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
153 while( ( $n < $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
154 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
156 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
159 htmlspecialchars( $t->getText() )
161 ($s->page_is_redirect ?
'</div>' : '' );
163 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
168 $out .= "<td>$link</td>";
174 if( ($n %
3) != 0 ) {
177 $out .= Xml
::closeElement( 'table' );
183 if ( $this->including() ) {
186 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
187 $self = $this->getTitle();
188 $out2 = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
193 <td id="mw-prefixindex-nav-form">' .
194 $sk->linkKnown( $self, wfMsgHtml( 'allpages' ) );
196 if( isset( $res ) && $res && ( $n == $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
198 'from' => $s->page_title
,
203 $query['namespace'] = $namespace;
206 $out2 = $wgLang->pipeList( array(
210 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title
) ) ),
216 $out2 .= "</td></tr>" .
217 Xml
::closeElement( 'table' );
220 $wgOut->addHTML( $out2 . $out );