Prevent some unnecessary lstat system calls, generated by include or require directives.
[lhc/web/wiklou.git] / includes / SpecialPrefixindex.php
1 <?php
2 /**
3 * @addtogroup SpecialPage
4 */
5
6 /**
7 * Entry point : initialise variables and call subfunctions.
8 * @param $par String: becomes "FOO" when called like Special:Prefixindex/FOO (default NULL)
9 * @param $specialPage SpecialPage object.
10 */
11 function wfSpecialPrefixIndex( $par=NULL, $specialPage ) {
12 global $wgRequest, $wgOut, $wgContLang;
13
14 # GET values
15 $from = $wgRequest->getVal( 'from' );
16 $prefix = $wgRequest->getVal( 'prefix' );
17 $namespace = $wgRequest->getInt( 'namespace' );
18
19 $namespaces = $wgContLang->getNamespaces();
20
21 $indexPage = new SpecialPrefixIndex();
22
23 if( !in_array($namespace, array_keys($namespaces)) )
24 $namespace = 0;
25
26 $wgOut->setPagetitle( $namespace > 0 ?
27 wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) ) :
28 wfMsg( 'allarticles' )
29 );
30
31
32
33 if ( isset($par) ) {
34 $indexPage->showChunk( $namespace, $par, $specialPage->including(), $from );
35 } elseif ( isset($prefix) ) {
36 $indexPage->showChunk( $namespace, $prefix, $specialPage->including(), $from );
37 } elseif ( isset($from) ) {
38 $indexPage->showChunk( $namespace, $from, $specialPage->including(), $from );
39 } else {
40 $wgOut->addHtml($indexPage->namespaceForm ( $namespace, null ));
41 }
42 }
43
44 class SpecialPrefixindex extends SpecialAllpages {
45 var $maxPerPage=960;
46 var $topLevelMax=50;
47 var $name='Prefixindex';
48 # Determines, which message describes the input field 'nsfrom', used in function namespaceForm (see superclass SpecialAllpages)
49 var $nsfromMsg='allpagesprefix';
50
51 /**
52 * @param integer $namespace (Default NS_MAIN)
53 * @param string $from list all pages from this name (default FALSE)
54 */
55 function showChunk( $namespace = NS_MAIN, $prefix, $including = false, $from = null ) {
56 global $wgOut, $wgUser, $wgContLang;
57
58 $fname = 'indexShowChunk';
59
60 $sk = $wgUser->getSkin();
61
62 if (!isset($from)) $from = $prefix;
63
64 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
65 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
66
67 if ( !$prefixList || !$fromList ) {
68 $out = wfMsgWikiHtml( 'allpagesbadtitle' );
69 } else {
70 list( $namespace, $prefixKey, $prefix ) = $prefixList;
71 list( /* $fromNs */, $fromKey, $from ) = $fromList;
72
73 ### FIXME: should complain if $fromNs != $namespace
74
75 $dbr = wfGetDB( DB_SLAVE );
76
77 $res = $dbr->select( 'page',
78 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
79 array(
80 'page_namespace' => $namespace,
81 'page_title LIKE \'' . $dbr->escapeLike( $prefixKey ) .'%\'',
82 'page_title >= ' . $dbr->addQuotes( $fromKey ),
83 ),
84 $fname,
85 array(
86 'ORDER BY' => 'page_title',
87 'LIMIT' => $this->maxPerPage + 1,
88 'USE INDEX' => 'name_title',
89 )
90 );
91
92 ### FIXME: side link to previous
93
94 $n = 0;
95 $out = '<table style="background: inherit;" border="0" width="100%">';
96
97 while( ($n < $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
98 $t = Title::makeTitle( $s->page_namespace, $s->page_title );
99 if( $t ) {
100 $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
101 $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
102 ($s->page_is_redirect ? '</div>' : '' );
103 } else {
104 $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
105 }
106 if( $n % 3 == 0 ) {
107 $out .= '<tr>';
108 }
109 $out .= "<td>$link</td>";
110 $n++;
111 if( $n % 3 == 0 ) {
112 $out .= '</tr>';
113 }
114 }
115 if( ($n % 3) != 0 ) {
116 $out .= '</tr>';
117 }
118 $out .= '</table>';
119 }
120
121 if ( $including ) {
122 $out2 = '';
123 } else {
124 $nsForm = $this->namespaceForm ( $namespace, $prefix );
125 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
126 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
127 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
128 $sk->makeKnownLink( $wgContLang->specialPage( $this->name ),
129 wfMsg ( 'allpages' ) );
130 if ( isset($dbr) && $dbr && ($n == $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
131 $namespaceparam = $namespace ? "&namespace=$namespace" : "";
132 $out2 .= " | " . $sk->makeKnownLink(
133 $wgContLang->specialPage( $this->name ),
134 wfMsg ( 'nextpage', $s->page_title ),
135 "from=" . wfUrlEncode ( $s->page_title ) .
136 "&prefix=" . wfUrlEncode ( $prefix ) . $namespaceparam );
137 }
138 $out2 .= "</td></tr></table><hr />";
139 }
140
141 $wgOut->addHtml( $out2 . $out );
142 }
143 }
144
145 ?>