r47231 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47230‎ | r47231 | r47232 >
Date:21:34, 13 February 2009
Author:catrope
Status:deferred (Comments)
Tags:
Comment:
API: (bug 16740) Adding list=protectedtitles to list create-protected titles
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryProtectedTitles.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryProtectedTitles.php
@@ -0,0 +1,193 @@
 2+<?php
 3+
 4+/*
 5+ * Created on Feb 13, 2009
 6+ *
 7+ * API for MediaWiki 1.8+
 8+ *
 9+ * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
 10+ *
 11+ * This program is free software; you can redistribute it and/or modify
 12+ * it under the terms of the GNU General Public License as published by
 13+ * the Free Software Foundation; either version 2 of the License, or
 14+ * (at your option) any later version.
 15+ *
 16+ * This program is distributed in the hope that it will be useful,
 17+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 19+ * GNU General Public License for more details.
 20+ *
 21+ * You should have received a copy of the GNU General Public License along
 22+ * with this program; if not, write to the Free Software Foundation, Inc.,
 23+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 24+ * http://www.gnu.org/copyleft/gpl.html
 25+ */
 26+
 27+if (!defined('MEDIAWIKI')) {
 28+ // Eclipse helper - will be ignored in production
 29+ require_once ('ApiQueryBase.php');
 30+}
 31+
 32+/**
 33+ * Query module to enumerate all available pages.
 34+ *
 35+ * @ingroup API
 36+ */
 37+class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
 38+
 39+ public function __construct($query, $moduleName) {
 40+ parent :: __construct($query, $moduleName, 'pt');
 41+ }
 42+
 43+ public function execute() {
 44+ $this->run();
 45+ }
 46+
 47+ public function executeGenerator($resultPageSet) {
 48+ if ($resultPageSet->isResolvingRedirects())
 49+ $this->dieUsage('Use "gapfilterredir=nonredirects" option instead of "redirects" when using allpages as a generator', 'params');
 50+
 51+ $this->run($resultPageSet);
 52+ }
 53+
 54+ private function run($resultPageSet = null) {
 55+ $db = $this->getDB();
 56+ $params = $this->extractRequestParams();
 57+
 58+ $this->addTables('protected_titles');
 59+ $this->addFields(array('pt_namespace', 'pt_title', 'pt_timestamp'));
 60+
 61+ $prop = array_flip($params['prop']);
 62+ $this->addFieldsIf('pt_user', isset($prop['user']));
 63+ $this->addFieldsIf('pt_reason', isset($prop['comment']));
 64+ $this->addFieldsIf('pt_expiry', isset($prop['expiry']));
 65+ $this->addFieldsIf('pt_create_perm', isset($prop['level']));
 66+
 67+ $this->addWhereRange('pt_timestamp', $params['dir'], $params['start'], $params['end']);
 68+ $this->addWhereFld('pt_namespace', $params['namespace']);
 69+ $this->addWhereFld('pt_create_perm', $params['level']);
 70+
 71+ if(isset($prop['user']))
 72+ {
 73+ $this->addTables('user');
 74+ $this->addFields('user_name');
 75+ $this->addJoinConds(array('user' => array('LEFT JOIN',
 76+ 'user_id=pt_user'
 77+ )));
 78+ }
 79+
 80+ $this->addOption('LIMIT', $params['limit'] + 1);
 81+ $res = $this->select(__METHOD__);
 82+
 83+ $count = 0;
 84+ $result = $this->getResult();
 85+ while ($row = $db->fetchObject($res)) {
 86+ if (++ $count > $params['limit']) {
 87+ // We've reached the one extra which shows that there are additional pages to be had. Stop here...
 88+ $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->pt_timestamp));
 89+ break;
 90+ }
 91+
 92+ $title = Title::makeTitle($row->pt_namespace, $row->pt_title);
 93+ if (is_null($resultPageSet)) {
 94+ $vals = array();
 95+ ApiQueryBase::addTitleInfo($vals, $title);
 96+ if(isset($prop['timestamp']))
 97+ $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->pt_timestamp);
 98+ if(isset($prop['user']) && !is_null($row->user_name))
 99+ $vals['user'] = $row->user_name;
 100+ if(isset($prop['comment']))
 101+ $vals['comment'] = $row->pt_reason;
 102+ if(isset($prop['expiry']))
 103+ $vals['expiry'] = Block::decodeExpiry($row->pt_expiry, TS_ISO_8601);
 104+ if(isset($prop['level']))
 105+ $vals['level'] = $row->pt_create_perm;
 106+
 107+ $fit = $result->addValue(array('query', $this->getModuleName()), null, $vals);
 108+ if(!$fit)
 109+ {
 110+ $this->setContinueEnumParameter('start',
 111+ wfTimestamp(TS_ISO_8601, $row->pt_timestamp));
 112+ break;
 113+ }
 114+ } else {
 115+ $titles[] = $title;
 116+ }
 117+ }
 118+ $db->freeResult($res);
 119+ if(is_null($resultPageSet))
 120+ $result->setIndexedTagName_internal(array('query', $this->getModuleName()), $this->getModulePrefix());
 121+ else
 122+ $resultPageSet->populateFromTitles($titles);
 123+ }
 124+
 125+ public function getAllowedParams() {
 126+ global $wgRestrictionLevels;
 127+ return array (
 128+ 'namespace' => array (
 129+ ApiBase :: PARAM_ISMULTI => true,
 130+ ApiBase :: PARAM_TYPE => 'namespace',
 131+ ),
 132+ 'level' => array(
 133+ ApiBase :: PARAM_ISMULTI => true,
 134+ ApiBase :: PARAM_TYPE => array_diff($wgRestrictionLevels, array(''))
 135+ ),
 136+ 'limit' => array (
 137+ ApiBase :: PARAM_DFLT => 10,
 138+ ApiBase :: PARAM_TYPE => 'limit',
 139+ ApiBase :: PARAM_MIN => 1,
 140+ ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
 141+ ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
 142+ ),
 143+ 'dir' => array (
 144+ ApiBase :: PARAM_DFLT => 'ascending',
 145+ ApiBase :: PARAM_TYPE => array (
 146+ 'ascending',
 147+ 'descending'
 148+ )
 149+ ),
 150+ 'start' => array(
 151+ ApiBase :: PARAM_TYPE => 'timestamp'
 152+ ),
 153+ 'end' => array(
 154+ ApiBase :: PARAM_TYPE => 'timestamp'
 155+ ),
 156+ 'prop' => array(
 157+ ApiBase :: PARAM_ISMULTI => true,
 158+ ApiBase :: PARAM_DFLT => 'timestamp|level',
 159+ ApiBase :: PARAM_TYPE => array(
 160+ 'timestamp',
 161+ 'user',
 162+ 'comment',
 163+ 'expiry',
 164+ 'level'
 165+ )
 166+ ),
 167+ );
 168+ }
 169+
 170+ public function getParamDescription() {
 171+ return array (
 172+ 'namespace' => 'Only list titles in these namespaces',
 173+ 'start' => 'Start listing at this protection timestamp',
 174+ 'end' => 'Stop listing at this protection timestamp',
 175+ 'dir' => 'The direction in which to list',
 176+ 'limit' => 'How many total pages to return.',
 177+ 'prop' => 'Which properties to get',
 178+ );
 179+ }
 180+
 181+ public function getDescription() {
 182+ return 'List all titles protected from creation';
 183+ }
 184+
 185+ protected function getExamples() {
 186+ return array (
 187+ 'api.php?action=query&list=protectedtitles',
 188+ );
 189+ }
 190+
 191+ public function getVersion() {
 192+ return __CLASS__ . ': $Id$';
 193+ }
 194+}
