Page MenuHomePhabricator

flaggedrevsapi.patch

Authored By
bzimport
Nov 21 2014, 10:11 PM
Size
14 KB
Referenced Files
None
Subscribers
None

flaggedrevsapi.patch

Index: FlaggedRevs.php
===================================================================
--- FlaggedRevs.php (revision 41798)
+++ FlaggedRevs.php (working copy)
@@ -270,6 +270,7 @@
$wgAutoloadClasses['FlaggedRevs'] = $dir.'FlaggedRevs.class.php';
$wgAutoloadClasses['FlaggedRevsHooks'] = $dir.'FlaggedRevs.hooks.php';
+$wgAutoloadClasses['FlaggedRevsApiHooks'] = $dir.'FlaggedRevs.hooks.php';
$wgAutoloadClasses['FRCacheUpdate'] = $dir.'FRCacheUpdate.php';
$wgAutoloadClasses['FRCacheUpdateJob'] = $dir.'FRCacheUpdate.php';
@@ -336,6 +337,11 @@
$wgAutoloadClasses['ValidationStatistics'] = $dir . 'specialpages/ValidationStatistics_body.php';
$wgExtensionMessagesFiles['ValidationStatistics'] = $langDir . 'ValidationStatistics.i18n.php';
$wgSpecialPageGroups['ValidationStatistics'] = 'quality';
+# API Modules
+$wgAutoloadClasses['ApiQueryOldreviewedpages'] = $dir . 'api/ApiQueryOldreviewedpages.php';
+$wgAPIListModules['oldreviewedpages'] = 'ApiQueryOldreviewedpages';
+$wgAutoloadClasses['ApiQueryFlagged'] = $dir . 'api/ApiQueryFlagged.php';
+$wgAPIPropModules['flagged'] = 'ApiQueryFlagged';
######### Hook attachments #########
# Remove stand-alone patrolling
@@ -420,6 +426,10 @@
# Duplicate flagged* tables in parserTests.php
$wgHooks['ParserTestTables'][] = 'FlaggedRevsHooks::onParserTestTables';
+# Add flagging data to ApiQueryRevisions
+$wgHooks['APIGetAllowedParams'][] = 'FlaggedRevsApiHooks::addApiRevisionParams';
+$wgHooks['APIQueryAfterExecute'][] = 'FlaggedRevsApiHooks::addApiRevisionData';
+
#########
function efLoadFlaggedRevs() {
Index: FlaggedRevs.class.php
===================================================================
--- FlaggedRevs.class.php (revision 41798)
+++ FlaggedRevs.class.php (working copy)
@@ -212,6 +212,24 @@
self::load();
return empty(self::$dimensions);
}
+
+ /**
+ * Get corresponding text for the api output of flagging levels
+ *
+ * @param int $level
+ * @return string
+ */
+ public static function getQualityLevelText( $level ) {
+ static $levelText = array(
+ 0 => 'stable',
+ 1 => 'quality',
+ 2 => 'pristine'
+ );
+ if ( isset( $levelText[$level] ) )
+ return $levelText[$level];
+ else
+ return '';
+ }
################# Parsing functions #################
Index: FlaggedRevs.hooks.php
===================================================================
--- FlaggedRevs.hooks.php (revision 41798)
+++ FlaggedRevs.hooks.php (working copy)
@@ -1264,3 +1264,85 @@
return true;
}
}
+
+abstract class FlaggedRevsApiHooks extends ApiQueryBase {
+
+ public static function addApiRevisionParams ( &$module, &$params ) {
+ if (!$module instanceof ApiQueryRevisions)
+ return true;
+ $params['prop'][ApiBase::PARAM_TYPE][] = 'flagged';
+ return true;
+ }
+
+ public static function addApiRevisionData( &$module ) {
+ if (!$module instanceof ApiQueryRevisions)
+ return true;
+ $params = $module->extractRequestParams( false );
+ if ( empty( $params['prop'] ) || !in_array( 'flagged', $params['prop'] ) )
+ return true;
+ if ( !in_array( 'ids', $params['prop'] ) )
+ $module->dieUsage( 'if rvprop=flagged is set, you must also set rvprop=ids', 'missingparam' );
+
+ // Get all requested pageids/revids in a mapping:
+ // pageid => revid => array_index of the revision
+ // we will need this later to add data to the result array
+ $result = $module->getResult();
+ $data = $result->getData();
+ if ( !isset( $data['query'] ) || !isset( $data['query']['pages'] ) )
+ return true;
+ foreach ( $data['query']['pages'] as $pageid => $page )
+ if ( array_key_exists( 'revisions', (array)$page ) )
+ foreach ( $page['revisions'] as $index => $rev )
+ if ( array_key_exists( 'revid', (array)$rev ) )
+ $pageids[$pageid][$rev['revid']] = $index;
+ if ( empty( $pageids ) )
+ return true;
+
+ //Construct SQL Query
+ $db = $module->getDB();
+ $module->resetQueryParams();
+ $module->addTables( array( 'flaggedrevs', 'user' ) );
+ $module->addFields( array(
+ 'fr_page_id',
+ 'fr_rev_id',
+ 'fr_timestamp',
+ 'fr_comment',
+ 'fr_quality',
+ 'fr_tags',
+ 'user_name'
+ ) );
+ $module->addWhere( 'fr_user=user_id' );
+
+ //Construct WHERE-clause to avoid multiplying the number of scanned rows
+ //as flaggedrevs table has composite primary key (fr_page_id,fr_rev_id)
+ foreach ( $pageids as $pageid => $revids )
+ $where[] = $db->makeList( array(
+ 'fr_page_id' => $pageid,
+ 'fr_rev_id' => array_keys( $revids ) ), LIST_AND );
+ $module->addWhere( $db->makeList( $where, LIST_OR ) );
+ $module->addOption( 'USE INDEX', array( 'flaggedrevs' => 'PRIMARY' ) );
+
+ $res = $module->select( __METHOD__ );
+
+ //Add flagging data to result array
+ while ( $row = $db->fetchObject( $res ) ) {
+ $index = $pageids[$row->fr_page_id][$row->fr_rev_id];
+ $data = array(
+ 'user' => $row->user_name,
+ 'timestamp' => wfTimestamp( TS_ISO_8601, $row->fr_timestamp ),
+ 'level' => intval( $row->fr_quality ),
+ 'level_text' => FlaggedRevs::getQualityLevelText( $row->fr_quality ),
+ 'tags' => FlaggedRevision::expandRevisionTags( $row->fr_tags )
+ );
+ if ( $row->fr_comment )
+ $data['comment'] = $row->fr_comment;
+ $result->addValue(
+ array( 'query', 'pages', $row->fr_page_id, 'revisions', $index ),
+ 'flagged',
+ $data
+ );
+ }
+ $db->freeResult( $res );
+ return true;
+ }
+}
Index: api/ApiQueryFlagged.php
===================================================================
--- api/ApiQueryFlagged.php (revision 0)
+++ api/ApiQueryFlagged.php (revision 0)
@@ -0,0 +1,87 @@
+<?php
+
+/*
+ * Created on Sep 17, 2008
+ *
+ * API module for MediaWiki's FlaggedRevs extension
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/**
+ * Query module to get flagging information about pages via 'prop=flagged'
+ *
+ * @ingroup FlaggedRevs
+ */
+class ApiQueryFlagged extends ApiQueryBase {
+
+ public function execute() {
+ $params = $this->extractRequestParams();
+ $pageSet = $this->getPageSet();
+ $pageids = array_keys( $pageSet->getGoodTitles() );
+ if ( !$pageids )
+ return true;
+
+ //Construct SQL Query
+ $this->addTables( 'flaggedpages' );
+ $this->addFields( array(
+ 'fp_page_id', 'fp_stable', 'fp_quality', 'fp_pending_since'
+ ) );
+ $this->addWhereFld( 'fp_page_id', $pageids );
+ $res = $this->select( __METHOD__ );
+
+ $result = $this->getResult();
+ $db = $this->getDB();
+ while ( $row = $db->fetchObject( $res ) ) {
+ $pageid = $row->fp_page_id;
+ $data = array(
+ 'stable_revid' => intval( $row->fp_stable ),
+ 'level' => intval( $row->fp_quality ),
+ 'level_text' => FlaggedRevs::getQualityLevelText( $row->fp_quality )
+ );
+ if ( $row->fp_pending_since )
+ $data['pending_since'] = wfTimestamp( TS_ISO_8601, $row->fp_pending_since );
+ $result->addValue( array( 'query', 'pages', $pageid ), 'flagged', $data );
+ }
+ $db->freeResult( $res );
+ }
+
+ public function getAllowedParams() {
+ return array();
+ }
+
+ public function getDescription() {
+ return array(
+ 'Get information about the flagging status of the given pages.',
+ 'If a page is flagged, the following parameters are returned:',
+ '* stable_revid : The revision id of the latest stable revision',
+ '* level, level_text : The highest flagging level of the page',
+ '* pending_since : If there are any current unreviewed revisions'
+ .' for that page, holds the timestamp of the first of them'
+ );
+ }
+
+ protected function getExamples() {
+ return array (
+ 'api.php?action=query&prop=info|flagged&titles=Main%20Page',
+ 'api.php?action=query&generator=allpages&gapfrom=K&prop=flagged'
+ );
+ }
+
+ public function getVersion() {
+ return __CLASS__.': $Id$';
+ }
+}
Property changes on: api\ApiQueryFlagged.php
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Index: api/ApiQueryOldreviewedpages.php
===================================================================
--- api/ApiQueryOldreviewedpages.php (revision 0)
+++ api/ApiQueryOldreviewedpages.php (revision 0)
@@ -0,0 +1,192 @@
+<?php
+
+/*
+ * Created on Sep 17, 2008
+ *
+ * API module for MediaWiki's FlaggedRevs extension
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/**
+ * Query module to list pages with outdated review flag.
+ *
+ * @ingroup FlaggedRevs
+ */
+class ApiQueryOldreviewedpages extends ApiQueryGeneratorBase {
+
+ public function __construct( $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, 'or' );
+ }
+
+ public function execute() {
+ $this->run();
+ }
+
+ public function executeGenerator( $resultPageSet ) {
+ $this->run( $resultPageSet );
+ }
+
+ private function run( $resultPageSet = null ) {
+ // Permission check
+ global $wgUser;
+ if ( !$wgUser->isAllowed( 'unreviewedpages' ) )
+ $this->dieUsage(
+ "You need the unreviewedpages right to request the list of"
+ ." old reviewed pages.",
+ 'permissiondenied'
+ );
+
+ $params = $this->extractRequestParams();
+
+ // Construct SQL Query
+ $this->addTables( array( 'page', 'flaggedpages' ) );
+ $this->addWhereFld( 'page_namespace', $params['namespace'] );
+ $this->addWhereRange(
+ 'fp_pending_since',
+ $params['dir'],
+ $params['start'],
+ $params['end']
+ );
+ $this->addWhere( 'page_id=fp_page_id' );
+ if ( !isset( $params['start'] ) && !isset( $params['end'] ) )
+ $this->addWhere( 'fp_pending_since IS NOT NULL' );
+ $this->addOption(
+ 'USE INDEX',
+ array( 'flaggedpages' => 'fp_pending_since' )
+ );
+
+ if ( is_null( $resultPageSet ) ) {
+ $this->addFields( array (
+ 'page_id',
+ 'page_namespace',
+ 'page_title',
+ 'page_latest',
+ 'fp_stable',
+ 'fp_pending_since',
+ 'fp_quality'
+ ) );
+ } else {
+ $this->addFields( $resultPageSet->getPageTableFields() );
+ $this->addFields ( 'fp_pending_since' );
+ }
+
+ $limit = $params['limit'];
+ $this->addOption( 'LIMIT', $limit+1 );
+ $res = $this->select( __METHOD__ );
+
+ $data = array ();
+ $count = 0;
+ $db = $this->getDB();
+ while ( $row = $db->fetchObject( $res ) ) {
+ if ( ++$count > $limit ) {
+ // We've reached the one extra which shows that there are
+ // additional pages to be had. Stop here...
+ $this->setContinueEnumParameter(
+ 'start',
+ wfTimestamp( TS_ISO_8601, $row->fp_pending_since )
+ );
+ break;
+ }
+
+ if ( is_null( $resultPageSet ) ) {
+ $title = Title::makeTitle(
+ $row->page_namespace,
+ $row->page_title
+ );
+ $data[] = array(
+ 'pageid' => intval( $row->page_id ),
+ 'ns' => intval( $title->getNamespace() ),
+ 'title' => $title->getPrefixedText(),
+ 'revid' => intval( $row->page_latest ),
+ 'stable_revid' => intval( $row->fp_stable ),
+ 'pending_since' =>
+ wfTimestamp( TS_ISO_8601, $row->fp_pending_since ),
+ 'flagged_level' => intval( $row->fp_quality ),
+ 'flagged_level_text' => FlaggedRevs::getQualityLevelText( $row->fp_quality )
+ );
+ } else {
+ $resultPageSet->processDbRow( $row );
+ }
+ }
+ $db->freeResult( $res );
+
+ if ( is_null( $resultPageSet ) ) {
+ $result = $this->getResult();
+ $result->setIndexedTagName( $data, 'p' );
+ $result->addValue( 'query', $this->getModuleName(), $data );
+ }
+ }
+
+ public function getAllowedParams() {
+ global $wgFlaggedRevsNamespaces;
+ return array (
+ 'start' => array ( ApiBase::PARAM_TYPE => 'timestamp' ),
+ 'end' => array ( ApiBase::PARAM_TYPE => 'timestamp' ),
+ 'dir' => array (
+ ApiBase::PARAM_DFLT => 'newer',
+ ApiBase::PARAM_TYPE => array ( 'newer', 'older' )
+ ),
+ 'namespace' => array (
+ ApiBase::PARAM_DFLT =>
+ !$wgFlaggedRevsNamespaces ? NS_MAIN : $wgFlaggedRevsNamespaces[0],
+ ApiBase :: PARAM_TYPE => 'namespace',
+ ApiBase :: PARAM_ISMULTI => true,
+ ),
+ 'limit' => array (
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
+ )
+ );
+ }
+
+ public function getParamDescription() {
+ return array (
+ 'start' => 'Start listing at this timestamp.',
+ 'end' => 'Stop listing at this timestamp.',
+ 'namespace' => 'The namespaces to enumerate.',
+ 'limit' => 'How many total pages to return.',
+ 'dir' => array(
+ 'In which direction to list.',
+ '*newer: list the longest waiting pages first',
+ '*older: list the newest items first'
+ )
+ );
+ }
+
+ public function getDescription() {
+ return array(
+ 'Returns a list of pages, that have an outdated review flag,',
+ 'sorted by timestamp of the first unreviewed edit of that page.'
+ );
+ }
+
+ protected function getExamples() {
+ return array (
+ 'Show a list of pages with pending unreviewed changes',
+ ' api.php?action=query&list=oldreviewedpages&ornamespace=0',
+ 'Show info about some old reviewed pages',
+ ' api.php?action=query&generator=oldreviewedpages&gorlimit=4&prop=info',
+ );
+ }
+
+ public function getVersion() {
+ return __CLASS__.': $Id$';
+ }
+}
Property changes on: api\ApiQueryOldreviewedpages.php
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4462
Default Alt Text
flaggedrevsapi.patch (14 KB)

Event Timeline