MediaWiki
REL1_19
|
00001 <?php 00030 class ApiFeedContributions extends ApiBase { 00031 00032 public function __construct( $main, $action ) { 00033 parent::__construct( $main, $action ); 00034 } 00035 00041 public function getCustomPrinter() { 00042 return new ApiFormatFeedWrapper( $this->getMain() ); 00043 } 00044 00045 public function execute() { 00046 $params = $this->extractRequestParams(); 00047 00048 global $wgFeed, $wgFeedClasses, $wgSitename, $wgLanguageCode; 00049 00050 if( !$wgFeed ) { 00051 $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' ); 00052 } 00053 00054 if( !isset( $wgFeedClasses[ $params['feedformat'] ] ) ) { 00055 $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' ); 00056 } 00057 00058 global $wgMiserMode; 00059 if ( $params['showsizediff'] && $wgMiserMode ) { 00060 $this->dieUsage( 'Size difference is disabled in Miser Mode', 'sizediffdisabled' ); 00061 } 00062 00063 $msg = wfMsgForContent( 'Contributions' ); 00064 $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']'; 00065 $feedUrl = SpecialPage::getTitleFor( 'Contributions', $params['user'] )->getFullURL(); 00066 00067 $target = $params['user'] == 'newbies' 00068 ? 'newbies' 00069 : Title::makeTitleSafe( NS_USER, $params['user'] )->getText(); 00070 00071 $feed = new $wgFeedClasses[$params['feedformat']] ( 00072 $feedTitle, 00073 htmlspecialchars( $msg ), 00074 $feedUrl 00075 ); 00076 00077 $pager = new ContribsPager( $this->getContext(), array( 00078 'target' => $target, 00079 'namespace' => $params['namespace'], 00080 'year' => $params['year'], 00081 'month' => $params['month'], 00082 'tagFilter' => $params['tagfilter'], 00083 'deletedOnly' => $params['deletedonly'], 00084 'topOnly' => $params['toponly'], 00085 'showSizeDiff' => $params['showsizediff'], 00086 ) ); 00087 00088 $feedItems = array(); 00089 if( $pager->getNumRows() > 0 ) { 00090 foreach ( $pager->mResult as $row ) { 00091 $feedItems[] = $this->feedItem( $row ); 00092 } 00093 } 00094 00095 ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems ); 00096 } 00097 00098 protected function feedItem( $row ) { 00099 $title = Title::MakeTitle( intval( $row->page_namespace ), $row->page_title ); 00100 if( $title ) { 00101 $date = $row->rev_timestamp; 00102 $comments = $title->getTalkPage()->getFullURL(); 00103 $revision = Revision::newFromRow( $row ); 00104 00105 return new FeedItem( 00106 $title->getPrefixedText(), 00107 $this->feedItemDesc( $revision ), 00108 $title->getFullURL(), 00109 $date, 00110 $this->feedItemAuthor( $revision ), 00111 $comments 00112 ); 00113 } else { 00114 return null; 00115 } 00116 } 00117 00122 protected function feedItemAuthor( $revision ) { 00123 return $revision->getUserText(); 00124 } 00125 00130 protected function feedItemDesc( $revision ) { 00131 if( $revision ) { 00132 return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) . 00133 htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) . 00134 "</p>\n<hr />\n<div>" . 00135 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>"; 00136 } 00137 return ''; 00138 } 00139 00140 public function getAllowedParams() { 00141 global $wgFeedClasses; 00142 $feedFormatNames = array_keys( $wgFeedClasses ); 00143 return array ( 00144 'feedformat' => array( 00145 ApiBase::PARAM_DFLT => 'rss', 00146 ApiBase::PARAM_TYPE => $feedFormatNames 00147 ), 00148 'user' => array( 00149 ApiBase::PARAM_TYPE => 'user', 00150 ApiBase::PARAM_REQUIRED => true, 00151 ), 00152 'namespace' => array( 00153 ApiBase::PARAM_TYPE => 'namespace', 00154 ApiBase::PARAM_ISMULTI => true 00155 ), 00156 'year' => array( 00157 ApiBase::PARAM_TYPE => 'integer' 00158 ), 00159 'month' => array( 00160 ApiBase::PARAM_TYPE => 'integer' 00161 ), 00162 'tagfilter' => array( 00163 ApiBase::PARAM_ISMULTI => true, 00164 ApiBase::PARAM_TYPE => array_values( ChangeTags::listDefinedTags() ), 00165 ApiBase::PARAM_DFLT => '', 00166 ), 00167 'deletedonly' => false, 00168 'toponly' => false, 00169 'showsizediff' => false, 00170 ); 00171 } 00172 00173 public function getParamDescription() { 00174 return array( 00175 'feedformat' => 'The format of the feed', 00176 'user' => 'What users to get the contributions for', 00177 'namespace' => 'What namespace to filter the contributions by', 00178 'year' => 'From year (and earlier)', 00179 'month' => 'From month (and earlier)', 00180 'tagfilter' => 'Filter contributions that have these tags', 00181 'deletedonly' => 'Show only deleted contributions', 00182 'toponly' => 'Only show edits that are latest revisions', 00183 'showsizediff' => 'Show the size difference between revisions. Disabled in Miser Mode', 00184 ); 00185 } 00186 00187 public function getDescription() { 00188 return 'Returns a user contributions feed'; 00189 } 00190 00191 public function getPossibleErrors() { 00192 return array_merge( parent::getPossibleErrors(), array( 00193 array( 'code' => 'feed-unavailable', 'info' => 'Syndication feeds are not available' ), 00194 array( 'code' => 'feed-invalid', 'info' => 'Invalid subscription feed type' ), 00195 array( 'code' => 'sizediffdisabled', 'info' => 'Size difference is disabled in Miser Mode' ), 00196 ) ); 00197 } 00198 00199 public function getExamples() { 00200 return array( 00201 'api.php?action=feedcontributions&user=Reedy', 00202 ); 00203 } 00204 00205 public function getVersion() { 00206 return __CLASS__ . ': $Id$'; 00207 } 00208 }