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