\ No newline at end of file
Property changes on: trunk/phase3/includes/api/ApiQueryProtectedTitles.php
___________________________________________________________________
Name: svn:eol-style
1195 + native
Name: svn:keywords
2196 + Id
Index: trunk/phase3/includes/api/ApiQuery.php
@@ -80,6 +80,7 @@
8181 'exturlusage' => 'ApiQueryExtLinksUsage',
8282 'users' => 'ApiQueryUsers',
8383 'random' => 'ApiQueryRandom',
 84+ 'protectedtitles' => 'ApiQueryProtectedTitles',
8485 );
8586
8687 private $mQueryMetaModules = array (
Index: trunk/phase3/includes/AutoLoader.php
@@ -273,6 +273,7 @@
274274 'ApiQueryLangLinks' => 'includes/api/ApiQueryLangLinks.php',
275275 'ApiQueryLinks' => 'includes/api/ApiQueryLinks.php',
276276 'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php',
 277+ 'ApiQueryProtectedTitles' => 'includes/api/ApiQueryProtectedTitles.php',
277278 'ApiQueryRandom' => 'includes/api/ApiQueryRandom.php',
278279 'ApiQueryRecentChanges'=> 'includes/api/ApiQueryRecentChanges.php',
279280 'ApiQueryRevisions' => 'includes/api/ApiQueryRevisions.php',
Index: trunk/phase3/RELEASE-NOTES
@@ -199,6 +199,7 @@
200200 limit and still set a query-continue in some cases
201201 * (bug 17357) Added movesubpages parameter to action=move
202202 * (bug 17433) Added bot flag to list=watchlist&wlprop=flags output
 203+* (bug 16740) Added list=protectedtitles
203204
204205 === Languages updated in 1.15 ===
205206

Follow-up revisions

RevisionCommit summaryAuthorDate
r47234And yet another fixup for r47231: use older/newer rather than ascending/desce...catrope21:49, 13 February 2009

Comments

#Comment by Catrope (talk | contribs)   21:37, 13 February 2009

Minor fixes in r47232, r47233

#Comment by Catrope (talk | contribs)   21:49, 13 February 2009

and r47234

#Comment by Catrope (talk | contribs)   21:54, 13 February 2009

and r47235

Status & tagging log