Followup r77393, restore commented variable in SpecialPrefixindex as the variable...
[lhc/web/wiklou.git] / includes / specials / SpecialPrefixindex.php
1 <?php
2 /**
3 * Implements Special:Prefixindex
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * Implements Special:Prefixindex
26 *
27 * @ingroup SpecialPage
28 */
29 class SpecialPrefixindex extends SpecialAllpages {
30 // Inherit $maxPerPage
31
32 function __construct(){
33 parent::__construct( 'Prefixindex' );
34 }
35
36 /**
37 * Entry point : initialise variables and call subfunctions.
38 * @param $par String: becomes "FOO" when called like Special:Prefixindex/FOO (default null)
39 */
40 function execute( $par ) {
41 global $wgRequest, $wgOut, $wgContLang;
42
43 $this->setHeaders();
44 $this->outputHeader();
45
46 # GET values
47 $from = $wgRequest->getVal( 'from', '' );
48 $prefix = $wgRequest->getVal( 'prefix', '' );
49 $namespace = $wgRequest->getInt( 'namespace' );
50 $namespaces = $wgContLang->getNamespaces();
51
52 $wgOut->setPagetitle( ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
53 ? wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
54 : wfMsg( 'prefixindex' )
55 );
56
57 if( isset( $par ) ){
58 $this->showPrefixChunk( $namespace, $par, $from );
59 } elseif( $prefix != '' ){
60 $this->showPrefixChunk( $namespace, $prefix, $from );
61 } elseif( $from != '' ){
62 $this->showPrefixChunk( $namespace, $from, $from );
63 } else {
64 $wgOut->addHTML( $this->namespacePrefixForm( $namespace, null ) );
65 }
66 }
67
68 /**
69 * HTML for the top form
70 * @param $namespace Integer: a namespace constant (default NS_MAIN).
71 * @param $from String: dbKey we are starting listing at.
72 */
73 function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) {
74 global $wgScript;
75 $t = $this->getTitle();
76
77 $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
78 $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
79 $out .= Html::hidden( 'title', $t->getPrefixedText() );
80 $out .= Xml::openElement( 'fieldset' );
81 $out .= Xml::element( 'legend', null, wfMsg( 'allpages' ) );
82 $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
83 $out .= "<tr>
84 <td class='mw-label'>" .
85 Xml::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
86 "</td>
87 <td class='mw-input'>" .
88 Xml::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
89 "</td>
90 </tr>
91 <tr>
92 <td class='mw-label'>" .
93 Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
94 "</td>
95 <td class='mw-input'>" .
96 Xml::namespaceSelector( $namespace, null ) . ' ' .
97 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
98 "</td>
99 </tr>";
100 $out .= Xml::closeElement( 'table' );
101 $out .= Xml::closeElement( 'fieldset' );
102 $out .= Xml::closeElement( 'form' );
103 $out .= Xml::closeElement( 'div' );
104 return $out;
105 }
106
107 /**
108 * @param $namespace Integer, default NS_MAIN
109 * @param $prefix String
110 * @param $from String: list all pages from this name (default FALSE)
111 */
112 function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) {
113 global $wgOut, $wgUser, $wgContLang, $wgLang;
114
115 $sk = $wgUser->getSkin();
116
117 if (!isset($from)) $from = $prefix;
118
119 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
120 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
121 $namespaces = $wgContLang->getNamespaces();
122
123 if ( !$prefixList || !$fromList ) {
124 $out = wfMsgWikiHtml( 'allpagesbadtitle' );
125 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
126 // Show errormessage and reset to NS_MAIN
127 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
128 $namespace = NS_MAIN;
129 } else {
130 list( $namespace, $prefixKey, $prefix ) = $prefixList;
131 list( /* $fromNS */, $fromKey, ) = $fromList;
132
133 ### FIXME: should complain if $fromNs != $namespace
134
135 $dbr = wfGetDB( DB_SLAVE );
136
137 $res = $dbr->select( 'page',
138 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
139 array(
140 'page_namespace' => $namespace,
141 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
142 'page_title >= ' . $dbr->addQuotes( $fromKey ),
143 ),
144 __METHOD__,
145 array(
146 'ORDER BY' => 'page_title',
147 'LIMIT' => $this->maxPerPage + 1,
148 'USE INDEX' => 'name_title',
149 )
150 );
151
152 ### FIXME: side link to previous
153
154 $n = 0;
155 if( $res->numRows() > 0 ) {
156 $out = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
157
158 while( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
159 $t = Title::makeTitle( $s->page_namespace, $s->page_title );
160 if( $t ) {
161 $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
162 $sk->linkKnown(
163 $t,
164 htmlspecialchars( $t->getText() )
165 ) .
166 ($s->page_is_redirect ? '</div>' : '' );
167 } else {
168 $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
169 }
170 if( $n % 3 == 0 ) {
171 $out .= '<tr>';
172 }
173 $out .= "<td>$link</td>";
174 $n++;
175 if( $n % 3 == 0 ) {
176 $out .= '</tr>';
177 }
178 }
179 if( ($n % 3) != 0 ) {
180 $out .= '</tr>';
181 }
182 $out .= Xml::closeElement( 'table' );
183 } else {
184 $out = '';
185 }
186 }
187
188 if ( $this->including() ) {
189 $out2 = '';
190 } else {
191 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
192 $self = $this->getTitle();
193 $out2 = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
194 '<tr>
195 <td>' .
196 $nsForm .
197 '</td>
198 <td id="mw-prefixindex-nav-form">' .
199 $sk->linkKnown( $self, wfMsgHtml( 'allpages' ) );
200
201 if( isset( $res ) && $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
202 $query = array(
203 'from' => $s->page_title,
204 'prefix' => $prefix
205 );
206
207 if( $namespace ) {
208 $query['namespace'] = $namespace;
209 }
210
211 $out2 = $wgLang->pipeList( array(
212 $out2,
213 $sk->linkKnown(
214 $self,
215 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title ) ) ),
216 array(),
217 $query
218 )
219 ) );
220 }
221 $out2 .= "</td></tr>" .
222 Xml::closeElement( 'table' );
223 }
224
225 $wgOut->addHTML( $out2 . $out );
226 }
227 }