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