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->showPrefixChunk( $namespace, $par, $specialPage->including(), $from );
30 } elseif ( isset($prefix) ) {
31 $indexPage->showPrefixChunk( $namespace, $prefix, $specialPage->including(), $from );
32 } elseif ( isset($from) ) {
33 $indexPage->showPrefixChunk( $namespace, $from, $specialPage->including(), $from );
35 $wgOut->addHtml( $indexPage->namespacePrefixForm( $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 * HTML for the top form
52 * @param integer $namespace A namespace constant (default NS_MAIN).
53 * @param string $from dbKey we are starting listing at.
55 function namespacePrefixForm( $namespace = NS_MAIN
, $from = '' ) {
57 $t = SpecialPage
::getTitleFor( $this->name
);
59 $out = Xml
::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
60 $out .= Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
61 $out .= Xml
::hidden( 'title', $t->getPrefixedText() );
62 $out .= Xml
::openElement( 'fieldset' );
63 $out .= Xml
::element( 'legend', null, wfMsg( 'allpages' ) );
64 $out .= Xml
::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
66 <td class='mw-label'>" .
67 Xml
::label( wfMsg( 'allpagesfrom' ), 'nsfrom' ) .
69 <td class='mw-input'>" .
70 Xml
::input( 'from', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
74 <td class='mw-label'>" .
75 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
77 <td class='mw-input'>" .
78 Xml
::namespaceSelector( $namespace, null ) . ' ' .
79 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
82 $out .= Xml
::closeElement( 'table' );
83 $out .= Xml
::closeElement( 'fieldset' );
84 $out .= Xml
::closeElement( 'form' );
85 $out .= Xml
::closeElement( 'div' );
90 * @param integer $namespace (Default NS_MAIN)
91 * @param string $from list all pages from this name (default FALSE)
93 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $including = false, $from = null ) {
94 global $wgOut, $wgUser, $wgContLang;
96 $fname = 'indexShowChunk';
98 $sk = $wgUser->getSkin();
100 if (!isset($from)) $from = $prefix;
102 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
103 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
104 $namespaces = $wgContLang->getNamespaces();
105 $align = $wgContLang->isRtl() ?
'left' : 'right';
107 if ( !$prefixList ||
!$fromList ) {
108 $out = wfMsgWikiHtml( 'allpagesbadtitle' );
109 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
110 // Show errormessage and reset to NS_MAIN
111 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
112 $namespace = NS_MAIN
;
114 list( $namespace, $prefixKey, $prefix ) = $prefixList;
115 list( /* $fromNs */, $fromKey, $from ) = $fromList;
117 ### FIXME: should complain if $fromNs != $namespace
119 $dbr = wfGetDB( DB_SLAVE
);
121 $res = $dbr->select( 'page',
122 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
124 'page_namespace' => $namespace,
125 'page_title LIKE \'' . $dbr->escapeLike( $prefixKey ) .'%\'',
126 'page_title >= ' . $dbr->addQuotes( $fromKey ),
130 'ORDER BY' => 'page_title',
131 'LIMIT' => $this->maxPerPage +
1,
132 'USE INDEX' => 'name_title',
136 ### FIXME: side link to previous
139 if( $res->numRows() > 0 ) {
140 $out = '<table style="background: inherit;" border="0" width="100%">';
142 while( ($n < $this->maxPerPage
) && ($s = $dbr->fetchObject( $res )) ) {
143 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
145 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
146 $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
147 ($s->page_is_redirect ?
'</div>' : '' );
149 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
154 $out .= "<td>$link</td>";
160 if( ($n %
3) != 0 ) {
172 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
173 $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
174 $out2 .= '<tr valign="top"><td>' . $nsForm;
175 $out2 .= '</td><td align="' . $align . '" style="font-size: smaller; margin-bottom: 1em;">' .
176 $sk->makeKnownLink( $wgContLang->specialPage( $this->name
),
177 wfMsg ( 'allpages' ) );
178 if ( isset($dbr) && $dbr && ($n == $this->maxPerPage
) && ($s = $dbr->fetchObject( $res )) ) {
179 $namespaceparam = $namespace ?
"&namespace=$namespace" : "";
180 $out2 .= " | " . $sk->makeKnownLink(
181 $wgContLang->specialPage( $this->name
),
182 wfMsgHtml( 'nextpage', htmlspecialchars( $s->page_title
) ),
183 "from=" . wfUrlEncode ( $s->page_title
) .
184 "&prefix=" . wfUrlEncode ( $prefix ) . $namespaceparam );
186 $out2 .= "</td></tr></table><hr />";
189 $wgOut->addHtml( $out2 . $out );