X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiPageSet.php;h=1a509c5c1e0edb487b00b72d9ce86b2ad03d678b;hb=7dd1600e9c04efd5988e99b7182a6e039dbe3575;hp=90438d43664f9e21ad94d1bc69b76e38835e66c7;hpb=2e7f4e48735b0e916336d9166cb1ab1756e0fa9f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 90438d4366..1a509c5c1e 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -23,6 +23,7 @@ * * @file */ +use MediaWiki\MediaWikiServices; /** * This class contains a list of pages that the client has requested. @@ -86,10 +87,10 @@ class ApiPageSet extends ApiBase { * Add all items from $values into the result * @param array $result Output * @param array $values Values to add - * @param string $flag The name of the boolean flag to mark this element + * @param string[] $flags The names of boolean flags to mark this element * @param string $name If given, name of the value */ - private static function addValues( array &$result, $values, $flag = null, $name = null ) { + private static function addValues( array &$result, $values, $flags = [], $name = null ) { foreach ( $values as $val ) { if ( $val instanceof Title ) { $v = []; @@ -99,7 +100,7 @@ class ApiPageSet extends ApiBase { } else { $v = $val; } - if ( $flag !== null ) { + foreach ( $flags as $flag ) { $v[$flag] = true; } $result[] = $v; @@ -309,8 +310,9 @@ class ApiPageSet extends ApiBase { $pageFlds['page_lang'] = null; } - // only store non-default fields - $this->mRequestedPageFields = array_diff_key( $this->mRequestedPageFields, $pageFlds ); + foreach ( LinkCache::getSelectFields() as $field ) { + $pageFlds[$field] = null; + } $pageFlds = array_merge( $pageFlds, $this->mRequestedPageFields ); @@ -495,10 +497,14 @@ class ApiPageSet extends ApiBase { * @since 1.21 */ public function getNormalizedTitlesAsResult( $result = null ) { + global $wgContLang; + $values = []; foreach ( $this->getNormalizedTitles() as $rawTitleStr => $titleStr ) { + $encode = ( $wgContLang->normalize( $rawTitleStr ) !== $rawTitleStr ); $values[] = [ - 'from' => $rawTitleStr, + 'fromencoded' => $encode, + 'from' => $encode ? rawurlencode( $rawTitleStr ) : $rawTitleStr, 'to' => $titleStr ]; } @@ -596,19 +602,39 @@ class ApiPageSet extends ApiBase { ) { $result = []; if ( in_array( 'invalidTitles', $invalidChecks ) ) { - self::addValues( $result, $this->getInvalidTitlesAndReasons(), 'invalid' ); + self::addValues( $result, $this->getInvalidTitlesAndReasons(), [ 'invalid' ] ); } if ( in_array( 'special', $invalidChecks ) ) { - self::addValues( $result, $this->getSpecialTitles(), 'special', 'title' ); + $known = []; + $unknown = []; + foreach ( $this->getSpecialTitles() as $title ) { + if ( $title->isKnown() ) { + $known[] = $title; + } else { + $unknown[] = $title; + } + } + self::addValues( $result, $unknown, [ 'special', 'missing' ] ); + self::addValues( $result, $known, [ 'special' ] ); } if ( in_array( 'missingIds', $invalidChecks ) ) { - self::addValues( $result, $this->getMissingPageIDs(), 'missing', 'pageid' ); + self::addValues( $result, $this->getMissingPageIDs(), [ 'missing' ], 'pageid' ); } if ( in_array( 'missingRevIds', $invalidChecks ) ) { - self::addValues( $result, $this->getMissingRevisionIDs(), 'missing', 'revid' ); + self::addValues( $result, $this->getMissingRevisionIDs(), [ 'missing' ], 'revid' ); } if ( in_array( 'missingTitles', $invalidChecks ) ) { - self::addValues( $result, $this->getMissingTitles(), 'missing' ); + $known = []; + $unknown = []; + foreach ( $this->getMissingTitles() as $title ) { + if ( $title->isKnown() ) { + $known[] = $title; + } else { + $unknown[] = $title; + } + } + self::addValues( $result, $unknown, [ 'missing' ] ); + self::addValues( $result, $known, [ 'missing', 'known' ] ); } if ( in_array( 'interwikiTitles', $invalidChecks ) ) { self::addValues( $result, $this->getInterwikiTitlesAsResult() ); @@ -730,6 +756,8 @@ class ApiPageSet extends ApiBase { // Store Title object in various data structures $title = Title::newFromRow( $row ); + LinkCache::singleton()->addGoodLinkObjFromRow( $title, $row ); + $pageId = intval( $row->page_id ); $this->mAllPages[$row->page_namespace][$row->page_title] = $pageId; $this->mTitles[] = $title; @@ -859,9 +887,11 @@ class ApiPageSet extends ApiBase { // Any items left in the $remaining list are added as missing if ( $processTitles ) { // The remaining titles in $remaining are non-existent pages + $linkCache = LinkCache::singleton(); foreach ( $remaining as $ns => $dbkeys ) { foreach ( array_keys( $dbkeys ) as $dbkey ) { $title = Title::makeTitle( $ns, $dbkey ); + $linkCache->addBadLinkObj( $title ); $this->mAllPages[$ns][$dbkey] = $this->mFakePageId; $this->mMissingPages[$ns][$dbkey] = $this->mFakePageId; $this->mGoodAndMissingPages[$ns][$dbkey] = $this->mFakePageId; @@ -886,7 +916,7 @@ class ApiPageSet extends ApiBase { } // Get gender information - $genderCache = GenderCache::singleton(); + $genderCache = MediaWikiServices::getInstance()->getGenderCache(); $genderCache->doQuery( $usernames, __METHOD__ ); } @@ -1168,7 +1198,7 @@ class ApiPageSet extends ApiBase { } } // Get gender information - $genderCache = GenderCache::singleton(); + $genderCache = MediaWikiServices::getInstance()->getGenderCache(); $genderCache->doQuery( $usernames, __METHOD__ ); return $linkBatch; @@ -1326,7 +1356,7 @@ class ApiPageSet extends ApiBase { /** * Get the database connection (read-only) - * @return DatabaseBase + * @return Database */ protected function getDB() { return $this->mDbSource->getDB(); @@ -1403,6 +1433,23 @@ class ApiPageSet extends ApiBase { return $result; } + protected function handleParamNormalization( $paramName, $value, $rawValue ) { + parent::handleParamNormalization( $paramName, $value, $rawValue ); + + if ( $paramName === 'titles' ) { + // For the 'titles' parameter, we want to split it like ApiBase would + // and add any changed titles to $this->mNormalizedTitles + $value = $this->explodeMultiValue( $value, self::LIMIT_SML2 + 1 ); + $l = count( $value ); + $rawValue = $this->explodeMultiValue( $rawValue, $l ); + for ( $i = 0; $i < $l; $i++ ) { + if ( $value[$i] !== $rawValue[$i] ) { + $this->mNormalizedTitles[$rawValue[$i]] = $value[$i]; + } + } + } + } + private static $generators = null; /**