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