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.
12 function wfSpecialPrefixIndex( $par=NULL, $specialPage ) {
13 global $wgRequest, $wgOut, $wgContLang;
16 $from = $wgRequest->getVal( 'from' );
17 $prefix = $wgRequest->getVal( 'prefix' );
18 $namespace = $wgRequest->getInt( 'namespace' );
19 $namespaces = $wgContLang->getNamespaces();
21 $indexPage = new SpecialPrefixIndex();
23 $wgOut->setPagetitle( ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
24 ?
wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
25 : wfMsg( 'allarticles' )
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 );
35 $wgOut->addHtml($indexPage->namespaceForm ( $namespace, null ));
40 * implements Special:Prefixindex
41 * @ingroup SpecialPage
43 class SpecialPrefixindex
extends SpecialAllpages
{
44 // Inherit $maxPerPage
46 // Define other properties
47 protected $name = 'Prefixindex';
48 protected $nsfromMsg = 'allpagesprefix';
51 * @param integer $namespace (Default NS_MAIN)
52 * @param string $from list all pages from this name (default FALSE)
54 function showChunk( $namespace = NS_MAIN
, $prefix, $including = false, $from = null ) {
55 global $wgOut, $wgUser, $wgContLang;
57 $fname = 'indexShowChunk';
59 $sk = $wgUser->getSkin();
61 if (!isset($from)) $from = $prefix;
63 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
64 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
65 $namespaces = $wgContLang->getNamespaces();
66 $align = $wgContLang->isRtl() ?
'left' : 'right';
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 );
75 list( $namespace, $prefixKey, $prefix ) = $prefixList;
76 list( /* $fromNs */, $fromKey, $from ) = $fromList;
78 ### FIXME: should complain if $fromNs != $namespace
80 $dbr = wfGetDB( DB_SLAVE
);
82 $res = $dbr->select( 'page',
83 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
85 'page_namespace' => $namespace,
86 'page_title LIKE \'' . $dbr->escapeLike( $prefixKey ) .'%\'',
87 'page_title >= ' . $dbr->addQuotes( $fromKey ),
91 'ORDER BY' => 'page_title',
92 'LIMIT' => $this->maxPerPage +
1,
93 'USE INDEX' => 'name_title',
97 ### FIXME: side link to previous
100 if( $res->numRows() > 0 ) {
101 $out = '<table style="background: inherit;" border="0" width="100%">';
103 while( ($n < $this->maxPerPage
) && ($s = $dbr->fetchObject( $res )) ) {
104 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
106 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
107 $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
108 ($s->page_is_redirect ?
'</div>' : '' );
110 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
115 $out .= "<td>$link</td>";
121 if( ($n %
3) != 0 ) {
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 );
147 $out2 .= "</td></tr></table><hr />";
150 $wgOut->addHtml( $out2 . $out );