r52556 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52555‎ | r52556 | r52557 >
Date:17:19, 29 June 2009
Author:aaron
Status:ok
Tags:
Comment:
Added reviewedpages to api
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiQueryReviewedpages.php (added) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -371,8 +371,13 @@
372372 $wgAutoloadClasses['FlaggedRevsApiHooks'] = $dir.'api/FlaggedRevsApi.hooks.php';
373373 $wgAutoloadClasses['ApiQueryOldreviewedpages'] = $dir . 'api/ApiQueryOldreviewedpages.php';
374374 $wgAPIListModules['oldreviewedpages'] = 'ApiQueryOldreviewedpages';
 375+
 376+$wgAutoloadClasses['ApiQueryReviewedpages'] = $dir . 'api/ApiQueryReviewedpages.php';
 377+$wgAPIListModules['reviewedpages'] = 'ApiQueryReviewedpages';
 378+
375379 $wgAutoloadClasses['ApiQueryFlagged'] = $dir . 'api/ApiQueryFlagged.php';
376380 $wgAPIPropModules['flagged'] = 'ApiQueryFlagged';
 381+
377382 $wgAutoloadClasses['ApiReview'] = $dir.'api/ApiReview.php';
378383 $wgAPIModules['review'] = 'ApiReview';
379384
Index: trunk/extensions/FlaggedRevs/api/ApiQueryReviewedpages.php
@@ -0,0 +1,196 @@
 2+<?php
 3+
 4+/*
 5+ * Created on June 29, 2009
 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+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 22+ * http://www.gnu.org/copyleft/gpl.html
 23+ */
 24+
 25+/**
 26+ * Query module to list pages reviewed pages
 27+ *
 28+ * @ingroup FlaggedRevs
 29+ */
 30+class ApiQueryReviewedpages extends ApiQueryGeneratorBase {
 31+
 32+ public function __construct( $query, $moduleName ) {
 33+ parent::__construct( $query, $moduleName, 'rp' );
 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', 'flaggedpages' ) );
 49+ $this->addWhereFld( 'page_namespace', $params['namespace'] );
 50+ if( $params['filterredir'] == 'redirects' )
 51+ $this->addWhereFld( 'page_is_redirect', 1 );
 52+ if( $params['filterredir'] == 'nonredirects' )
 53+ $this->addWhereFld( 'page_is_redirect', 0 );
 54+ $this->addWhereRange(
 55+ 'fp_page_id',
 56+ $params['dir'],
 57+ $params['start'],
 58+ $params['end']
 59+ );
 60+ $this->addWhere( 'page_id=fp_page_id' );
 61+ $this->addOption(
 62+ 'USE INDEX',
 63+ array( 'flaggedpages' => 'PRIMARY' )
 64+ );
 65+
 66+ if ( is_null( $resultPageSet ) ) {
 67+ $this->addFields( array (
 68+ 'page_id',
 69+ 'page_namespace',
 70+ 'page_title',
 71+ 'page_len',
 72+ 'page_latest',
 73+ 'fp_page_id',
 74+ 'fp_quality',
 75+ 'fp_stable'
 76+ ) );
 77+ } else {
 78+ $this->addFields( $resultPageSet->getPageTableFields() );
 79+ $this->addFields ( 'fp_page_id' );
 80+ }
 81+
 82+ $limit = $params['limit'];
 83+ $this->addOption( 'LIMIT', $limit+1 );
 84+ $res = $this->select( __METHOD__ );
 85+
 86+ $data = array ();
 87+ $count = 0;
 88+ $db = $this->getDB();
 89+ while ( $row = $db->fetchObject( $res ) ) {
 90+ if ( ++$count > $limit ) {
 91+ // We've reached the one extra which shows that there are
 92+ // additional pages to be had. Stop here...
 93+ $this->setContinueEnumParameter( 'start', $row->fp_page_id );
 94+ break;
 95+ }
 96+
 97+ if ( is_null( $resultPageSet ) ) {
 98+ $title = Title::newFromRow( $row );
 99+ $data[] = array(
 100+ 'pageid' => intval( $row->page_id ),
 101+ 'ns' => intval( $title->getNamespace() ),
 102+ 'title' => $title->getPrefixedText(),
 103+ 'revid' => intval( $row->page_latest ),
 104+ 'stable_revid' => intval( $row->fp_stable ),
 105+ 'flagged_level' => intval( $row->fp_quality ),
 106+ 'flagged_level_text' => FlaggedRevs::getQualityLevelText( $row->fp_quality )
 107+ );
 108+ } else {
 109+ $resultPageSet->processDbRow( $row );
 110+ }
 111+ }
 112+ $db->freeResult( $res );
 113+
 114+ if ( is_null( $resultPageSet ) ) {
 115+ $result = $this->getResult();
 116+ $result->setIndexedTagName( $data, 'p' );
 117+ $result->addValue( 'query', $this->getModuleName(), $data );
 118+ }
 119+ }
 120+
 121+ public function getAllowedParams() {
 122+ global $wgFlaggedRevsNamespaces;
 123+ return array (
 124+ 'start' => array (
 125+ ApiBase::PARAM_TYPE => 'integer'
 126+ ),
 127+ 'end' => array (
 128+ ApiBase::PARAM_TYPE => 'integer'
 129+ ),
 130+ 'dir' => array (
 131+ ApiBase::PARAM_DFLT => 'newer',
 132+ ApiBase::PARAM_TYPE => array (
 133+ 'newer',
 134+ 'older'
 135+ )
 136+ ),
 137+ 'namespace' => array (
 138+ ApiBase::PARAM_DFLT =>
 139+ !$wgFlaggedRevsNamespaces ?
 140+ NS_MAIN :
 141+ $wgFlaggedRevsNamespaces[0],
 142+ ApiBase::PARAM_TYPE => 'namespace',
 143+ ApiBase::PARAM_ISMULTI => true,
 144+ ),
 145+ 'filterredir' => array (
 146+ ApiBase::PARAM_DFLT => 'all',
 147+ ApiBase::PARAM_TYPE => array (
 148+ 'redirects',
 149+ 'nonredirects',
 150+ 'all'
 151+ )
 152+ ),
 153+ 'limit' => array (
 154+ ApiBase::PARAM_DFLT => 10,
 155+ ApiBase::PARAM_TYPE => 'limit',
 156+ ApiBase::PARAM_MIN => 1,
 157+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
 158+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
 159+ )
 160+ );
 161+ }
 162+
 163+ public function getParamDescription() {
 164+ return array (
 165+ 'start' => 'Start listing at this page id.',
 166+ 'end' => 'Stop listing at this page id.',
 167+ 'namespace' => 'The namespaces to enumerate.',
 168+ 'filterredir' => 'How to filter for redirects',
 169+ 'limit' => 'How many total pages to return.',
 170+ 'dir' => array(
 171+ 'In which direction to list.',
 172+ '*newer: list the newest pages first',
 173+ '*older: list the oldest pages first'
 174+ )
 175+ );
 176+ }
 177+
 178+ public function getDescription() {
 179+ return array(
 180+ 'Returns a list of pages, that have been reviewed,',
 181+ 'sorted by page id.'
 182+ );
 183+ }
 184+
 185+ protected function getExamples() {
 186+ return array (
 187+ 'Show a list of reviewed pages',
 188+ ' api.php?action=query&list=reviewedpages&rpnamespace=0',
 189+ 'Show info about some reviewed pages',
 190+ ' api.php?action=query&generator=reviewedpages&grplimit=4&prop=info',
 191+ );
 192+ }
 193+
 194+ public function getVersion() {
 195+ return __CLASS__.': $Id: ApiQueryReviewedpages.php 44870 2008-12-21 12:48:08Z aaron $';
 196+ }
 197+}

Status & tagging log