From: umherirrender Date: Fri, 13 Jun 2014 19:16:37 +0000 (+0200) Subject: Add SpecialPagesWithProp::prefixSearchSubpages X-Git-Tag: 1.31.0-rc.0~15152 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22sites_tous%22%29%20.%20%22?a=commitdiff_plain;h=4bc8a7740b47787820b291304cd0a93f069e162e;p=lhc%2Fweb%2Fwiklou.git Add SpecialPagesWithProp::prefixSearchSubpages This shows the existing props as subpages on search suggestion Change-Id: I3d35474bcf840a6feede8079642d83074874c6f3 --- diff --git a/includes/specials/SpecialPagesWithProp.php b/includes/specials/SpecialPagesWithProp.php index e22b42a38c..05f0b2b1f4 100644 --- a/includes/specials/SpecialPagesWithProp.php +++ b/includes/specials/SpecialPagesWithProp.php @@ -30,6 +30,7 @@ */ class SpecialPagesWithProp extends QueryPage { private $propName = null; + private $existingPropNames = null; function __construct( $name = 'PagesWithProp' ) { parent::__construct( $name ); @@ -47,18 +48,7 @@ class SpecialPagesWithProp extends QueryPage { $request = $this->getRequest(); $propname = $request->getVal( 'propname', $par ); - $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( - 'page_props', - 'pp_propname', - '', - __METHOD__, - array( 'DISTINCT', 'ORDER BY' => 'pp_propname' ) - ); - $propnames = array(); - foreach ( $res as $row ) { - $propnames[$row->pp_propname] = $row->pp_propname; - } + $propnames = $this->getExistingPropNames(); $form = new HTMLForm( array( 'propname' => array( @@ -88,6 +78,18 @@ class SpecialPagesWithProp extends QueryPage { parent::execute( $data['propname'] ); } + /** + * Return an array of subpages beginning with $search that this special page will accept. + * + * @param string $search Prefix to search for + * @param integer $limit Maximum number of results to return + * @return string[] Matching subpages + */ + public function prefixSearchSubpages( $search, $limit = 10 ) { + $subpages = array_keys( $this->getExistingPropNames() ); + return self::prefixSearchArray( $search, $limit, $subpages ); + } + /** * Disable RSS/Atom feeds * @return bool @@ -150,6 +152,25 @@ class SpecialPagesWithProp extends QueryPage { return $ret; } + public function getExistingPropNames() { + if ( $this->existingPropNames === null ) { + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr->select( + 'page_props', + 'pp_propname', + '', + __METHOD__, + array( 'DISTINCT', 'ORDER BY' => 'pp_propname' ) + ); + $propnames = array(); + foreach ( $res as $row ) { + $propnames[$row->pp_propname] = $row->pp_propname; + } + $this->existingPropNames = $propnames; + } + return $this->existingPropNames; + } + protected function getGroupName() { return 'pages'; }