Index: ApiQueryGlobalUsage.php =================================================================== --- ApiQueryGlobalUsage.php (revision 69060) +++ ApiQueryGlobalUsage.php (working copy) @@ -46,6 +46,7 @@ } $query->setLimit( $params['limit'] ); $query->filterLocal( $params['filterlocal'] ); + $query->ignoreCaseFirstChar(); # Execute the query $query->execute(); Index: GlobalUsageImagePageHooks.php =================================================================== --- GlobalUsageImagePageHooks.php (revision 69060) +++ GlobalUsageImagePageHooks.php (working copy) @@ -14,6 +14,7 @@ if ( !isset( self::$queryCache[$name] ) ) { $query = new GlobalUsageQuery( $title ); $query->filterLocal(); + $query->ignoreCaseFirstChar(); $query->execute(); self::$queryCache[$name] = $query; Index: GlobalUsageQuery.php =================================================================== --- GlobalUsageQuery.php (revision 69060) +++ GlobalUsageQuery.php (working copy) @@ -11,6 +11,7 @@ private $result; private $continue; private $reversed = false; + private $target = null; /** * @param $target mixed Title or db key, or array of db keys of target(s) @@ -235,4 +236,49 @@ public function count() { return count( $this->result ); } + + /** + * Query both the lcfirst and ucfirst versions of the target. + * + * This may be necessary due to different capitalization settings between + * local and foreign wikis. If the foreign wiki is capitalized, both the + * lcfirst and ucfirst version of the filename will refer to the same file, + * so we need to query both. + */ + public function ignoreCaseFirstChar() { + $switchedTarget = array(); + foreach ( (array)$this->target as $target ) { + $file = wfFindFile( $target ); + if ( $file && !$file->getRepo()->initialCapital ) { + # Repo is uncapitalized + continue; + } + + $switched = self::switchCaseFirstChar( $target ); + if ( $switched !== false ) { + $switchedTarget[] = $switched; + } + } + $this->target = array_merge( $this->target, $switched ); + } + + /** + * Return the db key with case switched first char. + * + * @param $dbKey string Db key to switch + * @return mixed Switched db key or false if unswitchable + */ + protected static function switchCaseFirstChar( $dbKey ) { + global $wgContLang; + $lcfirst = $wgContLang->lcfirst( $dbKey ); + if ( $lcfirst !== $dbKey ) { + return $lcfirst; + } + $ucfirst = $wgContLang->ucfirst( $dbKey ); + if ( $ucfirst !== $dbKey ) { + return $ucfirst; + } + return false; + } + } Index: SpecialGlobalUsage.php =================================================================== --- SpecialGlobalUsage.php (revision 69060) +++ SpecialGlobalUsage.php (working copy) @@ -94,6 +94,7 @@ $query->setOffset( $wgRequest->getText( 'to' ), true ); $query->setLimit( $wgRequest->getInt( 'limit', 50 ) ); $query->filterLocal( $this->filterLocal ); + $query->ignoreCaseFirstChar(); // Perform query $query->execute();