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