Index: trunk/phase3/includes/api/ApiFeedContributions.php |
— | — | @@ -43,56 +43,80 @@ |
44 | 44 | } |
45 | 45 | |
46 | 46 | public function execute() { |
47 | | - $params = $this->extractRequestParams(); |
48 | 47 | |
49 | 48 | global $wgFeed, $wgFeedClasses, $wgSitename, $wgLanguageCode; |
50 | 49 | |
51 | | - if( !$wgFeed ) { |
52 | | - $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' ); |
53 | | - } |
| 50 | + try { |
| 51 | + $params = $this->extractRequestParams(); |
| 52 | + |
| 53 | + if( !$wgFeed ) { |
| 54 | + $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' ); |
| 55 | + } |
| 56 | + |
| 57 | + if( !isset( $wgFeedClasses[ $params['feedformat'] ] ) ) { |
| 58 | + $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' ); |
| 59 | + } |
54 | 60 | |
55 | | - if( !isset( $wgFeedClasses[ $params['feedformat'] ] ) ) { |
56 | | - $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' ); |
57 | | - } |
| 61 | + global $wgMiserMode; |
| 62 | + if ( $params['showsizediff'] && $wgMiserMode ) { |
| 63 | + $this->dieUsage( 'Size difference is disabled in Miser Mode', 'sizediffdisabled' ); |
| 64 | + } |
| 65 | + |
| 66 | + $msg = wfMsgForContent( 'Contributions' ); |
| 67 | + $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']'; |
| 68 | + $feedUrl = SpecialPage::getTitleFor( 'Contributions', $params['user'] )->getFullURL(); |
| 69 | + |
| 70 | + $target = $params['user'] == 'newbies' |
| 71 | + ? 'newbies' |
| 72 | + : Title::makeTitleSafe( NS_USER, $params['user'] )->getText(); |
| 73 | + |
| 74 | + $feed = new $wgFeedClasses[$params['feedformat']] ( |
| 75 | + $feedTitle, |
| 76 | + htmlspecialchars( $msg ), |
| 77 | + $feedUrl |
| 78 | + ); |
| 79 | + |
| 80 | + $pager = new ContribsPager( $this->getContext(), array( |
| 81 | + 'target' => $target, |
| 82 | + 'namespace' => $params['namespace'], |
| 83 | + 'year' => $params['year'], |
| 84 | + 'month' => $params['month'], |
| 85 | + 'tagFilter' => $params['tagfilter'], |
| 86 | + 'deletedOnly' => $params['deletedonly'], |
| 87 | + 'topOnly' => $params['toponly'], |
| 88 | + 'showSizeDiff' => $params['showsizediff'], |
| 89 | + ) ); |
| 90 | + |
| 91 | + $feedItems = array(); |
| 92 | + if( $pager->getNumRows() > 0 ) { |
| 93 | + foreach ( $pager->mResult as $row ) { |
| 94 | + $feedItems[] = $this->feedItem( $row ); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems ); |
| 99 | + |
| 100 | + } catch ( Exception $e ) { |
| 101 | + // Error results should not be cached |
| 102 | + $this->getMain()->setCacheMaxAge( 0 ); |
58 | 103 | |
59 | | - global $wgMiserMode; |
60 | | - if ( $params['showsizediff'] && $wgMiserMode ) { |
61 | | - $this->dieUsage( 'Size difference is disabled in Miser Mode', 'sizediffdisabled' ); |
62 | | - } |
| 104 | + $feedTitle = $wgSitename . ' - Error - ' . wfMsgForContent( 'contributions' ) . ' [' . $wgLanguageCode . ']'; |
| 105 | + $feedUrl = SpecialPage::getTitleFor( 'Contributions', $params['user'] )->getFullURL(); |
63 | 106 | |
64 | | - $msg = wfMsgForContent( 'Contributions' ); |
65 | | - $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']'; |
66 | | - $feedUrl = SpecialPage::getTitleFor( 'Contributions', $params['user'] )->getFullURL(); |
| 107 | + $feedFormat = isset( $params['feedformat'] ) ? $params['feedformat'] : 'rss'; |
| 108 | + $feed = new $wgFeedClasses[$feedFormat] ( $feedTitle, htmlspecialchars( wfMsgForContent( 'contributions' ) ), $feedUrl ); |
67 | 109 | |
68 | | - $target = $params['user'] == 'newbies' |
69 | | - ? 'newbies' |
70 | | - : Title::makeTitleSafe( NS_USER, $params['user'] )->getText(); |
| 110 | + if ( $e instanceof UsageException ) { |
| 111 | + $errorCode = $e->getCodeString(); |
| 112 | + } else { |
| 113 | + // Something is seriously wrong |
| 114 | + $errorCode = 'internal_api_error'; |
| 115 | + } |
71 | 116 | |
72 | | - $feed = new $wgFeedClasses[$params['feedformat']] ( |
73 | | - $feedTitle, |
74 | | - htmlspecialchars( $msg ), |
75 | | - $feedUrl |
76 | | - ); |
77 | | - |
78 | | - $pager = new ContribsPager( $this->getContext(), array( |
79 | | - 'target' => $target, |
80 | | - 'namespace' => $params['namespace'], |
81 | | - 'year' => $params['year'], |
82 | | - 'month' => $params['month'], |
83 | | - 'tagFilter' => $params['tagfilter'], |
84 | | - 'deletedOnly' => $params['deletedonly'], |
85 | | - 'topOnly' => $params['toponly'], |
86 | | - 'showSizeDiff' => $params['showsizediff'], |
87 | | - ) ); |
88 | | - |
89 | | - $feedItems = array(); |
90 | | - if( $pager->getNumRows() > 0 ) { |
91 | | - foreach ( $pager->mResult as $row ) { |
92 | | - $feedItems[] = $this->feedItem( $row ); |
93 | | - } |
| 117 | + $errorText = $e->getMessage(); |
| 118 | + $feedItems[] = new FeedItem( "Error ($errorCode)", $errorText, '', '', '' ); |
| 119 | + ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems ); |
94 | 120 | } |
95 | | - |
96 | | - ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems ); |
97 | 121 | } |
98 | 122 | |
99 | 123 | protected function feedItem( $row ) { |