MediaWiki  REL1_19
SpecialPrefixindex.php
Go to the documentation of this file.
00001 <?php
00029 class SpecialPrefixindex extends SpecialAllpages {
00030         // Inherit $maxPerPage
00031 
00032         function __construct(){
00033                 parent::__construct( 'Prefixindex' );
00034         }
00035 
00040         function execute( $par ) {
00041                 global $wgContLang;
00042 
00043                 $this->setHeaders();
00044                 $this->outputHeader();
00045 
00046                 $out = $this->getOutput();
00047                 $out->addModuleStyles( 'mediawiki.special' );
00048 
00049                 # GET values
00050                 $request = $this->getRequest();
00051                 $from = $request->getVal( 'from', '' );
00052                 $prefix = $request->getVal( 'prefix', '' );
00053                 $ns = $request->getIntOrNull( 'namespace' );
00054                 $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN).
00055 
00056                 $namespaces = $wgContLang->getNamespaces();
00057                 $out->setPageTitle(
00058                         ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
00059                                 ? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
00060                                 : $this->msg( 'prefixindex' )
00061                 );
00062 
00063                 $showme = '';
00064                 if( isset( $par ) ) {
00065                         $showme = $par;
00066                 } elseif( $prefix != '' ) {
00067                         $showme = $prefix;
00068                 } elseif( $from != '' && $ns === null ) {
00069                         // For back-compat with Special:Allpages
00070                         // Don't do this if namespace is passed, so paging works when doing NS views.
00071                         $showme = $from;
00072                 }
00073 
00074                 // Bug 27864: if transcluded, show all pages instead of the form.
00075                 if ( $this->including() || $showme != '' || $ns !== null ) {
00076                         $this->showPrefixChunk( $namespace, $showme, $from );
00077                 } else {
00078                         $out->addHTML( $this->namespacePrefixForm( $namespace, null ) );
00079                 }
00080         }
00081 
00087         function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) {
00088                 global $wgScript;
00089 
00090                 $out  = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
00091                 $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
00092                 $out .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() );
00093                 $out .= Xml::openElement( 'fieldset' );
00094                 $out .= Xml::element( 'legend', null, wfMsg( 'allpages' ) );
00095                 $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
00096                 $out .= "<tr>
00097                                 <td class='mw-label'>" .
00098                                 Xml::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
00099                                 "</td>
00100                                 <td class='mw-input'>" .
00101                                         Xml::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
00102                                 "</td>
00103                         </tr>
00104                         <tr>
00105                                 <td class='mw-label'>" .
00106                                         Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
00107                                 "</td>
00108                                 <td class='mw-input'>" .
00109                                         Xml::namespaceSelector( $namespace, null ) . ' ' .
00110                                         Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
00111                                 "</td>
00112                                 </tr>";
00113                 $out .= Xml::closeElement( 'table' );
00114                 $out .= Xml::closeElement( 'fieldset' );
00115                 $out .= Xml::closeElement( 'form' );
00116                 $out .= Xml::closeElement( 'div' );
00117                 return $out;
00118         }
00119 
00125         function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) {
00126                 global $wgContLang;
00127 
00128                 if ( $from === null ) {
00129                         $from = $prefix;
00130                 }
00131 
00132                 $fromList = $this->getNamespaceKeyAndText($namespace, $from);
00133                 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
00134                 $namespaces = $wgContLang->getNamespaces();
00135 
00136                 if ( !$prefixList || !$fromList ) {
00137                         $out = wfMsgExt( 'allpagesbadtitle', 'parse' );
00138                 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
00139                         // Show errormessage and reset to NS_MAIN
00140                         $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
00141                         $namespace = NS_MAIN;
00142                 } else {
00143                         list( $namespace, $prefixKey, $prefix ) = $prefixList;
00144                         list( /* $fromNS */, $fromKey, ) = $fromList;
00145 
00146                         ### @todo FIXME: Should complain if $fromNs != $namespace
00147 
00148                         $dbr = wfGetDB( DB_SLAVE );
00149 
00150                         $res = $dbr->select( 'page',
00151                                 array( 'page_namespace', 'page_title', 'page_is_redirect' ),
00152                                 array(
00153                                         'page_namespace' => $namespace,
00154                                         'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
00155                                         'page_title >= ' . $dbr->addQuotes( $fromKey ),
00156                                 ),
00157                                 __METHOD__,
00158                                 array(
00159                                         'ORDER BY'  => 'page_title',
00160                                         'LIMIT'     => $this->maxPerPage + 1,
00161                                         'USE INDEX' => 'name_title',
00162                                 )
00163                         );
00164 
00165                         ### @todo FIXME: Side link to previous
00166 
00167                         $n = 0;
00168                         if( $res->numRows() > 0 ) {
00169                                 $out = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
00170 
00171                                 while( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
00172                                         $t = Title::makeTitle( $s->page_namespace, $s->page_title );
00173                                         if( $t ) {
00174                                                 $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
00175                                                         Linker::linkKnown(
00176                                                                 $t,
00177                                                                 htmlspecialchars( $t->getText() )
00178                                                         ) .
00179                                                         ($s->page_is_redirect ? '</div>' : '' );
00180                                         } else {
00181                                                 $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
00182                                         }
00183                                         if( $n % 3 == 0 ) {
00184                                                 $out .= '<tr>';
00185                                         }
00186                                         $out .= "<td>$link</td>";
00187                                         $n++;
00188                                         if( $n % 3 == 0 ) {
00189                                                 $out .= '</tr>';
00190                                         }
00191                                 }
00192                                 if( ($n % 3) != 0 ) {
00193                                         $out .= '</tr>';
00194                                 }
00195                                 $out .= Xml::closeElement( 'table' );
00196                         } else {
00197                                 $out = '';
00198                         }
00199                 }
00200 
00201                 $footer = '';
00202                 if ( $this->including() ) {
00203                         $out2 = '';
00204                 } else {
00205                         $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
00206                         $self = $this->getTitle();
00207                         $out2 = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) )  .
00208                                 '<tr>
00209                                         <td>' .
00210                                                 $nsForm .
00211                                         '</td>
00212                                         <td id="mw-prefixindex-nav-form" class="mw-prefixindex-nav">';
00213 
00214                         if( isset( $res ) && $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
00215                                 $query = array(
00216                                         'from' => $s->page_title,
00217                                         'prefix' => $prefix
00218                                 );
00219 
00220                                 if( $namespace || ($prefix == '')) {
00221                                         // Keep the namespace even if it's 0 for empty prefixes.
00222                                         // This tells us we're not just a holdover from old links.
00223                                         $query['namespace'] = $namespace;
00224                                 }
00225                                 $nextLink = Linker::linkKnown(
00226                                                 $self,
00227                                                 wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title ) ) ),
00228                                                 array(),
00229                                                 $query
00230                                         );
00231                                 $out2 .= $nextLink;
00232 
00233                                 $footer = "\n" . Html::element( "hr" )
00234                                         . Html::rawElement( "div", array( "class" => "mw-prefixindex-nav" ), $nextLink );
00235                         }
00236                         $out2 .= "</td></tr>" .
00237                                 Xml::closeElement( 'table' );
00238                 }
00239 
00240                 $this->getOutput()->addHTML( $out2 . $out . $footer );
00241         }
00242 }