MediaWiki
REL1_20
|
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 $hideredirects = $request->getBool( 'hideredirects', false ); 00056 00057 $namespaces = $wgContLang->getNamespaces(); 00058 $out->setPageTitle( 00059 ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) ) 00060 ? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) ) 00061 : $this->msg( 'prefixindex' ) 00062 ); 00063 00064 $showme = ''; 00065 if( isset( $par ) ) { 00066 $showme = $par; 00067 } elseif( $prefix != '' ) { 00068 $showme = $prefix; 00069 } elseif( $from != '' && $ns === null ) { 00070 // For back-compat with Special:Allpages 00071 // Don't do this if namespace is passed, so paging works when doing NS views. 00072 $showme = $from; 00073 } 00074 00075 // Bug 27864: if transcluded, show all pages instead of the form. 00076 if ( $this->including() || $showme != '' || $ns !== null ) { 00077 $this->showPrefixChunk( $namespace, $showme, $from, $hideredirects ); 00078 } else { 00079 $out->addHTML( $this->namespacePrefixForm( $namespace, null, $hideredirects ) ); 00080 } 00081 } 00082 00090 function namespacePrefixForm( $namespace = NS_MAIN, $from = '', $hideredirects = false ) { 00091 global $wgScript; 00092 00093 $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) ); 00094 $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); 00095 $out .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ); 00096 $out .= Xml::openElement( 'fieldset' ); 00097 $out .= Xml::element( 'legend', null, $this->msg( 'allpages' )->text() ); 00098 $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) ); 00099 $out .= "<tr> 00100 <td class='mw-label'>" . 00101 Xml::label( $this->msg( 'allpagesprefix' )->text(), 'nsfrom' ) . 00102 "</td> 00103 <td class='mw-input'>" . 00104 Xml::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) . 00105 "</td> 00106 </tr> 00107 <tr> 00108 <td class='mw-label'>" . 00109 Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) . 00110 "</td> 00111 <td class='mw-input'>" . 00112 Html::namespaceSelector( array( 00113 'selected' => $namespace, 00114 ), array( 00115 'name' => 'namespace', 00116 'id' => 'namespace', 00117 'class' => 'namespaceselector', 00118 ) ) . 00119 Xml::checkLabel( 00120 $this->msg( 'allpages-hide-redirects' )->text(), 00121 'hideredirects', 00122 'hideredirects', 00123 $hideredirects 00124 ) . ' ' . 00125 Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . 00126 "</td> 00127 </tr>"; 00128 $out .= Xml::closeElement( 'table' ); 00129 $out .= Xml::closeElement( 'fieldset' ); 00130 $out .= Xml::closeElement( 'form' ); 00131 $out .= Xml::closeElement( 'div' ); 00132 return $out; 00133 } 00134 00141 function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null, $hideredirects = false ) { 00142 global $wgContLang; 00143 00144 if ( $from === null ) { 00145 $from = $prefix; 00146 } 00147 00148 $fromList = $this->getNamespaceKeyAndText($namespace, $from); 00149 $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix); 00150 $namespaces = $wgContLang->getNamespaces(); 00151 00152 if ( !$prefixList || !$fromList ) { 00153 $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock(); 00154 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) { 00155 // Show errormessage and reset to NS_MAIN 00156 $out = $this->msg( 'allpages-bad-ns', $namespace )->parse(); 00157 $namespace = NS_MAIN; 00158 } else { 00159 list( $namespace, $prefixKey, $prefix ) = $prefixList; 00160 list( /* $fromNS */, $fromKey, ) = $fromList; 00161 00162 ### @todo FIXME: Should complain if $fromNs != $namespace 00163 00164 $dbr = wfGetDB( DB_SLAVE ); 00165 00166 $conds = array( 00167 'page_namespace' => $namespace, 00168 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ), 00169 'page_title >= ' . $dbr->addQuotes( $fromKey ), 00170 ); 00171 00172 if ( $hideredirects ) { 00173 $conds['page_is_redirect'] = 0; 00174 } 00175 00176 $res = $dbr->select( 'page', 00177 array( 'page_namespace', 'page_title', 'page_is_redirect' ), 00178 $conds, 00179 __METHOD__, 00180 array( 00181 'ORDER BY' => 'page_title', 00182 'LIMIT' => $this->maxPerPage + 1, 00183 'USE INDEX' => 'name_title', 00184 ) 00185 ); 00186 00187 ### @todo FIXME: Side link to previous 00188 00189 $n = 0; 00190 if( $res->numRows() > 0 ) { 00191 $out = Xml::openElement( 'table', array( 'id' => 'mw-prefixindex-list-table' ) ); 00192 00193 while( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) { 00194 $t = Title::makeTitle( $s->page_namespace, $s->page_title ); 00195 if( $t ) { 00196 $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) . 00197 Linker::linkKnown( 00198 $t, 00199 htmlspecialchars( $t->getText() ), 00200 $s->page_is_redirect ? array( 'class' => 'mw-redirect' ) : array() 00201 ) . 00202 ($s->page_is_redirect ? '</div>' : '' ); 00203 } else { 00204 $link = '[[' . htmlspecialchars( $s->page_title ) . ']]'; 00205 } 00206 if( $n % 3 == 0 ) { 00207 $out .= '<tr>'; 00208 } 00209 $out .= "<td>$link</td>"; 00210 $n++; 00211 if( $n % 3 == 0 ) { 00212 $out .= '</tr>'; 00213 } 00214 } 00215 if( ($n % 3) != 0 ) { 00216 $out .= '</tr>'; 00217 } 00218 $out .= Xml::closeElement( 'table' ); 00219 } else { 00220 $out = ''; 00221 } 00222 } 00223 00224 $footer = ''; 00225 if ( $this->including() ) { 00226 $out2 = ''; 00227 } else { 00228 $nsForm = $this->namespacePrefixForm( $namespace, $prefix, $hideredirects ); 00229 $self = $this->getTitle(); 00230 $out2 = Xml::openElement( 'table', array( 'id' => 'mw-prefixindex-nav-table' ) ) . 00231 '<tr> 00232 <td>' . 00233 $nsForm . 00234 '</td> 00235 <td id="mw-prefixindex-nav-form" class="mw-prefixindex-nav">'; 00236 00237 if( isset( $res ) && $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) { 00238 $query = array( 00239 'from' => $s->page_title, 00240 'prefix' => $prefix, 00241 'hideredirects' => $hideredirects, 00242 ); 00243 00244 if( $namespace || ($prefix == '')) { 00245 // Keep the namespace even if it's 0 for empty prefixes. 00246 // This tells us we're not just a holdover from old links. 00247 $query['namespace'] = $namespace; 00248 } 00249 $nextLink = Linker::linkKnown( 00250 $self, 00251 $this->msg( 'nextpage', str_replace( '_',' ', $s->page_title ) )->escaped(), 00252 array(), 00253 $query 00254 ); 00255 $out2 .= $nextLink; 00256 00257 $footer = "\n" . Html::element( "hr" ) 00258 . Html::rawElement( "div", array( "class" => "mw-prefixindex-nav" ), $nextLink ); 00259 } 00260 $out2 .= "</td></tr>" . 00261 Xml::closeElement( 'table' ); 00262 } 00263 00264 $this->getOutput()->addHTML( $out2 . $out . $footer ); 00265 } 00266 }