tab name for discussion page of extra namespace
[lhc/web/wiklou.git] / includes / SpecialPrefixindex.php
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage SpecialPage
5 */
6
7 /**
8 * Entry point : initialise variables and call subfunctions.
9 * @param string $par Becomes "FOO" when called like Special:Prefixindex/FOO (default NULL)
10 */
11
12 require_once 'SpecialAllpages.php';
13
14 function wfSpecialPrefixIndex( $par=NULL, $specialPage ) {
15 global $wgRequest, $wgOut, $wgContLang;
16
17 # GET values
18 $from = $wgRequest->getVal( 'from' );
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', $namespaces[$namespace] ) :
30 wfMsg( 'allarticles' )
31 );
32
33
34 if ( isset($par) ) {
35 $indexPage->showChunk( $namespace, $par, $specialPage->including() );
36 } elseif ( isset($from) ) {
37 $indexPage->showChunk( $namespace, $from, $specialPage->including() );
38 } else {
39 $wgOut->addHtml($indexPage->namespaceForm ( $namespace, $from ));
40 }
41 }
42
43 class SpecialPrefixindex extends SpecialAllpages {
44 var $maxPerPage=960;
45 var $topLevelMax=50;
46 var $name='Prefixindex';
47
48 /**
49 * @param integer $namespace (Default NS_MAIN)
50 * @param string $from list all pages from this name (default FALSE)
51 */
52 function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
53 global $wgOut, $wgUser, $wgContLang;
54
55 $fname = 'indexShowChunk';
56
57 $sk = $wgUser->getSkin();
58
59 $fromTitle = Title::newFromURL( $from );
60 if ($namespace == NS_MAIN and $fromTitle) {
61 $namespace = $fromTitle->getNamespace();
62 }
63
64 $fromKey = is_null( $fromTitle ) ? '' : $fromTitle->getDBkey();
65
66 $dbr =& wfGetDB( DB_SLAVE );
67
68 $res = $dbr->select( 'page',
69 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
70 array(
71 'page_namespace' => $namespace,
72 'page_title LIKE \'' . $dbr->escapeLike( $fromKey ) .'%\''
73 ),
74 $fname,
75 array(
76 'ORDER BY' => 'page_title',
77 'LIMIT' => $this->maxPerPage + 1,
78 'USE INDEX' => 'name_title',
79 )
80 );
81
82 ### FIXME: side link to previous
83
84 $n = 0;
85 $out = '<table style="background: inherit;" border="0" width="100%">';
86
87 $namespaces = $wgContLang->getFormattedNamespaces();
88 while( ($n < $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
89 $t = Title::makeTitle( $s->page_namespace, $s->page_title );
90 if( $t ) {
91 $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
92 $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
93 ($s->page_is_redirect ? '</div>' : '' );
94 } else {
95 $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
96 }
97 if( $n % 3 == 0 ) {
98 $out .= '<tr>';
99 }
100 $out .= "<td>$link</td>";
101 $n++;
102 if( $n % 3 == 0 ) {
103 $out .= '</tr>';
104 }
105 }
106 if( ($n % 3) != 0 ) {
107 $out .= '</tr>';
108 }
109 $out .= '</table>';
110
111 if ( $including ) {
112 $out2 = '';
113 } else {
114 $nsForm = $this->namespaceForm ( $namespace, $from );
115 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
116 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
117 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
118 $sk->makeKnownLink( $wgContLang->specialPage( $this->name ),
119 wfMsg ( 'allpages' ) );
120 if ( ($n == $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
121 $namespaceparam = $namespace ? "&namespace=$namespace" : "";
122 $out2 .= " | " . $sk->makeKnownLink(
123 $wgContLang->specialPage( $this->name ),
124 wfMsg ( 'nextpage', $s->page_title ),
125 "from=" . wfUrlEncode ( $s->page_title ) . $namespaceparam );
126 }
127 $out2 .= "</td></tr></table><hr />";
128 }
129
130 $wgOut->addHtml( $out2 . $out );
131 }
132 }
133
134 ?>