4 * implements Special:Prefixindex
7 class SpecialPrefixindex
extends SpecialAllpages
{
10 function __construct(){
11 parent
::__construct( 'Prefixindex' );
15 * Entry point : initialise variables and call subfunctions.
16 * @param $par String: becomes "FOO" when called like Special:Prefixindex/FOO (default null)
18 function execute( $par ) {
19 global $wgRequest, $wgOut, $wgContLang;
22 $this->outputHeader();
25 $from = $wgRequest->getVal( 'from' );
26 $prefix = $wgRequest->getVal( 'prefix' );
27 $namespace = $wgRequest->getInt( 'namespace' );
28 $namespaces = $wgContLang->getNamespaces();
30 $wgOut->setPagetitle( ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
31 ?
wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
32 : wfMsg( 'prefixindex' )
36 $this->showPrefixChunk( $namespace, $par, $from );
37 } elseif( isset( $prefix ) ){
38 $this->showPrefixChunk( $namespace, $prefix, $from );
39 } elseif( isset( $from ) ){
40 $this->showPrefixChunk( $namespace, $from, $from );
42 $wgOut->addHTML( $this->namespacePrefixForm( $namespace, null ) );
47 * HTML for the top form
48 * @param integer $namespace A namespace constant (default NS_MAIN).
49 * @param string $from dbKey we are starting listing at.
51 function namespacePrefixForm( $namespace = NS_MAIN
, $from = '' ) {
53 $t = $this->getTitle();
55 $out = Xml
::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
56 $out .= Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
57 $out .= Xml
::hidden( 'title', $t->getPrefixedText() );
58 $out .= Xml
::openElement( 'fieldset' );
59 $out .= Xml
::element( 'legend', null, wfMsg( 'allpages' ) );
60 $out .= Xml
::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
62 <td class='mw-label'>" .
63 Xml
::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
65 <td class='mw-input'>" .
66 Xml
::input( 'from', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
70 <td class='mw-label'>" .
71 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
73 <td class='mw-input'>" .
74 Xml
::namespaceSelector( $namespace, null ) . ' ' .
75 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
78 $out .= Xml
::closeElement( 'table' );
79 $out .= Xml
::closeElement( 'fieldset' );
80 $out .= Xml
::closeElement( 'form' );
81 $out .= Xml
::closeElement( 'div' );
86 * @param integer $namespace (Default NS_MAIN)
87 * @param string $from list all pages from this name (default FALSE)
89 function showPrefixChunk( $namespace = NS_MAIN
, $prefix, $from = null ) {
90 global $wgOut, $wgUser, $wgContLang, $wgLang;
92 $sk = $wgUser->getSkin();
94 if (!isset($from)) $from = $prefix;
96 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
97 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
98 $namespaces = $wgContLang->getNamespaces();
100 if ( !$prefixList ||
!$fromList ) {
101 $out = wfMsgWikiHtml( 'allpagesbadtitle' );
102 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
103 // Show errormessage and reset to NS_MAIN
104 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
105 $namespace = NS_MAIN
;
107 list( $namespace, $prefixKey, $prefix ) = $prefixList;
108 list( /* $fromNs */, $fromKey, $from ) = $fromList;
110 ### FIXME: should complain if $fromNs != $namespace
112 $dbr = wfGetDB( DB_SLAVE
);
114 $res = $dbr->select( 'page',
115 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
117 'page_namespace' => $namespace,
118 'page_title LIKE \'' . $dbr->escapeLike( $prefixKey ) .'%\'',
119 'page_title >= ' . $dbr->addQuotes( $fromKey ),
123 'ORDER BY' => 'page_title',
124 'LIMIT' => $this->maxPerPage +
1,
125 'USE INDEX' => 'name_title',
129 ### FIXME: side link to previous
132 if( $res->numRows() > 0 ) {
133 $out = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
135 while( ( $n < $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
136 $t = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
138 $link = ($s->page_is_redirect ?
'<div class="allpagesredirect">' : '' ) .
139 $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
140 ($s->page_is_redirect ?
'</div>' : '' );
142 $link = '[[' . htmlspecialchars( $s->page_title
) . ']]';
147 $out .= "<td>$link</td>";
153 if( ($n %
3) != 0 ) {
156 $out .= Xml
::closeElement( 'table' );
162 if ( $this->including() ) {
165 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
166 $self = $this->getTitle();
167 $out2 = Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
172 <td id="mw-prefixindex-nav-form">' .
173 $sk->makeKnownLinkObj( $self, wfMsg ( 'allpages' ) );
175 if( isset( $res ) && $res && ( $n == $this->maxPerPage
) && ( $s = $res->fetchObject() ) ) {
176 $namespaceparam = $namespace ?
"&namespace=$namespace" : "";
177 $out2 = $wgLang->pipeList( array(
179 $sk->makeKnownLinkObj(
181 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title
) ) ),
182 "from=" . wfUrlEncode( $s->page_title
) .
183 "&prefix=" . wfUrlEncode( $prefix ) . $namespaceparam )
186 $out2 .= "</td></tr>" .
187 Xml
::closeElement( 'table' );
190 $wgOut->addHTML( $out2 . $out );