Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -326,6 +326,8 @@ |
327 | 327 | $wgAutoloadClasses['ApiQueryUnreviewedpages'] = $dir . 'api/ApiQueryUnreviewedpages.php'; |
328 | 328 | # ReviewedPages for API |
329 | 329 | $wgAutoloadClasses['ApiQueryReviewedpages'] = $dir . 'api/ApiQueryReviewedpages.php'; |
| 330 | +# ConfiguredPages for API |
| 331 | +$wgAutoloadClasses['ApiQueryConfiguredpages'] = $dir . 'api/ApiQueryConfiguredpages.php'; |
330 | 332 | # Flag metadata for pages for API |
331 | 333 | $wgAutoloadClasses['ApiQueryFlagged'] = $dir . 'api/ApiQueryFlagged.php'; |
332 | 334 | $wgAPIPropModules['flagged'] = 'ApiQueryFlagged'; |
— | — | @@ -565,6 +567,7 @@ |
566 | 568 | $wgAPIModules['stabilize'] = 'ApiStabilizeGeneral'; |
567 | 569 | $wgAPIListModules['reviewedpages'] = 'ApiQueryReviewedpages'; |
568 | 570 | $wgAPIListModules['unreviewedpages'] = 'ApiQueryUnreviewedpages'; |
| 571 | + $wgAPIListModules['configuredpages'] = 'ApiQueryConfiguredpages'; |
569 | 572 | } |
570 | 573 | } |
571 | 574 | |
Index: trunk/extensions/FlaggedRevs/api/ApiQueryConfiguredPages.php |
— | — | @@ -0,0 +1,209 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on April 8, 2011 |
| 6 | + * |
| 7 | + * API module for MediaWiki's FlaggedRevs extension |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation; either version 2 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License along |
| 20 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | + * http://www.gnu.org/copyleft/gpl.html |
| 23 | + */ |
| 24 | + |
| 25 | +/** |
| 26 | + * Query module to list pages with custom review configurations |
| 27 | + * |
| 28 | + * @ingroup FlaggedRevs |
| 29 | + */ |
| 30 | +class ApiQueryConfiguredpages extends ApiQueryGeneratorBase { |
| 31 | + |
| 32 | + public function __construct( $query, $moduleName ) { |
| 33 | + parent::__construct( $query, $moduleName, 'cp' ); |
| 34 | + } |
| 35 | + |
| 36 | + public function execute() { |
| 37 | + $this->run(); |
| 38 | + } |
| 39 | + |
| 40 | + public function executeGenerator( $resultPageSet ) { |
| 41 | + $this->run( $resultPageSet ); |
| 42 | + } |
| 43 | + |
| 44 | + private function run( $resultPageSet = null ) { |
| 45 | + $params = $this->extractRequestParams(); |
| 46 | + |
| 47 | + // Construct SQL Query |
| 48 | + $this->addTables( array( 'page', 'flaggedpage_config', 'flaggedpages' ) ); |
| 49 | + if ( isset( $params['namespace'] ) ) { |
| 50 | + $this->addWhereFld( 'page_namespace', $params['namespace'] ); |
| 51 | + } |
| 52 | + if ( isset( $params['default'] ) ) { |
| 53 | + // Convert readable 'stable'/'latest' to 0/1 (DB format) |
| 54 | + $override = ( $params['default'] === 'stable' ) ? 1 : 0; |
| 55 | + $this->addWhereFld( 'fpc_override', $override ); |
| 56 | + } |
| 57 | + if ( isset( $params['autoreview'] ) ) { |
| 58 | + // Convert readable 'none' to '' (DB format) |
| 59 | + $level = ( $params['autoreview'] === 'none' ) ? '' : $params['autoreview']; |
| 60 | + $this->addWhereFld( 'fpc_level', $level ); |
| 61 | + } |
| 62 | + |
| 63 | + $this->addWhereRange( |
| 64 | + 'fpc_page_id', |
| 65 | + $params['dir'], |
| 66 | + $params['start'], |
| 67 | + $params['end'] |
| 68 | + ); |
| 69 | + $this->addJoinConds( array( |
| 70 | + 'flaggedpage_config' => array( 'INNER JOIN', 'page_id=fpc_page_id' ), |
| 71 | + 'flaggedpages' => array( 'LEFT JOIN', 'page_id=fp_page_id' ) |
| 72 | + ) ); |
| 73 | + $this->addOption( |
| 74 | + 'USE INDEX', |
| 75 | + array( 'flaggedpage_config' => 'PRIMARY' ) |
| 76 | + ); |
| 77 | + |
| 78 | + if ( is_null( $resultPageSet ) ) { |
| 79 | + $this->addFields( array( |
| 80 | + 'page_id', |
| 81 | + 'page_namespace', |
| 82 | + 'page_title', |
| 83 | + 'page_len', |
| 84 | + 'page_latest', |
| 85 | + 'fpc_page_id', |
| 86 | + 'fpc_override', |
| 87 | + 'fpc_level', |
| 88 | + 'fpc_expiry', |
| 89 | + 'fp_stable' |
| 90 | + ) ); |
| 91 | + } else { |
| 92 | + $this->addFields( $resultPageSet->getPageTableFields() ); |
| 93 | + $this->addFields( 'fpc_page_id' ); |
| 94 | + } |
| 95 | + |
| 96 | + $limit = $params['limit']; |
| 97 | + $this->addOption( 'LIMIT', $limit + 1 ); |
| 98 | + $res = $this->select( __METHOD__ ); |
| 99 | + |
| 100 | + $data = array(); |
| 101 | + $count = 0; |
| 102 | + foreach( $res as $row ) { |
| 103 | + if ( ++$count > $limit ) { |
| 104 | + // We've reached the one extra which shows that there are |
| 105 | + // additional pages to be had. Stop here... |
| 106 | + $this->setContinueEnumParameter( 'start', $row->fpc_page_id ); |
| 107 | + break; |
| 108 | + } |
| 109 | + |
| 110 | + if ( is_null( $resultPageSet ) ) { |
| 111 | + $title = Title::newFromRow( $row ); |
| 112 | + $data[] = array( |
| 113 | + 'pageid' => intval( $row->page_id ), |
| 114 | + 'ns' => intval( $row->page_namespace ), |
| 115 | + 'title' => $title->getPrefixedText(), |
| 116 | + 'last_revid' => intval( $row->page_latest ), |
| 117 | + 'stable_revid' => intval( $row->fp_stable ), |
| 118 | + 'stable_is_default' => intval( $row->fpc_override ), |
| 119 | + 'autoreview' => $row->fpc_level, |
| 120 | + 'expiry' => ( $row->fpc_expiry === 'infinity' ) ? |
| 121 | + 'infinity' : wfTimestamp( TS_ISO_8601, $row->fpc_expiry ), |
| 122 | + ); |
| 123 | + } else { |
| 124 | + $resultPageSet->processDbRow( $row ); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + if ( is_null( $resultPageSet ) ) { |
| 129 | + $result = $this->getResult(); |
| 130 | + $result->setIndexedTagName( $data, 'p' ); |
| 131 | + $result->addValue( 'query', $this->getModuleName(), $data ); |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + public function getCacheMode( $params ) { |
| 136 | + return 'public'; |
| 137 | + } |
| 138 | + |
| 139 | + public function getAllowedParams() { |
| 140 | + $namespaces = FlaggedRevs::getReviewNamespaces(); |
| 141 | + // Replace '' with more readable 'none' in autoreview restiction levels |
| 142 | + $autoreviewLevels = FlaggedRevs::getRestrictionLevels(); |
| 143 | + $autoreviewLevels[] = 'none'; |
| 144 | + return array( |
| 145 | + 'start' => array( |
| 146 | + ApiBase::PARAM_TYPE => 'integer' |
| 147 | + ), |
| 148 | + 'end' => array( |
| 149 | + ApiBase::PARAM_TYPE => 'integer' |
| 150 | + ), |
| 151 | + 'dir' => array( |
| 152 | + ApiBase::PARAM_DFLT => 'newer', |
| 153 | + ApiBase::PARAM_TYPE => array( 'newer', 'older' ) |
| 154 | + ), |
| 155 | + 'namespace' => array( |
| 156 | + ApiBase::PARAM_DFLT => null, |
| 157 | + ApiBase::PARAM_TYPE => 'namespace', |
| 158 | + ApiBase::PARAM_ISMULTI => true, |
| 159 | + ), |
| 160 | + 'default' => array( |
| 161 | + ApiBase :: PARAM_DFLT => null, |
| 162 | + ApiBase :: PARAM_TYPE => array( 'latest', 'stable' ), |
| 163 | + ), |
| 164 | + 'autoreview' => array( |
| 165 | + ApiBase :: PARAM_DFLT => null, |
| 166 | + ApiBase :: PARAM_TYPE => $autoreviewLevels, |
| 167 | + ), |
| 168 | + 'limit' => array( |
| 169 | + ApiBase::PARAM_DFLT => 10, |
| 170 | + ApiBase::PARAM_TYPE => 'limit', |
| 171 | + ApiBase::PARAM_MIN => 1, |
| 172 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 173 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
| 174 | + ) |
| 175 | + ); |
| 176 | + } |
| 177 | + |
| 178 | + public function getParamDescription() { |
| 179 | + return array( |
| 180 | + 'start' => 'Start listing at this page id.', |
| 181 | + 'end' => 'Stop listing at this page id.', |
| 182 | + 'namespace' => 'The namespaces to enumerate.', |
| 183 | + 'default' => 'The default page view version.', |
| 184 | + 'autoreview' => 'Review/autoreview restriction level.', |
| 185 | + 'limit' => 'How many total pages to return.', |
| 186 | + 'dir' => array( |
| 187 | + 'In which direction to list.', |
| 188 | + '*newer: list the newest pages first', |
| 189 | + '*older: list the oldest pages first' |
| 190 | + ) |
| 191 | + ); |
| 192 | + } |
| 193 | + |
| 194 | + public function getDescription() { |
| 195 | + return 'Enumerate all pages that have custom review configurations'; |
| 196 | + } |
| 197 | + |
| 198 | + protected function getExamples() { |
| 199 | + return array( |
| 200 | + 'Show a list of pages with custom review configurations', |
| 201 | + ' api.php?action=query&list=configuredpages&cpnamespace=0', |
| 202 | + 'Get some info about pages with custom review configurations', |
| 203 | + ' api.php?action=query&generator=configuredpages&gcplimit=4&prop=info', |
| 204 | + ); |
| 205 | + } |
| 206 | + |
| 207 | + public function getVersion() { |
| 208 | + return __CLASS__ . ': $Id: $'; |
| 209 | + } |
| 210 | +} |
Property changes on: trunk/extensions/FlaggedRevs/api/ApiQueryConfiguredPages.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 211 | + native |