class ApiImageRotate extends ApiBase {
private $mPageSet = null;
- /**
- * 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 $name If given, name of the value
- */
- private static function addValues( array &$result, $values, $flag = null, $name = null ) {
- foreach ( $values as $val ) {
- if ( $val instanceof Title ) {
- $v = [];
- ApiQueryBase::addTitleInfo( $v, $val );
- } elseif ( $name !== null ) {
- $v = [ $name => $val ];
- } else {
- $v = $val;
- }
- if ( $flag !== null ) {
- $v[$flag] = true;
- }
- $result[] = $v;
- }
- }
-
public function execute() {
$this->useTransactionalTimeLimit();
$result = [];
- self::addValues( $result, $pageSet->getInvalidTitlesAndReasons(), 'invalid' );
- self::addValues( $result, $pageSet->getSpecialTitles(), 'special', 'title' );
- self::addValues( $result, $pageSet->getMissingPageIDs(), 'missing', 'pageid' );
- self::addValues( $result, $pageSet->getMissingRevisionIDs(), 'missing', 'revid' );
- self::addValues( $result, $pageSet->getInterwikiTitlesAsResult() );
+ $result = $pageSet->getInvalidTitlesAndRevisions( [
+ 'invalidTitles', 'special', 'missingIds', 'missingRevIds', 'interwikiTitles',
+ ] );
foreach ( $pageSet->getTitles() as $title ) {
$r = [];
ApiQueryBase::addTitleInfo( $r, $title );
if ( !$title->exists() ) {
$r['missing'] = true;
+ if ( $title->isKnown() ) {
+ $r['known'] = true;
+ }
}
$file = wfFindFile( $title, [ 'latest' => true ] );
* 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 = [];
} else {
$v = $val;
}
- if ( $flag !== null ) {
+ foreach ( $flags as $flag ) {
$v[$flag] = true;
}
$result[] = $v;
$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 );
) {
$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() );
// 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;
// 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;
$hiddencats[$row->page_title] = isset( $row->pp_propname );
}
+ $linkCache = LinkCache::singleton();
+
foreach ( $links as $link => $sortkey ) {
$entry = [];
$entry['sortkey'] = $sortkey;
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;
}