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