| Index: branches/RL2/extensions/Gadgets/Gadgets.php |
| — | — | @@ -116,6 +116,7 @@ |
| 117 | 117 | |
| 118 | 118 | $wgAutoloadClasses['ApiGadgetManager'] = $dir . 'api/ApiGadgetManager.php'; |
| 119 | 119 | $wgAutoloadClasses['ApiQueryGadgetCategories'] = $dir . 'api/ApiQueryGadgetCategories.php'; |
| | 120 | +$wgAutoloadClasses['ApiQueryGadgetPages'] = $dir . 'api/ApiQueryGadgetPages.php'; |
| 120 | 121 | $wgAutoloadClasses['ApiQueryGadgets'] = $dir . 'api/ApiQueryGadgets.php'; |
| 121 | 122 | $wgAutoloadClasses['ForeignDBGadgetRepo'] = $dir . 'backend/ForeignDBGadgetRepo.php'; |
| 122 | 123 | $wgAutoloadClasses['Gadget'] = $dir . 'backend/Gadget.php'; |
| — | — | @@ -135,6 +136,7 @@ |
| 136 | 137 | $wgAPIModules['gadgetmanager'] = 'ApiGadgetManager'; |
| 137 | 138 | $wgAPIListModules['gadgetcategories'] = 'ApiQueryGadgetCategories'; |
| 138 | 139 | $wgAPIListModules['gadgets'] = 'ApiQueryGadgets'; |
| | 140 | +$wgAPIListModules['gadgetpages'] = 'ApiQueryGadgetPages'; |
| 139 | 141 | |
| 140 | 142 | $gadResourceTemplate = array( |
| 141 | 143 | 'localBasePath' => $dir . 'modules', |
| Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgetPages.php |
| — | — | @@ -0,0 +1,156 @@ |
| | 2 | +<?php |
| | 3 | +/** |
| | 4 | + * Created on 15 April 2011 |
| | 5 | + * API for Gadgets extension |
| | 6 | + * |
| | 7 | + * This program is free software; you can redistribute it and/or modify |
| | 8 | + * it under the terms of the GNU General Public License as published by |
| | 9 | + * the Free Software Foundation; either version 2 of the License, or |
| | 10 | + * (at your option) any later version. |
| | 11 | + * |
| | 12 | + * This program is distributed in the hope that it will be useful, |
| | 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| | 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| | 15 | + * GNU General Public License for more details. |
| | 16 | + * |
| | 17 | + * You should have received a copy of the GNU General Public License along |
| | 18 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| | 19 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| | 20 | + * http://www.gnu.org/copyleft/gpl.html |
| | 21 | + */ |
| | 22 | + |
| | 23 | +class ApiQueryGadgetPages extends ApiQueryGeneratorBase { |
| | 24 | + public function __construct( $query, $moduleName ) { |
| | 25 | + parent::__construct( $query, $moduleName, 'gp' ); |
| | 26 | + } |
| | 27 | + |
| | 28 | + public function getCacheMode( $params ) { |
| | 29 | + return 'public'; |
| | 30 | + } |
| | 31 | + |
| | 32 | + public function execute() { |
| | 33 | + $this->run(); |
| | 34 | + } |
| | 35 | + |
| | 36 | + /** |
| | 37 | + * @param $resultPageSet ApiPageSet |
| | 38 | + * @return void |
| | 39 | + */ |
| | 40 | + public function executeGenerator( $resultPageSet ) { |
| | 41 | + $this->run( $resultPageSet ); |
| | 42 | + } |
| | 43 | + |
| | 44 | + /** |
| | 45 | + * @param $resultPageSet ApiPageSet |
| | 46 | + * @return void |
| | 47 | + */ |
| | 48 | + private function run( $resultPageSet = null ) { |
| | 49 | + $params = $this->extractRequestParams(); |
| | 50 | + $db = $this->getDB(); |
| | 51 | + |
| | 52 | + $this->addTables( 'gadgetpagelist' ); |
| | 53 | + $this->addFields( array( 'gpl_namespace', 'gpl_title' ) ); |
| | 54 | + $this->addWhereFld( 'gpl_extension', $params['extension'] ); |
| | 55 | + $this->addWhereFld( 'gpl_namespace', $params['namespace'] ); |
| | 56 | + if ( $params['prefix'] !== null ) { |
| | 57 | + $this->addWhere( 'gpl_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) ); |
| | 58 | + } |
| | 59 | + $limit = $params['limit']; |
| | 60 | + $this->addOption( 'LIMIT', $limit + 1 ); |
| | 61 | + $dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' ); |
| | 62 | + $from = $params['from'] !== null ? $this->titlePartToKey( $params['from'] ) : null; |
| | 63 | + $this->addWhereRange( 'gpl_title', $dir, $from, null ); |
| | 64 | + |
| | 65 | + $res = $this->select( __METHOD__ ); |
| | 66 | + |
| | 67 | + $count = 0; |
| | 68 | + $titles = array(); |
| | 69 | + $result = $this->getResult(); |
| | 70 | + foreach ( $res as $row ) { |
| | 71 | + if ( ++$count > $limit ) { |
| | 72 | + // We've reached the one extra which shows that there are additional pages to be had. Stop here... |
| | 73 | + $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->gpl_title ) ); |
| | 74 | + break; |
| | 75 | + } |
| | 76 | + |
| | 77 | + $title = Title::makeTitle( $row->gpl_namespace, $row->gpl_title ); |
| | 78 | + if ( is_null( $resultPageSet ) ) { |
| | 79 | + $vals = array(); |
| | 80 | + self::addTitleInfo( $vals, $title ); |
| | 81 | + $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); |
| | 82 | + if ( !$fit ) { |
| | 83 | + $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->gpl_title ) ); |
| | 84 | + break; |
| | 85 | + } |
| | 86 | + } else { |
| | 87 | + $titles[] = $title; |
| | 88 | + } |
| | 89 | + } |
| | 90 | + |
| | 91 | + if ( is_null( $resultPageSet ) ) { |
| | 92 | + $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'p' ); |
| | 93 | + } else { |
| | 94 | + $resultPageSet->populateFromTitles( $titles ); |
| | 95 | + } |
| | 96 | + } |
| | 97 | + |
| | 98 | + public function getAllowedParams() { |
| | 99 | + return array( |
| | 100 | + 'extension' => array( |
| | 101 | + ApiBase::PARAM_DFLT => 'js', |
| | 102 | + ApiBase::PARAM_TYPE => array( 'js', 'css' ), |
| | 103 | + ), |
| | 104 | + 'namespace' => array( |
| | 105 | + ApiBase::PARAM_DFLT => NS_GADGET, |
| | 106 | + ApiBase::PARAM_TYPE => 'namespace', |
| | 107 | + ), |
| | 108 | + 'prefix' => null, |
| | 109 | + 'from' => null, |
| | 110 | + 'limit' => array( |
| | 111 | + ApiBase::PARAM_DFLT => 10, |
| | 112 | + ApiBase::PARAM_TYPE => 'limit', |
| | 113 | + ApiBase::PARAM_MIN => 1, |
| | 114 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| | 115 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
| | 116 | + ), |
| | 117 | + 'dir' => array( |
| | 118 | + ApiBase::PARAM_DFLT => 'ascending', |
| | 119 | + ApiBase::PARAM_TYPE => array( |
| | 120 | + 'ascending', |
| | 121 | + 'descending' |
| | 122 | + ) |
| | 123 | + ), |
| | 124 | + ); |
| | 125 | + } |
| | 126 | + |
| | 127 | + public function getDescription() { |
| | 128 | + return 'Returns a list of .js/.css pages'; |
| | 129 | + } |
| | 130 | + |
| | 131 | + public function getParamDescription() { |
| | 132 | + return array( |
| | 133 | + 'extension' => 'Search for pages with this extension.', |
| | 134 | + 'namespace' => 'Search for pages in this namespace.', |
| | 135 | + 'prefix' => array( 'Search for pages with this prefix (optional).', |
| | 136 | + 'NOTE: Prefix does not include the namespace prefix', |
| | 137 | + ), |
| | 138 | + 'from' => 'Start at this page title. NOTE: Does not include the namespace prefix', |
| | 139 | + 'limit' => 'How many total pages to return.', |
| | 140 | + 'dir' => 'The direction in which to list', |
| | 141 | + ); |
| | 142 | + } |
| | 143 | + |
| | 144 | + protected function getExamples() { |
| | 145 | + return array( |
| | 146 | + 'Get a list of .js pages in the MediaWiki namespace:', |
| | 147 | + ' api.php?action=query&list=gadgetpages&gpextension=js&gpnamespace=8', |
| | 148 | + "Get a list of .css pages in the Catrope's user space:", |
| | 149 | + ' api.php?action=query&list=gadgetpages&gpextension=css&gpnamespace=2&gpprefix=Catrope/', |
| | 150 | + ); |
| | 151 | + } |
| | 152 | + |
| | 153 | + public function getVersion() { |
| | 154 | + return __CLASS__ . ': $Id$'; |
| | 155 | + } |
| | 156 | + |
| | 157 | +} |
| Property changes on: branches/RL2/extensions/Gadgets/api/ApiQueryGadgetPages.php |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| 1 | 158 | + native |
| Added: svn:keywords |
| 2 | 159 | + Id |