X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialPrefixindex.php;h=c37bb1d3101c0821c027607726ebfe64602d0781;hb=6088cd4458f6b6ca36bcdd881c4c3d4d49b6d1b8;hp=5797f35a9973184700c17258700d85e9b302b3b7;hpb=b9be69ce3d6be06b739ebc0606ca42d3aa68f24b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialPrefixindex.php b/includes/specials/SpecialPrefixindex.php index 5797f35a99..c37bb1d310 100644 --- a/includes/specials/SpecialPrefixindex.php +++ b/includes/specials/SpecialPrefixindex.php @@ -28,67 +28,77 @@ */ class SpecialPrefixindex extends SpecialAllpages { // Inherit $maxPerPage - + function __construct(){ parent::__construct( 'Prefixindex' ); } - + /** * Entry point : initialise variables and call subfunctions. * @param $par String: becomes "FOO" when called like Special:Prefixindex/FOO (default null) */ function execute( $par ) { - global $wgRequest, $wgOut, $wgContLang; + global $wgContLang; $this->setHeaders(); $this->outputHeader(); - $wgOut->addModuleStyles( 'mediawiki.special' ); + + $out = $this->getOutput(); + $out->addModuleStyles( 'mediawiki.special' ); # GET values - $from = $wgRequest->getVal( 'from', '' ); - $prefix = $wgRequest->getVal( 'prefix', '' ); - $namespace = $wgRequest->getInt( 'namespace' ); - $namespaces = $wgContLang->getNamespaces(); + $request = $this->getRequest(); + $from = $request->getVal( 'from', '' ); + $prefix = $request->getVal( 'prefix', '' ); + $ns = $request->getIntOrNull( 'namespace' ); + $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN). + $hideredirects = $request->getBool( 'hideredirects', false ); - $wgOut->setPagetitle( ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) ) - ? wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) ) - : wfMsg( 'prefixindex' ) + $namespaces = $wgContLang->getNamespaces(); + $out->setPageTitle( + ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) ) + ? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) ) + : $this->msg( 'prefixindex' ) ); $showme = ''; - if( isset( $par ) ){ + if( isset( $par ) ) { $showme = $par; - } elseif( $prefix != '' ){ + } elseif( $prefix != '' ) { $showme = $prefix; - } elseif( $from != '' ){ + } elseif( $from != '' && $ns === null ) { // For back-compat with Special:Allpages + // Don't do this if namespace is passed, so paging works when doing NS views. $showme = $from; } - if ($showme != '' || $namespace) { - $this->showPrefixChunk( $namespace, $showme, $from ); + + // Bug 27864: if transcluded, show all pages instead of the form. + if ( $this->including() || $showme != '' || $ns !== null ) { + $this->showPrefixChunk( $namespace, $showme, $from, $hideredirects ); } else { - $wgOut->addHTML( $this->namespacePrefixForm( $namespace, null ) ); + $out->addHTML( $this->namespacePrefixForm( $namespace, null, $hideredirects ) ); } } - + /** - * HTML for the top form - * @param $namespace Integer: a namespace constant (default NS_MAIN). - * @param $from String: dbKey we are starting listing at. - */ - function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) { + * HTML for the top form + * @param $namespace Integer: a namespace constant (default NS_MAIN). + * @param $from String: dbKey we are starting listing at. + * @param $hideredirects Bool: hide redirects (default FALSE) + * @return string + */ + function namespacePrefixForm( $namespace = NS_MAIN, $from = '', $hideredirects = false ) { global $wgScript; - $t = $this->getTitle(); $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) ); $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); - $out .= Html::hidden( 'title', $t->getPrefixedText() ); + $out .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ); $out .= Xml::openElement( 'fieldset' ); - $out .= Xml::element( 'legend', null, wfMsg( 'allpages' ) ); + $out .= Xml::element( 'legend', null, $this->msg( 'allpages' )->text() ); $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) ); $out .= " " . - Xml::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) . + Xml::label( $this->msg( 'allpagesprefix' )->text(), 'nsfrom' ) . " " . Xml::input( 'prefix', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) . @@ -96,13 +106,25 @@ class SpecialPrefixindex extends SpecialAllpages { " . - Xml::label( wfMsg( 'namespace' ), 'namespace' ) . + Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) . " " . - Xml::namespaceSelector( $namespace, null ) . ' ' . - Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . + Html::namespaceSelector( array( + 'selected' => $namespace, + ), array( + 'name' => 'namespace', + 'id' => 'namespace', + 'class' => 'namespaceselector', + ) ) . + Xml::checkLabel( + $this->msg( 'allpages-hide-redirects' )->text(), + 'hideredirects', + 'hideredirects', + $hideredirects + ) . ' ' . + Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . " - "; + "; $out .= Xml::closeElement( 'table' ); $out .= Xml::closeElement( 'fieldset' ); $out .= Xml::closeElement( 'form' ); @@ -114,39 +136,46 @@ class SpecialPrefixindex extends SpecialAllpages { * @param $namespace Integer, default NS_MAIN * @param $prefix String * @param $from String: list all pages from this name (default FALSE) + * @param $hideredirects Bool: hide redirects (default FALSE) */ - function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) { - global $wgOut, $wgUser, $wgContLang, $wgLang; - - $sk = $wgUser->getSkin(); + function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null, $hideredirects = false ) { + global $wgContLang; - if (!isset($from)) $from = $prefix; + if ( $from === null ) { + $from = $prefix; + } $fromList = $this->getNamespaceKeyAndText($namespace, $from); $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix); $namespaces = $wgContLang->getNamespaces(); if ( !$prefixList || !$fromList ) { - $out = wfMsgExt( 'allpagesbadtitle', 'parse' ); + $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock(); } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) { // Show errormessage and reset to NS_MAIN - $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace ); + $out = $this->msg( 'allpages-bad-ns', $namespace )->parse(); $namespace = NS_MAIN; } else { list( $namespace, $prefixKey, $prefix ) = $prefixList; list( /* $fromNS */, $fromKey, ) = $fromList; - ### FIXME: should complain if $fromNs != $namespace + ### @todo FIXME: Should complain if $fromNs != $namespace $dbr = wfGetDB( DB_SLAVE ); + $conds = array( + 'page_namespace' => $namespace, + 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ), + 'page_title >= ' . $dbr->addQuotes( $fromKey ), + ); + + if ( $hideredirects ) { + $conds['page_is_redirect'] = 0; + } + $res = $dbr->select( 'page', array( 'page_namespace', 'page_title', 'page_is_redirect' ), - array( - 'page_namespace' => $namespace, - 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ), - 'page_title >= ' . $dbr->addQuotes( $fromKey ), - ), + $conds, __METHOD__, array( 'ORDER BY' => 'page_title', @@ -155,19 +184,20 @@ class SpecialPrefixindex extends SpecialAllpages { ) ); - ### FIXME: side link to previous + ### @todo FIXME: Side link to previous $n = 0; if( $res->numRows() > 0 ) { $out = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) ); - + while( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) { $t = Title::makeTitle( $s->page_namespace, $s->page_title ); if( $t ) { $link = ($s->page_is_redirect ? '
' : '' ) . - $sk->linkKnown( + Linker::linkKnown( $t, - htmlspecialchars( $t->getText() ) + htmlspecialchars( $t->getText() ), + $s->page_is_redirect ? array( 'class' => 'mw-redirect' ) : array() ) . ($s->page_is_redirect ? '
' : '' ); } else { @@ -191,43 +221,46 @@ class SpecialPrefixindex extends SpecialAllpages { } } + $footer = ''; if ( $this->including() ) { $out2 = ''; } else { - $nsForm = $this->namespacePrefixForm( $namespace, $prefix ); + $nsForm = $this->namespacePrefixForm( $namespace, $prefix, $hideredirects ); $self = $this->getTitle(); $out2 = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) . ' ' . $nsForm . ' - ' . - $sk->linkKnown( $self, wfMsgHtml( 'allpages' ) ); + '; if( isset( $res ) && $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) { $query = array( 'from' => $s->page_title, - 'prefix' => $prefix + 'prefix' => $prefix, + 'hideredirects' => $hideredirects, ); - if( $namespace ) { + if( $namespace || ($prefix == '')) { + // Keep the namespace even if it's 0 for empty prefixes. + // This tells us we're not just a holdover from old links. $query['namespace'] = $namespace; } - - $out2 = $wgLang->pipeList( array( - $out2, - $sk->linkKnown( + $nextLink = Linker::linkKnown( $self, - wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title ) ) ), + $this->msg( 'nextpage', str_replace( '_',' ', $s->page_title ) )->escaped(), array(), $query - ) - ) ); + ); + $out2 .= $nextLink; + + $footer = "\n" . Html::element( "hr" ) + . Html::rawElement( "div", array( "class" => "mw-prefixindex-nav" ), $nextLink ); } $out2 .= "" . Xml::closeElement( 'table' ); } - $wgOut->addHTML( $out2 . $out ); + $this->getOutput()->addHTML( $out2 . $out . $footer ); } }