]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialPrefixindex.php
MediaWiki 1.15.4-scripts
[autoinstallsdev/mediawiki.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 integer $namespace A namespace constant (default NS_MAIN).
49         * @param string $from 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( 'from', 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 integer $namespace (Default NS_MAIN)
87          * @param string $from list all pages from this name (default FALSE)
88          */
89         function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) {
90                 global $wgOut, $wgUser, $wgContLang, $wgLang;
91
92                 $sk = $wgUser->getSkin();
93
94                 if (!isset($from)) $from = $prefix;
95
96                 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
97                 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
98                 $namespaces = $wgContLang->getNamespaces();
99
100                 if ( !$prefixList || !$fromList ) {
101                         $out = wfMsgWikiHtml( 'allpagesbadtitle' );
102                 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
103                         // Show errormessage and reset to NS_MAIN
104                         $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
105                         $namespace = NS_MAIN;
106                 } else {
107                         list( $namespace, $prefixKey, $prefix ) = $prefixList;
108                         list( /* $fromNs */, $fromKey, $from ) = $fromList;
109
110                         ### FIXME: should complain if $fromNs != $namespace
111
112                         $dbr = wfGetDB( DB_SLAVE );
113
114                         $res = $dbr->select( 'page',
115                                 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
116                                 array(
117                                         'page_namespace' => $namespace,
118                                         'page_title LIKE \'' . $dbr->escapeLike( $prefixKey ) .'%\'',
119                                         'page_title >= ' . $dbr->addQuotes( $fromKey ),
120                                 ),
121                                 __METHOD__,
122                                 array(
123                                         'ORDER BY'  => 'page_title',
124                                         'LIMIT'     => $this->maxPerPage + 1,
125                                         'USE INDEX' => 'name_title',
126                                 )
127                         );
128
129                         ### FIXME: side link to previous
130
131                         $n = 0;
132                         if( $res->numRows() > 0 ) {
133                                 $out = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
134         
135                                 while( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
136                                         $t = Title::makeTitle( $s->page_namespace, $s->page_title );
137                                         if( $t ) {
138                                                 $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
139                                                         $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
140                                                         ($s->page_is_redirect ? '</div>' : '' );
141                                         } else {
142                                                 $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
143                                         }
144                                         if( $n % 3 == 0 ) {
145                                                 $out .= '<tr>';
146                                         }
147                                         $out .= "<td>$link</td>";
148                                         $n++;
149                                         if( $n % 3 == 0 ) {
150                                                 $out .= '</tr>';
151                                         }
152                                 }
153                                 if( ($n % 3) != 0 ) {
154                                         $out .= '</tr>';
155                                 }
156                                 $out .= Xml::closeElement( 'table' );
157                         } else {
158                                 $out = '';
159                         }
160                 }
161
162                 if ( $this->including() ) {
163                         $out2 = '';
164                 } else {
165                         $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
166                         $self = $this->getTitle();
167                         $out2 = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) )  .
168                                 '<tr>
169                                         <td>' .
170                                                 $nsForm .
171                                         '</td>
172                                         <td id="mw-prefixindex-nav-form">' .
173                                                 $sk->makeKnownLinkObj( $self, wfMsg ( 'allpages' ) );
174
175                         if( isset( $res ) && $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
176                                 $namespaceparam = $namespace ? "&namespace=$namespace" : "";
177                                 $out2 = $wgLang->pipeList( array(
178                                         $out2,
179                                         $sk->makeKnownLinkObj(
180                                                 $self,
181                                                 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title ) ) ),
182                                                 "from=" . wfUrlEncode( $s->page_title ) .
183                                                 "&prefix=" . wfUrlEncode( $prefix ) . $namespaceparam )
184                                 ) );
185                         }
186                         $out2 .= "</td></tr>" .
187                                 Xml::closeElement( 'table' );
188                 }
189
190                 $wgOut->addHTML( $out2 . $out );
191         }
192 }