r89564 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89563‎ | r89564 | r89565 >
Date:14:50, 6 June 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
* (bug 26763) Make RSS/Atom of user contributions more visible

Add ApiFeedContributions module

Somewhat duplicated against Special:Contributions?feed=atom

Going to strip out that functionality
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/api/ApiFeedContributions.php (added) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -105,6 +105,7 @@
106106 * (bug 28392) mark action=undelete&timestamps as type "timestamp"
107107 * (bug 21346) Make deleted images searchable by hash (disabled in Miser Mode)
108108 * (bug 27595) sha1 search of list=filearchive does not work
 109+* (bug 26763) Make RSS/Atom of user contributions more visible
109110
110111 === Languages updated in 1.19 ===
111112
Index: trunk/phase3/includes/api/ApiMain.php
@@ -60,6 +60,7 @@
6161 'expandtemplates' => 'ApiExpandTemplates',
6262 'parse' => 'ApiParse',
6363 'opensearch' => 'ApiOpenSearch',
 64+ 'feedcontributions' => 'ApiFeedContributions',
6465 'feedwatchlist' => 'ApiFeedWatchlist',
6566 'help' => 'ApiHelp',
6667 'paraminfo' => 'ApiParamInfo',
Index: trunk/phase3/includes/api/ApiFeedContributions.php
@@ -0,0 +1,201 @@
 2+<?php
 3+
 4+/**
 5+ *
 6+ *
 7+ * Created on June 06, 2011
 8+ *
 9+ * Copyright © 2011 Sam Reed
 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+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 24+ * http://www.gnu.org/copyleft/gpl.html
 25+ *
 26+ * @file
 27+ */
 28+
 29+/**
 30+ * @ingroup API
 31+ */
 32+class ApiFeedContributions extends ApiBase {
 33+
 34+ public function __construct( $main, $action ) {
 35+ parent::__construct( $main, $action );
 36+ }
 37+
 38+ /**
 39+ * This module uses a custom feed wrapper printer.
 40+ */
 41+ public function getCustomPrinter() {
 42+ return new ApiFormatFeedWrapper( $this->getMain() );
 43+ }
 44+
 45+ public function execute() {
 46+ $params = $this->extractRequestParams();
 47+
 48+ global $wgFeed, $wgFeedClasses, $wgSitename, $wgLanguageCode;
 49+
 50+ if( !$wgFeed ) {
 51+ $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' );
 52+ }
 53+
 54+ if( !isset( $wgFeedClasses[ $params['feedformat'] ] ) ) {
 55+ $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
 56+ }
 57+
 58+ $msg = wfMsgForContent( 'Contributions' );
 59+ $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']';
 60+ $feedUrl = SpecialPage::getTitleFor( 'Contributions', $params['user'] )->getFullURL();
 61+
 62+ $target = $params['user'] == 'newbies'
 63+ ? 'newbies'
 64+ : Title::makeTitleSafe( NS_USER, $params['user'] )->getText();
 65+
 66+ $feed = new $wgFeedClasses[$params['feedformat']] (
 67+ $feedTitle,
 68+ htmlspecialchars( $msg ),
 69+ $feedUrl
 70+ );
 71+
 72+ $pager = new ContribsPager( array(
 73+ 'target' => $target,
 74+ 'namespace' => $params['namespace'],
 75+ 'year' => $params['year'],
 76+ 'month' => $params['month'],
 77+ 'tagFilter' => $params['tagfilter'],
 78+ 'deletedOnly' => $params['deletedonly'],
 79+ 'topOnly' => $params['toponly'],
 80+ 'showSizeDiff' => $params['showsizediff'],
 81+ ) );
 82+
 83+ $feedItems = array();
 84+ if( $pager->getNumRows() > 0 ) {
 85+ foreach ( $pager->mResult as $row ) {
 86+ $feedItems[] = $this->feedItem( $row );
 87+ }
 88+ }
 89+
 90+ ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems );
 91+ }
 92+
 93+ protected function feedItem( $row ) {
 94+ $title = Title::MakeTitle( intval( $row->page_namespace ), $row->page_title );
 95+ if( $title ) {
 96+ $date = $row->rev_timestamp;
 97+ $comments = $title->getTalkPage()->getFullURL();
 98+ $revision = Revision::newFromTitle( $title, $row->rev_id );
 99+
 100+ return new FeedItem(
 101+ $title->getPrefixedText(),
 102+ $this->feedItemDesc( $revision ),
 103+ $title->getFullURL(),
 104+ $date,
 105+ $this->feedItemAuthor( $revision ),
 106+ $comments
 107+ );
 108+ } else {
 109+ return null;
 110+ }
 111+ }
 112+
 113+ /**
 114+ * @param $revision Revision
 115+ * @return string
 116+ */
 117+ protected function feedItemAuthor( $revision ) {
 118+ return $revision->getUserText();
 119+ }
 120+
 121+ /**
 122+ * @param $revision Revision
 123+ * @return string
 124+ */
 125+ protected function feedItemDesc( $revision ) {
 126+ if( $revision ) {
 127+ return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
 128+ htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) .
 129+ "</p>\n<hr />\n<div>" .
 130+ nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
 131+ }
 132+ return '';
 133+ }
 134+
 135+ public function getAllowedParams() {
 136+ global $wgFeedClasses;
 137+ $feedFormatNames = array_keys( $wgFeedClasses );
 138+ return array (
 139+ 'feedformat' => array(
 140+ ApiBase::PARAM_DFLT => 'rss',
 141+ ApiBase::PARAM_TYPE => $feedFormatNames
 142+ ),
 143+ 'user' => array(
 144+ ApiBase::PARAM_TYPE => 'user',
 145+ ApiBase::PARAM_REQUIRED => true,
 146+ ),
 147+ 'namespace' => array(
 148+ ApiBase::PARAM_TYPE => 'namespace',
 149+ ApiBase::PARAM_ISMULTI => true
 150+ ),
 151+ 'year' => array(
 152+ ApiBase::PARAM_TYPE => 'integer'
 153+ ),
 154+ 'month' => array(
 155+ ApiBase::PARAM_TYPE => 'integer'
 156+ ),
 157+ 'tagfilter' => array(
 158+ ApiBase::PARAM_ISMULTI => true,
 159+ ApiBase::PARAM_TYPE => array_values( ChangeTags::listDefinedTags() ),
 160+ ApiBase::PARAM_DFLT => '',
 161+ ),
 162+ 'deletedonly' => false,
 163+ 'toponly' => false,
 164+ 'showsizediff' => false,
 165+ );
 166+ }
 167+
 168+ public function getParamDescription() {
 169+ return array(
 170+ 'feedformat' => 'The format of the feed',
 171+ 'user' => 'What users to get the contributions for',
 172+ 'namespace' => 'What namespace to filter the contributions by',
 173+ 'year' => 'From year (and earlier)',
 174+ 'month' => 'From month (and earlier)',
 175+ 'tagfilter' => 'Filter contributions that have these tags',
 176+ 'deletedonly' => 'Show only deleted contributions',
 177+ 'toponly' => 'Only show edits that are latest revisions',
 178+ 'showsizediff' => '',
 179+ );
 180+ }
 181+
 182+ public function getDescription() {
 183+ return 'Returns a user contributions feed';
 184+ }
 185+
 186+ public function getPossibleErrors() {
 187+ return array_merge( parent::getPossibleErrors(), array(
 188+ array( 'code' => 'feed-unavailable', 'info' => 'Syndication feeds are not available' ),
 189+ array( 'code' => 'feed-invalid', 'info' => 'Invalid subscription feed type' ),
 190+ ) );
 191+ }
 192+
 193+ protected function getExamples() {
 194+ return array(
 195+ 'api.php?action=feedcontributions&user=Reedy',
 196+ );
 197+ }
 198+
 199+ public function getVersion() {
 200+ return __CLASS__ . ': $Id$';
 201+ }
 202+}
