X-Git-Url: http://git.cyclocoop.org/data/Luca_Pacioli_%28Gemaelde%29.jpeg?a=blobdiff_plain;ds=sidebyside;f=includes%2Fapi%2FApiFeedContributions.php;h=2492db20709b79e052039b2e5ba32fa4abf9ca51;hb=7fba6829efacee250d795c4a78349dad40b3d84e;hp=5bf8da9ff8bd501b19649ff2bc5f110ffaf5e79a;hpb=86529fef92eb87bf6a77aa8352aba0075cb6f728;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiFeedContributions.php b/includes/api/ApiFeedContributions.php index 5bf8da9ff8..fabe4a2e7c 100644 --- a/includes/api/ApiFeedContributions.php +++ b/includes/api/ApiFeedContributions.php @@ -34,6 +34,9 @@ class ApiFeedContributions extends ApiBase { /** @var RevisionStore */ private $revisionStore; + /** @var TitleParser */ + private $titleParser; + /** * This module uses a custom feed wrapper printer. * @@ -45,6 +48,7 @@ class ApiFeedContributions extends ApiBase { public function execute() { $this->revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); + $this->titleParser = MediaWikiServices::getInstance()->getTitleParser(); $params = $this->extractRequestParams(); @@ -67,9 +71,16 @@ class ApiFeedContributions extends ApiBase { ' [' . $config->get( 'LanguageCode' ) . ']'; $feedUrl = SpecialPage::getTitleFor( 'Contributions', $params['user'] )->getFullURL(); - $target = $params['user'] == 'newbies' - ? 'newbies' - : Title::makeTitleSafe( NS_USER, $params['user'] )->getText(); + try { + $target = $this->titleParser + ->parseTitle( $params['user'], NS_USER ) + ->getText(); + } catch ( MalformedTitleException $e ) { + $this->dieWithError( + [ 'apierror-baduser', 'user', wfEscapeWikiText( $params['user'] ) ], + 'baduser_' . $this->encodeParamName( 'user' ) + ); + } $feed = new $feedClasses[$params['feedformat']] ( $feedTitle, @@ -137,8 +148,10 @@ class ApiFeedContributions extends ApiBase { } // Hook completed and did not return a valid feed item - $title = Title::makeTitle( intval( $row->page_namespace ), $row->page_title ); - if ( $title && $title->userCan( 'read', $this->getUser() ) ) { + $title = Title::makeTitle( (int)$row->page_namespace, $row->page_title ); + $user = $this->getUser(); + + if ( $title && $this->getPermissionManager()->userCan( 'read', $user, $title ) ) { $date = $row->rev_timestamp; $comments = $title->getTalkPage()->getFullURL(); $revision = $this->revisionStore->newRevisionFromRow( $row ); @@ -172,33 +185,29 @@ class ApiFeedContributions extends ApiBase { * @return string */ protected function feedItemDesc( RevisionRecord $revision ) { - if ( $revision ) { - $msg = wfMessage( 'colon-separator' )->inContentLanguage()->text(); - try { - $content = $revision->getContent( SlotRecord::MAIN ); - } catch ( RevisionAccessException $e ) { - $content = null; - } - - if ( $content instanceof TextContent ) { - // only textual content has a "source view". - $html = nl2br( htmlspecialchars( $content->getNativeData() ) ); - } else { - // XXX: we could get an HTML representation of the content via getParserOutput, but that may - // contain JS magic and generally may not be suitable for inclusion in a feed. - // Perhaps Content should have a getDescriptiveHtml method and/or a getSourceText method. - // Compare also FeedUtils::formatDiffRow. - $html = ''; - } - - $comment = $revision->getComment(); + $msg = wfMessage( 'colon-separator' )->inContentLanguage()->text(); + try { + $content = $revision->getContent( SlotRecord::MAIN ); + } catch ( RevisionAccessException $e ) { + $content = null; + } - return '

' . htmlspecialchars( $this->feedItemAuthor( $revision ) ) . $msg . - htmlspecialchars( FeedItem::stripComment( $comment ? $comment->text : '' ) ) . - "

\n
\n
" . $html . '
'; + if ( $content instanceof TextContent ) { + // only textual content has a "source view". + $html = nl2br( htmlspecialchars( $content->getText() ) ); + } else { + // XXX: we could get an HTML representation of the content via getParserOutput, but that may + // contain JS magic and generally may not be suitable for inclusion in a feed. + // Perhaps Content should have a getDescriptiveHtml method and/or a getSourceText method. + // Compare also FeedUtils::formatDiffRow. + $html = ''; } - return ''; + $comment = $revision->getComment(); + + return '

' . htmlspecialchars( $this->feedItemAuthor( $revision ) ) . $msg . + htmlspecialchars( FeedItem::stripComment( $comment ? $comment->text : '' ) ) . + "

\n
\n
" . $html . '
'; } public function getAllowedParams() {