00001 <?php
00002
00007 class SpecialPrefixindex extends SpecialAllpages {
00008
00009
00010 function __construct(){
00011 parent::__construct( 'Prefixindex' );
00012 }
00013
00018 function execute( $par ) {
00019 global $wgRequest, $wgOut, $wgContLang;
00020
00021 $this->setHeaders();
00022 $this->outputHeader();
00023
00024 # GET values
00025 $from = $wgRequest->getVal( 'from' );
00026 $prefix = $wgRequest->getVal( 'prefix', '' );
00027 $namespace = $wgRequest->getInt( 'namespace' );
00028 $namespaces = $wgContLang->getNamespaces();
00029
00030 $wgOut->setPagetitle( ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
00031 ? wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
00032 : wfMsg( 'prefixindex' )
00033 );
00034
00035 if( isset( $par ) ){
00036 $this->showPrefixChunk( $namespace, $par, $from );
00037 } elseif( isset( $prefix ) ){
00038 $this->showPrefixChunk( $namespace, $prefix, $from );
00039 } elseif( isset( $from ) ){
00040 $this->showPrefixChunk( $namespace, $from, $from );
00041 } else {
00042 $wgOut->addHTML( $this->namespacePrefixForm( $namespace, null ) );
00043 }
00044 }
00045
00051 function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) {
00052 global $wgScript;
00053 $t = $this->getTitle();
00054
00055 $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
00056 $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
00057 $out .= Xml::hidden( 'title', $t->getPrefixedText() );
00058 $out .= Xml::openElement( 'fieldset' );
00059 $out .= Xml::element( 'legend', null, wfMsg( 'allpages' ) );
00060 $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
00061 $out .= "<tr>
00062 <td class='mw-label'>" .
00063 Xml::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
00064 "</td>
00065 <td class='mw-input'>" .
00066 Xml::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
00067 "</td>
00068 </tr>
00069 <tr>
00070 <td class='mw-label'>" .
00071 Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
00072 "</td>
00073 <td class='mw-input'>" .
00074 Xml::namespaceSelector( $namespace, null ) . ' ' .
00075 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
00076 "</td>
00077 </tr>";
00078 $out .= Xml::closeElement( 'table' );
00079 $out .= Xml::closeElement( 'fieldset' );
00080 $out .= Xml::closeElement( 'form' );
00081 $out .= Xml::closeElement( 'div' );
00082 return $out;
00083 }
00084
00089 function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) {
00090 global $wgOut, $wgUser, $wgContLang, $wgLang;
00091
00092 $sk = $wgUser->getSkin();
00093
00094 if (!isset($from)) $from = $prefix;
00095
00096 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
00097 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
00098 $namespaces = $wgContLang->getNamespaces();
00099
00100 if ( !$prefixList || !$fromList ) {
00101 $out = wfMsgWikiHtml( 'allpagesbadtitle' );
00102 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
00103
00104 $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
00105 $namespace = NS_MAIN;
00106 } else {
00107 list( $namespace, $prefixKey, $prefix ) = $prefixList;
00108 list( , $fromKey, $from ) = $fromList;
00109
00110 ### FIXME: should complain if $fromNs != $namespace
00111
00112 $dbr = wfGetDB( DB_SLAVE );
00113
00114 $res = $dbr->select( 'page',
00115 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
00116 array(
00117 'page_namespace' => $namespace,
00118 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
00119 'page_title >= ' . $dbr->addQuotes( $fromKey ),
00120 ),
00121 __METHOD__,
00122 array(
00123 'ORDER BY' => 'page_title',
00124 'LIMIT' => $this->maxPerPage + 1,
00125 'USE INDEX' => 'name_title',
00126 )
00127 );
00128
00129 ### FIXME: side link to previous
00130
00131 $n = 0;
00132 if( $res->numRows() > 0 ) {
00133 $out = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
00134
00135 while( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
00136 $t = Title::makeTitle( $s->page_namespace, $s->page_title );
00137 if( $t ) {
00138 $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
00139 $sk->linkKnown(
00140 $t,
00141 htmlspecialchars( $t->getText() )
00142 ) .
00143 ($s->page_is_redirect ? '</div>' : '' );
00144 } else {
00145 $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
00146 }
00147 if( $n % 3 == 0 ) {
00148 $out .= '<tr>';
00149 }
00150 $out .= "<td>$link</td>";
00151 $n++;
00152 if( $n % 3 == 0 ) {
00153 $out .= '</tr>';
00154 }
00155 }
00156 if( ($n % 3) != 0 ) {
00157 $out .= '</tr>';
00158 }
00159 $out .= Xml::closeElement( 'table' );
00160 } else {
00161 $out = '';
00162 }
00163 }
00164
00165 if ( $this->including() ) {
00166 $out2 = '';
00167 } else {
00168 $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
00169 $self = $this->getTitle();
00170 $out2 = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
00171 '<tr>
00172 <td>' .
00173 $nsForm .
00174 '</td>
00175 <td id="mw-prefixindex-nav-form">' .
00176 $sk->linkKnown( $self, wfMsgHtml( 'allpages' ) );
00177
00178 if( isset( $res ) && $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
00179 $query = array(
00180 'from' => $s->page_title,
00181 'prefix' => $prefix
00182 );
00183
00184 if( $namespace ) {
00185 $query['namespace'] = $namespace;
00186 }
00187
00188 $out2 = $wgLang->pipeList( array(
00189 $out2,
00190 $sk->linkKnown(
00191 $self,
00192 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title ) ) ),
00193 array(),
00194 $query
00195 )
00196 ) );
00197 }
00198 $out2 .= "</td></tr>" .
00199 Xml::closeElement( 'table' );
00200 }
00201
00202 $wgOut->addHTML( $out2 . $out );
00203 }
00204 }