X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiParse.php;h=0cad5dee9ce0e79a2c4fda5070551cbd171325bc;hb=7c49c10d802445aa775a43144158ce867ebb9274;hp=d53dbb485ff7a61addcdf6d880522b1bb822f291;hpb=9093af0a2874e8bd0f1dc14dc3ba88fff56a4c89;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index d53dbb485f..0cad5dee9c 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -36,6 +36,12 @@ class ApiParse extends ApiBase { /** @var Content $pstContent */ private $pstContent = null; + private function checkReadPermissions( Title $title ) { + if ( !$title->userCan( 'read', $this->getUser() ) ) { + $this->dieUsage( "You don't have permission to view this page", 'permissiondenied' ); + } + } + public function execute() { // The data is hot but user-dependent, like page views, so we set vary cookies $this->getMain()->setCacheMode( 'anon-public-user-private' ); @@ -102,6 +108,8 @@ class ApiParse extends ApiBase { if ( !$rev ) { $this->dieUsage( "There is no revision ID $oldid", 'missingrev' ); } + + $this->checkReadPermissions( $rev->getTitle() ); if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) { $this->dieUsage( "You don't have permission to view deleted revisions", 'permissiondenied' ); } @@ -161,6 +169,8 @@ class ApiParse extends ApiBase { if ( !$titleObj || !$titleObj->exists() ) { $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' ); } + + $this->checkReadPermissions( $titleObj ); $wgTitle = $titleObj; if ( isset( $prop['revid'] ) ) { @@ -345,7 +355,15 @@ class ApiParse extends ApiBase { $titleObj->getPrefixedText(); } - if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) { + if ( isset( $prop['headitems'] ) ) { + $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() ); + $this->logFeatureUsage( 'action=parse&prop=headitems' ); + $this->setWarning( 'headitems is deprecated since MediaWiki 1.28. ' + . 'Use prop=headhtml when creating new HTML documents, or ' + . 'prop=modules|jsconfigvars when updating a document client-side.' ); + } + + if ( isset( $prop['headhtml'] ) ) { $context = new DerivativeContext( $this->getContext() ); $context->setTitle( $titleObj ); $context->setWikiPage( $pageObj ); @@ -355,20 +373,8 @@ class ApiParse extends ApiBase { $output = new OutputPage( $context ); $output->addParserOutputMetadata( $p_result ); - if ( isset( $prop['headitems'] ) ) { - $headItems = $this->formatHeadItems( $p_result->getHeadItems() ); - - $css = $this->formatCss( $output->buildCssLinksArray() ); - - $scripts = [ $output->getHeadScripts() ]; - - $result_array['headitems'] = array_merge( $headItems, $css, $scripts ); - } - - if ( isset( $prop['headhtml'] ) ) { - $result_array['headhtml'] = $output->headElement( $context->getSkin() ); - $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'headhtml'; - } + $result_array['headhtml'] = $output->headElement( $context->getSkin() ); + $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'headhtml'; } if ( isset( $prop['modules'] ) ) { @@ -635,6 +641,8 @@ class ApiParse extends ApiBase { $hiddencats[$row->page_title] = isset( $row->pp_propname ); } + $linkCache = LinkCache::singleton(); + foreach ( $links as $link => $sortkey ) { $entry = []; $entry['sortkey'] = $sortkey; @@ -642,6 +650,14 @@ class ApiParse extends ApiBase { ApiResult::setContentValue( $entry, 'category', (string)$link ); if ( !isset( $hiddencats[$link] ) ) { $entry['missing'] = true; + + // We already know the link doesn't exist in the database, so + // tell LinkCache that before calling $title->isKnown(). + $title = Title::makeTitle( NS_CATEGORY, $link ); + $linkCache->addBadLinkObj( $title ); + if ( $title->isKnown() ) { + $entry['known'] = true; + } } elseif ( $hiddencats[$link] ) { $entry['hidden'] = true; } @@ -705,18 +721,6 @@ class ApiParse extends ApiBase { return $result; } - private function formatCss( $css ) { - $result = []; - foreach ( $css as $file => $link ) { - $entry = []; - $entry['file'] = $file; - ApiResult::setContentValue( $entry, 'link', $link ); - $result[] = $entry; - } - - return $result; - } - private function formatLimitReportData( $limitReportData ) { $result = [];