[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * This program is free software; you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation; either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License along 14 * with this program; if not, write to the Free Software Foundation, Inc., 15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 * http://www.gnu.org/copyleft/gpl.html 17 * 18 * @file 19 * @since 1.23 20 */ 21 22 /** 23 * Recent changes feed. 24 * 25 * @ingroup API 26 */ 27 class ApiFeedRecentChanges extends ApiBase { 28 29 /** 30 * This module uses a custom feed wrapper printer. 31 * 32 * @return ApiFormatFeedWrapper 33 */ 34 public function getCustomPrinter() { 35 return new ApiFormatFeedWrapper( $this->getMain() ); 36 } 37 38 /** 39 * Format the rows (generated by SpecialRecentchanges or SpecialRecentchangeslinked) 40 * as an RSS/Atom feed. 41 */ 42 public function execute() { 43 $config = $this->getConfig(); 44 45 $this->params = $this->extractRequestParams(); 46 47 if ( !$config->get( 'Feed' ) ) { 48 $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' ); 49 } 50 51 $feedClasses = $config->get( 'FeedClasses' ); 52 if ( !isset( $feedClasses[$this->params['feedformat']] ) ) { 53 $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' ); 54 } 55 56 $this->getMain()->setCacheMode( 'public' ); 57 if ( !$this->getMain()->getParameter( 'smaxage' ) ) { 58 // bug 63249: This page gets hit a lot, cache at least 15 seconds. 59 $this->getMain()->setCacheMaxAge( 15 ); 60 } 61 62 $feedFormat = $this->params['feedformat']; 63 $specialClass = $this->params['target'] !== null 64 ? 'SpecialRecentchangeslinked' 65 : 'SpecialRecentchanges'; 66 67 $formatter = $this->getFeedObject( $feedFormat, $specialClass ); 68 69 // Everything is passed implicitly via $wgRequest… :( 70 // The row-getting functionality should maybe be factored out of ChangesListSpecialPage too… 71 $rc = new $specialClass(); 72 $rows = $rc->getRows(); 73 74 $feedItems = $rows ? ChangesFeed::buildItems( $rows ) : array(); 75 76 ApiFormatFeedWrapper::setResult( $this->getResult(), $formatter, $feedItems ); 77 } 78 79 /** 80 * Return a ChannelFeed object. 81 * 82 * @param string $feedFormat Feed's format (either 'rss' or 'atom') 83 * @param string $specialClass Relevant special page name (either 'SpecialRecentchanges' or 84 * 'SpecialRecentchangeslinked') 85 * @return ChannelFeed 86 */ 87 public function getFeedObject( $feedFormat, $specialClass ) { 88 if ( $specialClass === 'SpecialRecentchangeslinked' ) { 89 $title = Title::newFromText( $this->params['target'] ); 90 if ( !$title ) { 91 $this->dieUsageMsg( array( 'invalidtitle', $this->params['target'] ) ); 92 } 93 94 $feed = new ChangesFeed( $feedFormat, false ); 95 $feedObj = $feed->getFeedObject( 96 $this->msg( 'recentchangeslinked-title', $title->getPrefixedText() ) 97 ->inContentLanguage()->text(), 98 $this->msg( 'recentchangeslinked-feed' )->inContentLanguage()->text(), 99 SpecialPage::getTitleFor( 'Recentchangeslinked' )->getFullURL() 100 ); 101 } else { 102 $feed = new ChangesFeed( $feedFormat, 'rcfeed' ); 103 $feedObj = $feed->getFeedObject( 104 $this->msg( 'recentchanges' )->inContentLanguage()->text(), 105 $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(), 106 SpecialPage::getTitleFor( 'Recentchanges' )->getFullURL() 107 ); 108 } 109 110 return $feedObj; 111 } 112 113 public function getAllowedParams() { 114 $config = $this->getConfig(); 115 $feedFormatNames = array_keys( $config->get( 'FeedClasses' ) ); 116 117 $ret = array( 118 'feedformat' => array( 119 ApiBase::PARAM_DFLT => 'rss', 120 ApiBase::PARAM_TYPE => $feedFormatNames, 121 ), 122 123 'namespace' => array( 124 ApiBase::PARAM_TYPE => 'namespace', 125 ), 126 'invert' => false, 127 'associated' => false, 128 129 'days' => array( 130 ApiBase::PARAM_DFLT => 7, 131 ApiBase::PARAM_MIN => 1, 132 ApiBase::PARAM_TYPE => 'integer', 133 ), 134 'limit' => array( 135 ApiBase::PARAM_DFLT => 50, 136 ApiBase::PARAM_MIN => 1, 137 ApiBase::PARAM_MAX => $config->get( 'FeedLimit' ), 138 ApiBase::PARAM_TYPE => 'integer', 139 ), 140 'from' => array( 141 ApiBase::PARAM_TYPE => 'timestamp', 142 ), 143 144 'hideminor' => false, 145 'hidebots' => false, 146 'hideanons' => false, 147 'hideliu' => false, 148 'hidepatrolled' => false, 149 'hidemyself' => false, 150 151 'tagfilter' => array( 152 ApiBase::PARAM_TYPE => 'string', 153 ), 154 155 'target' => array( 156 ApiBase::PARAM_TYPE => 'string', 157 ), 158 'showlinkedto' => false, 159 ); 160 161 if ( $config->get( 'AllowCategorizedRecentChanges' ) ) { 162 $ret += array( 163 'categories' => array( 164 ApiBase::PARAM_TYPE => 'string', 165 ApiBase::PARAM_ISMULTI => true, 166 ), 167 'categories_any' => false, 168 ); 169 } 170 171 return $ret; 172 } 173 174 public function getParamDescription() { 175 return array( 176 'feedformat' => 'The format of the feed', 177 'namespace' => 'Namespace to limit the results to', 178 'invert' => 'All namespaces but the selected one', 179 'associated' => 'Include associated (talk or main) namespace', 180 'days' => 'Days to limit the results to', 181 'limit' => 'Maximum number of results to return', 182 'from' => 'Show changes since then', 183 'hideminor' => 'Hide minor changes', 184 'hidebots' => 'Hide changes made by bots', 185 'hideanons' => 'Hide changes made by anonymous users', 186 'hideliu' => 'Hide changes made by registered users', 187 'hidepatrolled' => 'Hide patrolled changes', 188 'hidemyself' => 'Hide changes made by yourself', 189 'tagfilter' => 'Filter by tag', 190 'target' => 'Show only changes on pages linked from this page', 191 'showlinkedto' => 'Show changes on pages linked to the selected page instead', 192 'categories' => 'Show only changes on pages in all of these categories', 193 'categories_any' => 'Show only changes on pages in any of the categories instead', 194 ); 195 } 196 197 public function getDescription() { 198 return 'Returns a recent changes feed'; 199 } 200 201 public function getExamples() { 202 return array( 203 'api.php?action=feedrecentchanges', 204 'api.php?action=feedrecentchanges&days=30' 205 ); 206 } 207 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |