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