r23668 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23667‎ | r23668 | r23669 >
Date:15:11, 3 July 2007
Author:catrope
Status:old
Tags:
Comment:
apiedit: API: adding list=deletedrevs module, improving token caching in prop=info
Modified paths:
  • /branches/apiedit/phase3/includes/AutoLoader.php (modified) (history)
  • /branches/apiedit/phase3/includes/api/ApiQuery.php (modified) (history)
  • /branches/apiedit/phase3/includes/api/ApiQueryDeletedrevs.php (added) (history)
  • /branches/apiedit/phase3/includes/api/ApiQueryInfo.php (modified) (history)

Diff [purge]

Index: branches/apiedit/phase3/includes/AutoLoader.php
@@ -312,6 +312,7 @@
313313 'ApiQueryCategories' => 'includes/api/ApiQueryCategories.php',
314314 'ApiQueryCategoryMembers' => 'includes/api/ApiQueryCategoryMembers.php',
315315 'ApiQueryContributions' => 'includes/api/ApiQueryUserContributions.php',
 316+ 'ApiQueryDeletedrevs' => 'includes/api/ApiQueryDeletedrevs.php',
316317 'ApiQueryExternalLinks' => 'includes/api/ApiQueryExternalLinks.php',
317318 'ApiQueryImages' => 'includes/api/ApiQueryImages.php',
318319 'ApiQueryInfo' => 'includes/api/ApiQueryInfo.php',
Index: branches/apiedit/phase3/includes/api/ApiQueryDeletedrevs.php
@@ -0,0 +1,232 @@
 2+<?php
 3+
 4+/*
 5+ * Created on June 30, 2007
 6+ *
 7+ * API for MediaWiki 1.8+
 8+ *
 9+ * Copyright (C) 2007 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+ * @addtogroup API
 36+ */
 37+class ApiQueryDeletedrevs extends ApiQueryBase {
 38+
 39+ public function __construct($query, $moduleName) {
 40+ parent :: __construct($query, $moduleName, 'dr');
 41+ }
 42+
 43+ public function execute() {
 44+ $this->run();
 45+ }
 46+
 47+ private function run() {
 48+
 49+ global $wgUser;
 50+ // Before doing anything at all, let's check permissions
 51+ if(!$wgUser->isAllowed('deletedhistory'))
 52+ $this->dieUsage('You don\'t have permission to view deleted revisions', 'permissiondenied');
 53+
 54+ $db = $this->getDB();
 55+ $params = $this->extractRequestParams();
 56+ $prop = array_flip($params['prop']);
 57+ $fld_revid = isset($prop['revid']);
 58+ $fld_user = isset($prop['user']);
 59+ $fld_comment = isset($prop['comment']);
 60+ $fld_minor = isset($prop['minor']);
 61+ $fld_len = isset($prop['len']);
 62+ $fld_content = isset($prop['content']);
 63+ $fld_token = isset($prop['token']);
 64+
 65+ $result = $this->getResult();
 66+ $pageSet = $this->getPageSet();
 67+ $titles = $pageSet->getTitles();
 68+ $data = array();
 69+
 70+ $this->addTables('archive');
 71+ $this->addFields(array('ar_title', 'ar_namespace', 'ar_timestamp'));
 72+ if($fld_revid)
 73+ $this->addFields('ar_rev_id');
 74+ if($fld_user)
 75+ $this->addFields('ar_user_text');
 76+ if($fld_comment)
 77+ $this->addFields('ar_comment');
 78+ if($fld_minor)
 79+ $this->addFields('ar_minor_edit');
 80+ if($fld_len)
 81+ $this->addFields('ar_len');
 82+ if($fld_content)
 83+ {
 84+ $this->addTables('text');
 85+ $this->addFields(array('ar_text', 'ar_text_id', 'old_text', 'old_flags'));
 86+ $this->addWhere('ar_text_id = old_id');
 87+
 88+ // This also means stricter limits
 89+ $userMax = 50;
 90+ $botMax = 200;
 91+ $this->validateLimit('limit', $params['limit'], 1, $userMax, $botMax);
 92+ }
 93+ if($fld_token)
 94+ // Undelete tokens are identical for all pages, so we cache one here
 95+ $token = $wgUser->editToken();
 96+
 97+ // We need a custom WHERE clause that matches all titles.
 98+ if(count($titles) > 0)
 99+ {
 100+ $lb = new LinkBatch($titles);
 101+ $where = $lb->constructSet('ar', $db);
 102+ $this->addWhere($where);
 103+ }
 104+
 105+ $this->addOption('LIMIT', $params['limit'] + 1);
 106+ $this->addWhereRange('ar_timestamp', $params['dir'], $params['start'], $params['end']);
 107+ if(isset($params['namespace']))
 108+ $this->addWhereFld('ar_namespace', $params['namespace']);
 109+ $res = $this->select(__METHOD__);
 110+ $pages = array();
 111+ $count = 0;
 112+ // First populate the $pages array
 113+ while($row = $db->fetchObject($res))
 114+ {
 115+ if($count++ == $params['limit'])
 116+ {
 117+ // We've had enough
 118+ $this->setContinueEnumParameter('start', $row->ar_timestamp);
 119+ break;
 120+ }
 121+
 122+ $rev = array();
 123+ $rev['timestamp'] = $row->ar_timestamp;
 124+ if($fld_revid)
 125+ $rev['revid'] = $row->ar_rev_id;
 126+ if($fld_user)
 127+ $rev['user'] = $row->ar_user_text;
 128+ if($fld_comment)
 129+ $rev['comment'] = $row->ar_comment;
 130+ if($fld_minor)
 131+ if($row->ar_minor_edit == 1)
 132+ $rev['minor'] = '';
 133+ if($fld_len)
 134+ $rev['len'] = $row->ar_len;
 135+ if($fld_content)
 136+ ApiResult::setContent($rev, Revision::getRevisionText($row));
 137+
 138+ $t = Title::makeTitle($row->ar_namespace, $row->ar_title);
 139+ if(!isset($pages[$t->getPrefixedText()]))
 140+ {
 141+ $pages[$t->getPrefixedText()] = array(
 142+ 'title' => $t->getPrefixedText(),
 143+ 'ns' => intval($row->ar_namespace),
 144+ 'revisions' => array($rev)
 145+ );
 146+ if($fld_token)
 147+ $pages[$t->getPrefixedText()]['token'] = $token;
 148+ }
 149+ else
 150+ $pages[$t->getPrefixedText()]['revisions'][] = $rev;
 151+ }
 152+ $db->freeResult($res);
 153+
 154+ // We don't want entire pagenames as keys, so let's make this array indexed
 155+ foreach($pages as $page)
 156+ {
 157+ $result->setIndexedTagName($page['revisions'], 'rev');
 158+ $data[] = $page;
 159+ }
 160+ $result->setIndexedTagName($data, 'page');
 161+ $result->addValue('query', $this->getModuleName(), $data);
 162+ }
 163+
 164+ protected function getAllowedParams() {
 165+ return array (
 166+ 'start' => array(
 167+ ApiBase :: PARAM_TYPE => 'timestamp'
 168+ ),
 169+ 'end' => array(
 170+ ApiBase :: PARAM_TYPE => 'timestamp',
 171+ ),
 172+ 'dir' => array(
 173+ ApiBase :: PARAM_TYPE => array(
 174+ 'newer',
 175+ 'older'
 176+ ),
 177+ ApiBase :: PARAM_DFLT => 'older'
 178+ ),
 179+ 'namespace' => array(
 180+ ApiBase :: PARAM_ISMULTI => true,
 181+ ApiBase :: PARAM_TYPE => 'namespace'
 182+ ),
 183+ 'limit' => array(
 184+ ApiBase :: PARAM_DFLT => 10,
 185+ ApiBase :: PARAM_TYPE => 'limit',
 186+ ApiBase :: PARAM_MIN => 1,
 187+ ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
 188+ ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
 189+ ),
 190+ 'prop' => array(
 191+ ApiBase :: PARAM_DFLT => 'user|comment',
 192+ ApiBase :: PARAM_TYPE => array(
 193+ 'revid',
 194+ 'user',
 195+ 'comment',
 196+ 'minor',
 197+ 'len',
 198+ 'content',
 199+ 'token'
 200+ ),
 201+ ApiBase :: PARAM_ISMULTI => true
 202+ )
 203+ );
 204+ }
 205+
 206+ protected function getParamDescription() {
 207+ return array (
 208+ 'start' => 'The timestamp to start enumerating from',
 209+ 'end' => 'The timestamp to stop enumerating at',
 210+ 'dir' => 'The direction in which to enumerate',
 211+ 'namespace' => 'The namespaces to search in',
 212+ 'limit' => 'The maximum amount of revisions to list',
 213+ 'prop' => 'Which properties to get'
 214+ );
 215+ }
 216+
 217+ protected function getDescription() {
 218+ return 'List deleted revisions.';
 219+ }
 220+
 221+ protected function getExamples() {
 222+ return array (
 223+ 'List the first 50 deleted revisions in the Category and Category talk namespaces',
 224+ ' api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=14|15',
 225+ 'List the last deleted revisions of Main Page and Talk:Main Page, with content:',
 226+ ' api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&drprop=user|comment|content'
 227+ );
 228+ }
 229+
 230+ public function getVersion() {
 231+ return __CLASS__ . ': $Id: ApiQueryDeletedrevs.php 23531 2007-06-30 01:19:14Z simetrical $';
 232+ }
 233+}
