Merge "Add autocomplete for WhatLinksHere subpages"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 10 Jan 2015 20:04:53 +0000 (20:04 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 10 Jan 2015 20:04:53 +0000 (20:04 +0000)
1  2 
includes/specials/SpecialWhatlinkshere.php

@@@ -58,7 -58,6 +58,7 @@@ class SpecialWhatLinksHere extends Incl
                $opts->add( 'hidetrans', false );
                $opts->add( 'hidelinks', false );
                $opts->add( 'hideimages', false );
 +              $opts->add( 'invert', false );
  
                $opts->fetchValuesFromRequest( $this->getRequest() );
                $opts->validateIntBounds( 'limit', 0, 5000 );
  
                $useLinkNamespaceDBFields = $this->getConfig()->get( 'UseLinkNamespaceDBFields' );
                $namespace = $this->opts->getValue( 'namespace' );
 +              $invert = $this->opts->getValue( 'invert' );
 +              $nsComparison = ( $invert ? '!= ' : '= ' ) . $dbr->addQuotes( $namespace );
                if ( is_int( $namespace ) ) {
                        if ( $useLinkNamespaceDBFields ) {
 -                              $conds['pagelinks']['pl_from_namespace'] = $namespace;
 -                              $conds['templatelinks']['tl_from_namespace'] = $namespace;
 -                              $conds['imagelinks']['il_from_namespace'] = $namespace;
 +                              $conds['pagelinks'][] = "pl_from_namespace $nsComparison";
 +                              $conds['templatelinks'][] = "tl_from_namespace $nsComparison";
 +                              $conds['imagelinks'][] = "il_from_namespace $nsComparison";
                        } else {
 -                              $conds['pagelinks']['page_namespace'] = $namespace;
 -                              $conds['templatelinks']['page_namespace'] = $namespace;
 -                              $conds['imagelinks']['page_namespace'] = $namespace;
 +                              $conds['pagelinks'][] = "page_namespace $nsComparison";
 +                              $conds['templatelinks'][] = "page_namespace $nsComparison";
 +                              $conds['imagelinks'][] = "page_namespace $nsComparison";
                        }
                }
  
  
                $target = $this->target ? $this->target->getPrefixedText() : '';
                $namespace = $this->opts->consumeValue( 'namespace' );
 +              $nsinvert = $this->opts->consumeValue( 'invert' );
  
                # Build up the form
                $f = Xml::openElement( 'form', array( 'action' => wfScript() ) );
                        )
                );
  
 +              $f .= '&#160;' .
 +                      Xml::checkLabel(
 +                              $this->msg( 'invert' )->text(),
 +                              'invert',
 +                              'nsinvert',
 +                              $nsinvert,
 +                              array( 'title' => $this->msg( 'tooltip-whatlinkshere-invert' )->text() )
 +                      );
 +
                $f .= ' ';
  
                # Submit
                );
        }
  
+       /**
+        * Return an array of subpages beginning with $search that this special page will accept.
+        *
+        * @param string $search Prefix to search for
+        * @param int $limit Maximum number of results to return (usually 10)
+        * @param int $offset Number of results to skip (usually 0)
+        * @return string[] Matching subpages
+        */
+       public function prefixSearchSubpages( $search, $limit, $offset ) {
+               if ( $search === '' ) {
+                       return array();
+               }
+               // Autocomplete subpage the same as a normal search
+               $prefixSearcher = new StringPrefixSearch;
+               $result = $prefixSearcher->search( $search, $limit, array(), $offset );
+               return $result;
+       }
        protected function getGroupName() {
                return 'pagetools';
        }