\ No newline at end of file
Property changes on: trunk/phase3/includes/api/ApiFeedContributions.php
___________________________________________________________________
Added: svn:eol-style
1203 + native
Added: svn:keywords
2204 + Id
Index: trunk/phase3/includes/AutoLoader.php
@@ -262,6 +262,7 @@
263263 'ApiEditPage' => 'includes/api/ApiEditPage.php',
264264 'ApiEmailUser' => 'includes/api/ApiEmailUser.php',
265265 'ApiExpandTemplates' => 'includes/api/ApiExpandTemplates.php',
 266+ 'ApiFeedContributions' => 'includes/api/ApiFeedContributions.php',
266267 'ApiFeedWatchlist' => 'includes/api/ApiFeedWatchlist.php',
267268 'ApiFileRevert' => 'includes/api/ApiFileRevert.php',
268269 'ApiFormatBase' => 'includes/api/ApiFormatBase.php',

Sign-offs

UserFlagDate
Aaron Schulzinspected22:57, 2 August 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r89566Followup r89564...reedy14:56, 6 June 2011
r89572Followup r89564...reedy15:34, 6 June 2011
r93936Followup r89564...reedy23:26, 4 August 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   22:56, 2 August 2011
$revision = Revision::newFromTitle( $title, $row->rev_id );

There are not enough fields to use new Revision( $row )?

#Comment by Reedy (talk | contribs)   00:08, 3 August 2011

That reads like a statement, but is appended with a question mark...

Help? :P

#Comment by Aaron Schulz (talk | contribs)   02:31, 3 August 2011

I was curious why you didn't use that to avoid queries.

Status & tagging log