MediaWiki
REL1_22
|
00001 <?php 00029 class SpecialPrefixindex extends SpecialAllpages { 00030 00035 protected $stripPrefix = false; 00036 00037 protected $hideRedirects = false; 00038 00039 // Inherit $maxPerPage 00040 00041 function __construct() { 00042 parent::__construct( 'Prefixindex' ); 00043 } 00044 00049 function execute( $par ) { 00050 global $wgContLang; 00051 00052 $this->setHeaders(); 00053 $this->outputHeader(); 00054 00055 $out = $this->getOutput(); 00056 $out->addModuleStyles( 'mediawiki.special' ); 00057 00058 # GET values 00059 $request = $this->getRequest(); 00060 $from = $request->getVal( 'from', '' ); 00061 $prefix = $request->getVal( 'prefix', '' ); 00062 $ns = $request->getIntOrNull( 'namespace' ); 00063 $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN). 00064 $this->hideRedirects = $request->getBool( 'hideredirects', $this->hideRedirects ); 00065 $this->stripPrefix = $request->getBool( 'stripprefix', $this->stripPrefix ); 00066 00067 $namespaces = $wgContLang->getNamespaces(); 00068 $out->setPageTitle( 00069 ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) ) 00070 ? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) ) 00071 : $this->msg( 'prefixindex' ) 00072 ); 00073 00074 $showme = ''; 00075 if ( isset( $par ) ) { 00076 $showme = $par; 00077 } elseif ( $prefix != '' ) { 00078 $showme = $prefix; 00079 } elseif ( $from != '' && $ns === null ) { 00080 // For back-compat with Special:Allpages 00081 // Don't do this if namespace is passed, so paging works when doing NS views. 00082 $showme = $from; 00083 } 00084 00085 // Bug 27864: if transcluded, show all pages instead of the form. 00086 if ( $this->including() || $showme != '' || $ns !== null ) { 00087 $this->showPrefixChunk( $namespace, $showme, $from ); 00088 } else { 00089 $out->addHTML( $this->namespacePrefixForm( $namespace, null ) ); 00090 } 00091 } 00092 00099 protected function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) { 00100 global $wgScript; 00101 00102 $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) ); 00103 $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); 00104 $out .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ); 00105 $out .= Xml::openElement( 'fieldset' ); 00106 $out .= Xml::element( 'legend', null, $this->msg( 'allpages' )->text() ); 00107 $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) ); 00108 $out .= "<tr> 00109 <td class='mw-label'>" . 00110 Xml::label( $this->msg( 'allpagesprefix' )->text(), 'nsfrom' ) . 00111 "</td> 00112 <td class='mw-input'>" . 00113 Xml::input( 'prefix', 30, str_replace( '_', ' ', $from ), array( 'id' => 'nsfrom' ) ) . 00114 "</td> 00115 </tr> 00116 <tr> 00117 <td class='mw-label'>" . 00118 Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) . 00119 "</td> 00120 <td class='mw-input'>" . 00121 Html::namespaceSelector( array( 00122 'selected' => $namespace, 00123 ), array( 00124 'name' => 'namespace', 00125 'id' => 'namespace', 00126 'class' => 'namespaceselector', 00127 ) ) . 00128 Xml::checkLabel( 00129 $this->msg( 'allpages-hide-redirects' )->text(), 00130 'hideredirects', 00131 'hideredirects', 00132 $this->hideRedirects 00133 ) . ' ' . 00134 Xml::checkLabel( 00135 $this->msg( 'prefixindex-strip' )->text(), 00136 'stripprefix', 00137 'stripprefix', 00138 $this->stripPrefix 00139 ) . ' ' . 00140 Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . 00141 "</td> 00142 </tr>"; 00143 $out .= Xml::closeElement( 'table' ); 00144 $out .= Xml::closeElement( 'fieldset' ); 00145 $out .= Xml::closeElement( 'form' ); 00146 $out .= Xml::closeElement( 'div' ); 00147 00148 return $out; 00149 } 00150 00156 protected function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) { 00157 global $wgContLang; 00158 00159 if ( $from === null ) { 00160 $from = $prefix; 00161 } 00162 00163 $fromList = $this->getNamespaceKeyAndText( $namespace, $from ); 00164 $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix ); 00165 $namespaces = $wgContLang->getNamespaces(); 00166 00167 if ( !$prefixList || !$fromList ) { 00168 $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock(); 00169 } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) { 00170 // Show errormessage and reset to NS_MAIN 00171 $out = $this->msg( 'allpages-bad-ns', $namespace )->parse(); 00172 $namespace = NS_MAIN; 00173 } else { 00174 list( $namespace, $prefixKey, $prefix ) = $prefixList; 00175 list( /* $fromNS */, $fromKey, ) = $fromList; 00176 00177 ### @todo FIXME: Should complain if $fromNs != $namespace 00178 00179 $dbr = wfGetDB( DB_SLAVE ); 00180 00181 $conds = array( 00182 'page_namespace' => $namespace, 00183 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ), 00184 'page_title >= ' . $dbr->addQuotes( $fromKey ), 00185 ); 00186 00187 if ( $this->hideRedirects ) { 00188 $conds['page_is_redirect'] = 0; 00189 } 00190 00191 $res = $dbr->select( 'page', 00192 array( 'page_namespace', 'page_title', 'page_is_redirect' ), 00193 $conds, 00194 __METHOD__, 00195 array( 00196 'ORDER BY' => 'page_title', 00197 'LIMIT' => $this->maxPerPage + 1, 00198 'USE INDEX' => 'name_title', 00199 ) 00200 ); 00201 00202 ### @todo FIXME: Side link to previous 00203 00204 $n = 0; 00205 if ( $res->numRows() > 0 ) { 00206 $out = Xml::openElement( 'table', array( 'id' => 'mw-prefixindex-list-table' ) ); 00207 00208 $prefixLength = strlen( $prefix ); 00209 while ( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) { 00210 $t = Title::makeTitle( $s->page_namespace, $s->page_title ); 00211 if ( $t ) { 00212 $displayed = $t->getText(); 00213 // Try not to generate unclickable links 00214 if ( $this->stripPrefix && $prefixLength !== strlen( $displayed ) ) { 00215 $displayed = substr( $displayed, $prefixLength ); 00216 } 00217 $link = ( $s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) . 00218 Linker::linkKnown( 00219 $t, 00220 htmlspecialchars( $displayed ), 00221 $s->page_is_redirect ? array( 'class' => 'mw-redirect' ) : array() 00222 ) . 00223 ( $s->page_is_redirect ? '</div>' : '' ); 00224 } else { 00225 $link = '[[' . htmlspecialchars( $s->page_title ) . ']]'; 00226 } 00227 if ( $n % 3 == 0 ) { 00228 $out .= '<tr>'; 00229 } 00230 $out .= "<td>$link</td>"; 00231 $n++; 00232 if ( $n % 3 == 0 ) { 00233 $out .= '</tr>'; 00234 } 00235 } 00236 00237 if ( $n % 3 != 0 ) { 00238 $out .= '</tr>'; 00239 } 00240 00241 $out .= Xml::closeElement( 'table' ); 00242 } else { 00243 $out = ''; 00244 } 00245 } 00246 00247 $footer = ''; 00248 if ( $this->including() ) { 00249 $out2 = ''; 00250 } else { 00251 $nsForm = $this->namespacePrefixForm( $namespace, $prefix ); 00252 $self = $this->getTitle(); 00253 $out2 = Xml::openElement( 'table', array( 'id' => 'mw-prefixindex-nav-table' ) ) . 00254 '<tr> 00255 <td>' . 00256 $nsForm . 00257 '</td> 00258 <td id="mw-prefixindex-nav-form" class="mw-prefixindex-nav">'; 00259 00260 if ( isset( $res ) && $res && ( $n == $this->maxPerPage ) && 00261 ( $s = $res->fetchObject() ) 00262 ) { 00263 $query = array( 00264 'from' => $s->page_title, 00265 'prefix' => $prefix, 00266 'hideredirects' => $this->hideRedirects, 00267 'stripprefix' => $this->stripPrefix, 00268 ); 00269 00270 if ( $namespace || $prefix == '' ) { 00271 // Keep the namespace even if it's 0 for empty prefixes. 00272 // This tells us we're not just a holdover from old links. 00273 $query['namespace'] = $namespace; 00274 } 00275 00276 $nextLink = Linker::linkKnown( 00277 $self, 00278 $this->msg( 'nextpage', str_replace( '_', ' ', $s->page_title ) )->escaped(), 00279 array(), 00280 $query 00281 ); 00282 00283 $out2 .= $nextLink; 00284 00285 $footer = "\n" . Html::element( 'hr' ) . 00286 Html::rawElement( 00287 'div', 00288 array( 'class' => 'mw-prefixindex-nav' ), 00289 $nextLink 00290 ); 00291 } 00292 $out2 .= "</td></tr>" . 00293 Xml::closeElement( 'table' ); 00294 } 00295 00296 $this->getOutput()->addHTML( $out2 . $out . $footer ); 00297 } 00298 00299 protected function getGroupName() { 00300 return 'pages'; 00301 } 00302 }