r52566 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52565‎ | r52566 | r52567 >
Date:19:43, 29 June 2009
Author:aaron
Status:ok
Tags:
Comment:
Added unreviewedpages to api
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiQueryUnreviewedpages.php (added) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -369,12 +369,16 @@
370370 $wgSpecialPageGroups['ValidationStatistics'] = 'quality';
371371 # API Modules
372372 $wgAutoloadClasses['FlaggedRevsApiHooks'] = $dir.'api/FlaggedRevsApi.hooks.php';
 373+# OldReviewedPages for API
373374 $wgAutoloadClasses['ApiQueryOldreviewedpages'] = $dir . 'api/ApiQueryOldreviewedpages.php';
374375 $wgAPIListModules['oldreviewedpages'] = 'ApiQueryOldreviewedpages';
375 -
 376+# UnreviewedPages for API
 377+$wgAutoloadClasses['ApiQueryUnreviewedpages'] = $dir . 'api/ApiQueryUnreviewedpages.php';
 378+$wgAPIListModules['unreviewedpages'] = 'ApiQueryUnreviewedpages';
 379+# ReviewedPages for API
376380 $wgAutoloadClasses['ApiQueryReviewedpages'] = $dir . 'api/ApiQueryReviewedpages.php';
377381 $wgAPIListModules['reviewedpages'] = 'ApiQueryReviewedpages';
378 -
 382+# Flag meta-data for pags
379383 $wgAutoloadClasses['ApiQueryFlagged'] = $dir . 'api/ApiQueryFlagged.php';
380384 $wgAPIPropModules['flagged'] = 'ApiQueryFlagged';
381385
Index: trunk/extensions/FlaggedRevs/api/ApiQueryUnreviewedpages.php
@@ -0,0 +1,188 @@
 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 unreviewed pages
 27+ *
 28+ * @ingroup FlaggedRevs
 29+ */
 30+class ApiQueryUnreviewedpages extends ApiQueryGeneratorBase {
 31+
 32+ public function __construct( $query, $moduleName ) {
 33+ parent::__construct( $query, $moduleName, 'ur' );
 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+ 'page_title',
 56+ 'newer',
 57+ $params['start'],
 58+ $params['end']
 59+ );
 60+ $this->addJoinConds(
 61+ array('flaggedpages' => array ('LEFT JOIN','fp_page_id=page_id') )
 62+ );
 63+ $this->addWhere( 'fp_page_id IS NULL OR
 64+ fp_quality < '.intval($params['filterlevel']) );
 65+ $this->addOption(
 66+ 'USE INDEX',
 67+ array( 'page' => 'name_title', 'flaggedpages' => 'PRIMARY' )
 68+ );
 69+
 70+ if ( is_null( $resultPageSet ) ) {
 71+ $this->addFields( array (
 72+ 'page_id',
 73+ 'page_namespace',
 74+ 'page_title',
 75+ 'page_len',
 76+ 'page_latest',
 77+ ) );
 78+ } else {
 79+ $this->addFields( $resultPageSet->getPageTableFields() );
 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->page_title );
 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+ );
 105+ } else {
 106+ $resultPageSet->processDbRow( $row );
 107+ }
 108+ }
 109+ $db->freeResult( $res );
 110+
 111+ if ( is_null( $resultPageSet ) ) {
 112+ $result = $this->getResult();
 113+ $result->setIndexedTagName( $data, 'p' );
 114+ $result->addValue( 'query', $this->getModuleName(), $data );
 115+ }
 116+ }
 117+
 118+ public function getAllowedParams() {
 119+ global $wgFlaggedRevsNamespaces;
 120+ return array (
 121+ 'start' => array (
 122+ ApiBase::PARAM_TYPE => 'sring'
 123+ ),
 124+ 'end' => array (
 125+ ApiBase::PARAM_TYPE => 'string'
 126+ ),
 127+ 'namespace' => array (
 128+ ApiBase::PARAM_DFLT =>
 129+ !$wgFlaggedRevsNamespaces ?
 130+ NS_MAIN :
 131+ $wgFlaggedRevsNamespaces[0],
 132+ ApiBase::PARAM_TYPE => 'namespace',
 133+ ApiBase::PARAM_ISMULTI => true,
 134+ ),
 135+ 'filterredir' => array (
 136+ ApiBase::PARAM_DFLT => 'all',
 137+ ApiBase::PARAM_TYPE => array (
 138+ 'redirects',
 139+ 'nonredirects',
 140+ 'all'
 141+ )
 142+ ),
 143+ 'filterlevel' => array (
 144+ ApiBase::PARAM_DFLT => 0,
 145+ ApiBase::PARAM_TYPE => 'integer',
 146+ ApiBase::PARAM_MIN => 0,
 147+ ApiBase::PARAM_MAX => 2,
 148+ ),
 149+ 'limit' => array (
 150+ ApiBase::PARAM_DFLT => 10,
 151+ ApiBase::PARAM_TYPE => 'limit',
 152+ ApiBase::PARAM_MIN => 1,
 153+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
 154+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
 155+ )
 156+ );
 157+ }
 158+
 159+ public function getParamDescription() {
 160+ return array (
 161+ 'start' => 'Start listing at this page title.',
 162+ 'end' => 'Stop listing at this page title.',
 163+ 'namespace' => 'The namespaces to enumerate.',
 164+ 'filterredir' => 'How to filter for redirects',
 165+ 'filterlevel' => 'How to filter by quality (0=sighted,1=quality)',
 166+ 'limit' => 'How many total pages to return.',
 167+ );
 168+ }
 169+
 170+ public function getDescription() {
 171+ return array(
 172+ 'Returns a list of pages, that have not been reviewed (to "filterlevel"),',
 173+ 'sorted by page title.'
 174+ );
 175+ }
 176+
 177+ protected function getExamples() {
 178+ return array (
 179+ 'Show a list of unreviewed pages',
 180+ ' api.php?action=query&list=unreviewedpages&urnamespace=0&urfilterlevel=0',
 181+ 'Show info about some unreviewed pages',
 182+ ' api.php?action=query&generator=unreviewedpages&urnamespace=0&gurlimit=4&prop=info',
 183+ );
 184+ }
 185+
 186+ public function getVersion() {
 187+ return __CLASS__.': $Id: ApiQueryUnreviewedpages.php 44870 2008-12-21 12:48:08Z aaron $';
 188+ }
 189+}

Status & tagging log