Property changes on: branches/apiedit/phase3/includes/api/ApiQueryDeletedrevs.php
___________________________________________________________________
Added: svn:eol-style
1234 + native
Index: branches/apiedit/phase3/includes/api/ApiQueryInfo.php
@@ -103,7 +103,7 @@
104104 $lastrevby[intval($row->rev_id)] = $row->rev_user_text;
105105 }
106106
107 - $et = null; // Cached edit token is stored here
 107+ $cachedToken = $wgUser->editToken(); // We cache universal tokens like edit,delete,etc.
108108 foreach ( $titles as $pageid => $title ) {
109109 $pageInfo = array (
110110 'touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]),
@@ -144,16 +144,7 @@
145145 case 'delete':
146146 case 'protect':
147147 case 'unprotect':
148 - // All these tokens are constant, so we can cache them
149 - if(!is_null($et))
150 - $tokenArr[$token] = $et;
151 - else
152 - {
153 - if($wgUser->isAnon())
154 - $et = $tokenArr[$token] = EDIT_TOKEN_SUFFIX;
155 - else
156 - $et = $tokenArr[$token] = $wgUser->editToken();
157 - }
 148+ $tokenArr[$token] = $cachedToken;
158149 // default: can't happen, ignore it if it does happen in some weird way
159150 }
160151 if(count($tokenArr) > 0)
Index: branches/apiedit/phase3/includes/api/ApiQuery.php
@@ -63,6 +63,7 @@
6464 'allpages' => 'ApiQueryAllpages',
6565 'backlinks' => 'ApiQueryBacklinks',
6666 'categorymembers' => 'ApiQueryCategoryMembers',
 67+ 'deletedrevs' => 'ApiQueryDeletedrevs',
6768 'embeddedin' => 'ApiQueryBacklinks',
6869 'imageusage' => 'ApiQueryBacklinks',
6970 'logevents' => 'ApiQueryLogEvents',

Status & tagging log