[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * This program is free software; you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation; either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License along 14 * with this program; if not, write to the Free Software Foundation, Inc., 15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 * http://www.gnu.org/copyleft/gpl.html 17 * 18 * @file 19 * @since 1.23 20 */ 21 22 /** 23 * @ingroup API 24 */ 25 class ApiQueryPrefixSearch extends ApiQueryGeneratorBase { 26 public function __construct( $query, $moduleName ) { 27 parent::__construct( $query, $moduleName, 'ps' ); 28 } 29 30 public function execute() { 31 $this->run(); 32 } 33 34 public function executeGenerator( $resultPageSet ) { 35 $this->run( $resultPageSet ); 36 } 37 38 /** 39 * @param ApiPageSet $resultPageSet 40 */ 41 private function run( $resultPageSet = null ) { 42 $params = $this->extractRequestParams(); 43 $search = $params['search']; 44 $limit = $params['limit']; 45 $namespaces = $params['namespace']; 46 47 $searcher = new TitlePrefixSearch; 48 $titles = $searcher->searchWithVariants( $search, $limit, $namespaces ); 49 if ( $resultPageSet ) { 50 $resultPageSet->populateFromTitles( $titles ); 51 } else { 52 $result = $this->getResult(); 53 foreach ( $titles as $title ) { 54 if ( !$limit-- ) { 55 break; 56 } 57 $vals = array( 58 'ns' => intval( $title->getNamespace() ), 59 'title' => $title->getPrefixedText(), 60 ); 61 if ( $title->isSpecialPage() ) { 62 $vals['special'] = ''; 63 } else { 64 $vals['pageid'] = intval( $title->getArticleId() ); 65 } 66 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); 67 if ( !$fit ) { 68 break; 69 } 70 } 71 $result->setIndexedTagName_internal( 72 array( 'query', $this->getModuleName() ), $this->getModulePrefix() 73 ); 74 } 75 } 76 77 public function getCacheMode( $params ) { 78 return 'public'; 79 } 80 81 public function getAllowedParams() { 82 return array( 83 'search' => array( 84 ApiBase::PARAM_TYPE => 'string', 85 ApiBase::PARAM_REQUIRED => true, 86 ), 87 'namespace' => array( 88 ApiBase::PARAM_DFLT => NS_MAIN, 89 ApiBase::PARAM_TYPE => 'namespace', 90 ApiBase::PARAM_ISMULTI => true, 91 ), 92 'limit' => array( 93 ApiBase::PARAM_DFLT => 10, 94 ApiBase::PARAM_TYPE => 'limit', 95 ApiBase::PARAM_MIN => 1, 96 // Non-standard value for compatibility with action=opensearch 97 ApiBase::PARAM_MAX => 100, 98 ApiBase::PARAM_MAX2 => 200, 99 ), 100 ); 101 } 102 103 public function getParamDescription() { 104 return array( 105 'search' => 'Search string', 106 'limit' => 'Maximum amount of results to return', 107 'namespace' => 'Namespaces to search', 108 ); 109 } 110 111 public function getDescription() { 112 return 'Perform a prefix search for page titles'; 113 } 114 115 public function getExamples() { 116 return array( 117 'api.php?action=query&list=prefixsearch&pssearch=meaning', 118 ); 119 } 120 121 public function getHelpUrls() { 122 return 'https://www.mediawiki.org/wiki/API:Prefixsearch'; 123 } 124 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |