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