Fixed spacing in db/debug/diff/externalstore/objectcache folder
[mediawiki.git] / includes / specials / SpecialPrefixindex.php
blob35b5e3cd6dfb5f5aada8a178d1caa5b741351d7e
1 <?php
2 /**
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
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * Implements Special:Prefixindex
27 * @ingroup SpecialPage
29 class SpecialPrefixindex extends SpecialAllpages {
30 // Inherit $maxPerPage
32 function __construct() {
33 parent::__construct( 'Prefixindex' );
36 /**
37 * Entry point : initialise variables and call subfunctions.
38 * @param string $par becomes "FOO" when called like Special:Prefixindex/FOO (default null)
40 function execute( $par ) {
41 global $wgContLang;
43 $this->setHeaders();
44 $this->outputHeader();
46 $out = $this->getOutput();
47 $out->addModuleStyles( 'mediawiki.special' );
49 # GET values
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).
55 $hideredirects = $request->getBool( 'hideredirects', false );
57 $namespaces = $wgContLang->getNamespaces();
58 $out->setPageTitle(
59 ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
60 ? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
61 : $this->msg( 'prefixindex' )
64 $showme = '';
65 if ( isset( $par ) ) {
66 $showme = $par;
67 } elseif ( $prefix != '' ) {
68 $showme = $prefix;
69 } elseif ( $from != '' && $ns === null ) {
70 // For back-compat with Special:Allpages
71 // Don't do this if namespace is passed, so paging works when doing NS views.
72 $showme = $from;
75 // Bug 27864: if transcluded, show all pages instead of the form.
76 if ( $this->including() || $showme != '' || $ns !== null ) {
77 $this->showPrefixChunk( $namespace, $showme, $from, $hideredirects );
78 } else {
79 $out->addHTML( $this->namespacePrefixForm( $namespace, null, $hideredirects ) );
83 /**
84 * HTML for the top form
85 * @param $namespace Integer: a namespace constant (default NS_MAIN).
86 * @param string $from dbKey we are starting listing at.
87 * @param bool $hideredirects hide redirects (default FALSE)
88 * @return string
90 function namespacePrefixForm( $namespace = NS_MAIN, $from = '', $hideredirects = false ) {
91 global $wgScript;
93 $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
94 $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
95 $out .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() );
96 $out .= Xml::openElement( 'fieldset' );
97 $out .= Xml::element( 'legend', null, $this->msg( 'allpages' )->text() );
98 $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
99 $out .= "<tr>
100 <td class='mw-label'>" .
101 Xml::label( $this->msg( 'allpagesprefix' )->text(), 'nsfrom' ) .
102 "</td>
103 <td class='mw-input'>" .
104 Xml::input( 'prefix', 30, str_replace( '_', ' ', $from ), array( 'id' => 'nsfrom' ) ) .
105 "</td>
106 </tr>
107 <tr>
108 <td class='mw-label'>" .
109 Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) .
110 "</td>
111 <td class='mw-input'>" .
112 Html::namespaceSelector( array(
113 'selected' => $namespace,
114 ), array(
115 'name' => 'namespace',
116 'id' => 'namespace',
117 'class' => 'namespaceselector',
118 ) ) .
119 Xml::checkLabel(
120 $this->msg( 'allpages-hide-redirects' )->text(),
121 'hideredirects',
122 'hideredirects',
123 $hideredirects
124 ) . ' ' .
125 Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) .
126 "</td>
127 </tr>";
128 $out .= Xml::closeElement( 'table' );
129 $out .= Xml::closeElement( 'fieldset' );
130 $out .= Xml::closeElement( 'form' );
131 $out .= Xml::closeElement( 'div' );
132 return $out;
136 * @param $namespace Integer, default NS_MAIN
137 * @param $prefix String
138 * @param string $from list all pages from this name (default FALSE)
139 * @param bool $hideredirects hide redirects (default FALSE)
141 function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null, $hideredirects = false ) {
142 global $wgContLang;
144 if ( $from === null ) {
145 $from = $prefix;
148 $fromList = $this->getNamespaceKeyAndText( $namespace, $from );
149 $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
150 $namespaces = $wgContLang->getNamespaces();
152 if ( !$prefixList || !$fromList ) {
153 $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock();
154 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
155 // Show errormessage and reset to NS_MAIN
156 $out = $this->msg( 'allpages-bad-ns', $namespace )->parse();
157 $namespace = NS_MAIN;
158 } else {
159 list( $namespace, $prefixKey, $prefix ) = $prefixList;
160 list( /* $fromNS */, $fromKey, ) = $fromList;
162 ### @todo FIXME: Should complain if $fromNs != $namespace
164 $dbr = wfGetDB( DB_SLAVE );
166 $conds = array(
167 'page_namespace' => $namespace,
168 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
169 'page_title >= ' . $dbr->addQuotes( $fromKey ),
172 if ( $hideredirects ) {
173 $conds['page_is_redirect'] = 0;
176 $res = $dbr->select( 'page',
177 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
178 $conds,
179 __METHOD__,
180 array(
181 'ORDER BY' => 'page_title',
182 'LIMIT' => $this->maxPerPage + 1,
183 'USE INDEX' => 'name_title',
187 ### @todo FIXME: Side link to previous
189 $n = 0;
190 if ( $res->numRows() > 0 ) {
191 $out = Xml::openElement( 'table', array( 'id' => 'mw-prefixindex-list-table' ) );
193 while ( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
194 $t = Title::makeTitle( $s->page_namespace, $s->page_title );
195 if ( $t ) {
196 $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
197 Linker::linkKnown(
199 htmlspecialchars( $t->getText() ),
200 $s->page_is_redirect ? array( 'class' => 'mw-redirect' ) : array()
202 ($s->page_is_redirect ? '</div>' : '' );
203 } else {
204 $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
206 if ( $n % 3 == 0 ) {
207 $out .= '<tr>';
209 $out .= "<td>$link</td>";
210 $n++;
211 if ( $n % 3 == 0 ) {
212 $out .= '</tr>';
215 if ( ($n % 3) != 0 ) {
216 $out .= '</tr>';
218 $out .= Xml::closeElement( 'table' );
219 } else {
220 $out = '';
224 $footer = '';
225 if ( $this->including() ) {
226 $out2 = '';
227 } else {
228 $nsForm = $this->namespacePrefixForm( $namespace, $prefix, $hideredirects );
229 $self = $this->getTitle();
230 $out2 = Xml::openElement( 'table', array( 'id' => 'mw-prefixindex-nav-table' ) ) .
231 '<tr>
232 <td>' .
233 $nsForm .
234 '</td>
235 <td id="mw-prefixindex-nav-form" class="mw-prefixindex-nav">';
237 if ( isset( $res ) && $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
238 $query = array(
239 'from' => $s->page_title,
240 'prefix' => $prefix,
241 'hideredirects' => $hideredirects,
244 if ( $namespace || $prefix == '' ) {
245 // Keep the namespace even if it's 0 for empty prefixes.
246 // This tells us we're not just a holdover from old links.
247 $query['namespace'] = $namespace;
249 $nextLink = Linker::linkKnown(
250 $self,
251 $this->msg( 'nextpage', str_replace( '_', ' ', $s->page_title ) )->escaped(),
252 array(),
253 $query
255 $out2 .= $nextLink;
257 $footer = "\n" . Html::element( "hr" )
258 . Html::rawElement( "div", array( "class" => "mw-prefixindex-nav" ), $nextLink );
260 $out2 .= "</td></tr>" .
261 Xml::closeElement( 'table' );
264 $this->getOutput()->addHTML( $out2 . $out . $footer );
267 protected function getGroupName() {
268 return 'pages';