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