Live hack: Skip some work on empty category/link sets
[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 # Determines, which message describes the input field 'nsfrom', used in function namespaceForm (see superclass SpecialAllpages)
48 var $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, $from, $including = false ) {
55 global $wgOut, $wgUser, $wgContLang;
56
57 $fname = 'indexShowChunk';
58
59 $sk = $wgUser->getSkin();
60
61 $fromTitle = Title::newFromURL( $from );
62 if ($namespace == NS_MAIN and $fromTitle) {
63 $namespace = $fromTitle->getNamespace();
64 }
65
66 $fromKey = is_null( $fromTitle ) ? '' : $fromTitle->getDBkey();
67
68 $dbr =& wfGetDB( DB_SLAVE );
69
70 $res = $dbr->select( 'page',
71 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
72 array(
73 'page_namespace' => $namespace,
74 'page_title LIKE \'' . $dbr->escapeLike( $fromKey ) .'%\''
75 ),
76 $fname,
77 array(
78 'ORDER BY' => 'page_title',
79 'LIMIT' => $this->maxPerPage + 1,
80 'USE INDEX' => 'name_title',
81 )
82 );
83
84 ### FIXME: side link to previous
85
86 $n = 0;
87 $out = '<table style="background: inherit;" border="0" width="100%">';
88
89 $namespaces = $wgContLang->getFormattedNamespaces();
90 while( ($n < $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
91 $t = Title::makeTitle( $s->page_namespace, $s->page_title );
92 if( $t ) {
93 $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
94 $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
95 ($s->page_is_redirect ? '</div>' : '' );
96 } else {
97 $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
98 }
99 if( $n % 3 == 0 ) {
100 $out .= '<tr>';
101 }
102 $out .= "<td>$link</td>";
103 $n++;
104 if( $n % 3 == 0 ) {
105 $out .= '</tr>';
106 }
107 }
108 if( ($n % 3) != 0 ) {
109 $out .= '</tr>';
110 }
111 $out .= '</table>';
112
113 if ( $including ) {
114 $out2 = '';
115 } else {
116 $nsForm = $this->namespaceForm ( $namespace, $from );
117 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
118 $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
119 $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
120 $sk->makeKnownLink( $wgContLang->specialPage( $this->name ),
121 wfMsg ( 'allpages' ) );
122 if ( ($n == $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
123 $namespaceparam = $namespace ? "&namespace=$namespace" : "";
124 $out2 .= " | " . $sk->makeKnownLink(
125 $wgContLang->specialPage( $this->name ),
126 wfMsg ( 'nextpage', $s->page_title ),
127 "from=" . wfUrlEncode ( $s->page_title ) . $namespaceparam );
128 }
129 $out2 .= "</td></tr></table><hr />";
130 }
131
132 $wgOut->addHtml( $out2 . $out );
133 }
134 }
135
136 ?>