3f39cbce673bbda2eda86df2c92dba17dbafd255
[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, $wgContLang;
60
61 $fname = 'indexShowChunk';
62
63 if (!isset($from)) $from = $prefix;
64
65 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
66 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
67
68 if ( !$prefixList || !$fromList ) {
69 $out = wfMsgWikiHtml( 'allpagesbadtitle' );
70 } else {
71 list( $namespace, $prefixKey, $prefix ) = $prefixList;
72 list( $fromNs, $fromKey, $from ) = $fromList;
73
74 ### FIXME: should complain if $fromNs != $namespace
75
76 $dbr =& wfGetDB( DB_SLAVE );
77
78 $res = $dbr->select( 'page',
79 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
80 array(
81 'page_namespace' => $namespace,
82 'page_title LIKE \'' . $dbr->escapeLike( $prefixKey ) .'%\'',
83 'page_title >= ' . $dbr->addQuotes( $fromKey ),
84 ),
85 $fname,
86 array(
87 'ORDER BY' => 'page_title',
88 'LIMIT' => $this->maxPerPage + 1,
89 'USE INDEX' => 'name_title',
90 )
91 );
92
93 ### FIXME: side link to previous
94
95 $n = 0;
96 $out = '<table style="background: inherit;" border="0" width="100%">';
97
98 $namespaces = $wgContLang->getFormattedNamespaces();
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 Linker::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 Linker::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 .= " | " . Linker::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 ?>