Change usages of $wgUser->getSkin() in special pages to use $this->getSkin()
[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 $wgOut->addModuleStyles( 'mediawiki.special' );
46
47 # GET values
48 $from = $wgRequest->getVal( 'from', '' );
49 $prefix = $wgRequest->getVal( 'prefix', '' );
50 $ns = $wgRequest->getIntOrNull( 'namespace' );
51 $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN).
52
53 $namespaces = $wgContLang->getNamespaces();
54 $wgOut->setPagetitle(
55 ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
56 ? wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
57 : wfMsg( 'prefixindex' )
58 );
59
60 $showme = '';
61 if( isset( $par ) ) {
62 $showme = $par;
63 } elseif( $prefix != '' ) {
64 $showme = $prefix;
65 } elseif( $from != '' ) {
66 // For back-compat with Special:Allpages
67 $showme = $from;
68 }
69
70 // Bug 27864: if transcluded, show all pages instead of the form.
71 if ( $this->including() || $showme != '' || $ns !== null ) {
72 $this->showPrefixChunk( $namespace, $showme, $from );
73 } else {
74 $wgOut->addHTML( $this->namespacePrefixForm( $namespace, null ) );
75 }
76 }
77
78 /**
79 * HTML for the top form
80 * @param $namespace Integer: a namespace constant (default NS_MAIN).
81 * @param $from String: dbKey we are starting listing at.
82 */
83 function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) {
84 global $wgScript;
85 $t = $this->getTitle();
86
87 $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
88 $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
89 $out .= Html::hidden( 'title', $t->getPrefixedText() );
90 $out .= Xml::openElement( 'fieldset' );
91 $out .= Xml::element( 'legend', null, wfMsg( 'allpages' ) );
92 $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
93 $out .= "<tr>
94 <td class='mw-label'>" .
95 Xml::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
96 "</td>
97 <td class='mw-input'>" .
98 Xml::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
99 "</td>
100 </tr>
101 <tr>
102 <td class='mw-label'>" .
103 Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
104 "</td>
105 <td class='mw-input'>" .
106 Xml::namespaceSelector( $namespace, null ) . ' ' .
107 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
108 "</td>
109 </tr>";
110 $out .= Xml::closeElement( 'table' );
111 $out .= Xml::closeElement( 'fieldset' );
112 $out .= Xml::closeElement( 'form' );
113 $out .= Xml::closeElement( 'div' );
114 return $out;
115 }
116
117 /**
118 * @param $namespace Integer, default NS_MAIN
119 * @param $prefix String
120 * @param $from String: list all pages from this name (default FALSE)
121 */
122 function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) {
123 global $wgOut, $wgContLang, $wgLang;
124
125 $sk = $this->getSkin();
126
127 if (!isset($from)) $from = $prefix;
128
129 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
130 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
131 $namespaces = $wgContLang->getNamespaces();
132
133 if ( !$prefixList || !$fromList ) {
134 $out = wfMsgExt( 'allpagesbadtitle', 'parse' );
135 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
136 // Show errormessage and reset to NS_MAIN
137 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
138 $namespace = NS_MAIN;
139 } else {
140 list( $namespace, $prefixKey, $prefix ) = $prefixList;
141 list( /* $fromNS */, $fromKey, ) = $fromList;
142
143 ### @todo FIXME: Should complain if $fromNs != $namespace
144
145 $dbr = wfGetDB( DB_SLAVE );
146
147 $res = $dbr->select( 'page',
148 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
149 array(
150 'page_namespace' => $namespace,
151 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
152 'page_title >= ' . $dbr->addQuotes( $fromKey ),
153 ),
154 __METHOD__,
155 array(
156 'ORDER BY' => 'page_title',
157 'LIMIT' => $this->maxPerPage + 1,
158 'USE INDEX' => 'name_title',
159 )
160 );
161
162 ### @todo FIXME: Side link to previous
163
164 $n = 0;
165 if( $res->numRows() > 0 ) {
166 $out = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
167
168 while( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
169 $t = Title::makeTitle( $s->page_namespace, $s->page_title );
170 if( $t ) {
171 $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
172 $sk->linkKnown(
173 $t,
174 htmlspecialchars( $t->getText() )
175 ) .
176 ($s->page_is_redirect ? '</div>' : '' );
177 } else {
178 $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
179 }
180 if( $n % 3 == 0 ) {
181 $out .= '<tr>';
182 }
183 $out .= "<td>$link</td>";
184 $n++;
185 if( $n % 3 == 0 ) {
186 $out .= '</tr>';
187 }
188 }
189 if( ($n % 3) != 0 ) {
190 $out .= '</tr>';
191 }
192 $out .= Xml::closeElement( 'table' );
193 } else {
194 $out = '';
195 }
196 }
197
198 if ( $this->including() ) {
199 $out2 = '';
200 } else {
201 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
202 $self = $this->getTitle();
203 $out2 = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
204 '<tr>
205 <td>' .
206 $nsForm .
207 '</td>
208 <td id="mw-prefixindex-nav-form">';
209
210 if( isset( $res ) && $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
211 $query = array(
212 'from' => $s->page_title,
213 'prefix' => $prefix
214 );
215
216 if( $namespace ) {
217 $query['namespace'] = $namespace;
218 }
219
220 $out2 = $wgLang->pipeList( array(
221 $out2,
222 $sk->linkKnown(
223 $self,
224 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title ) ) ),
225 array(),
226 $query
227 )
228 ) );
229 }
230 $out2 .= "</td></tr>" .
231 Xml::closeElement( 'table' );
232 }
233
234 $wgOut->addHTML( $out2 . $out );
235 }
236 }