Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 15 |
GeoData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 15 |
getPageCoordinates | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
getAllCoordinates | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 8 |
|||
getDB | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
<?php | |
namespace GeoData; | |
use MediaWiki\MediaWikiServices; | |
use Title; | |
use Wikimedia\Rdbms\IDatabase; | |
class GeoData { | |
/** | |
* Returns primary coordinates of the given page, if any | |
* @param Title $title | |
* @return Coord|bool Coordinates or false | |
*/ | |
public static function getPageCoordinates( Title $title ) { | |
$coords = self::getAllCoordinates( $title->getArticleID(), [ 'gt_primary' => 1 ] ); | |
if ( $coords ) { | |
return $coords[0]; | |
} | |
return false; | |
} | |
/** | |
* Retrieves all coordinates for the given page id | |
* | |
* @param int $pageId ID of the page | |
* @param array $conds Conditions for IDatabase::select() | |
* @param int $dbType Database to select from DB_PRIMARY or DB_REPLICA | |
* @return Coord[] | |
*/ | |
public static function getAllCoordinates( int $pageId, array $conds = [], int $dbType = DB_REPLICA ): array { | |
$db = self::getDB( $dbType ); | |
$conds['gt_page_id'] = $pageId; | |
$columns = array_values( Coord::FIELD_MAPPING ); | |
$res = $db->select( 'geo_tags', $columns, $conds, __METHOD__ ); | |
$coords = []; | |
foreach ( $res as $row ) { | |
$coords[] = Coord::newFromRow( $row ); | |
} | |
return $coords; | |
} | |
/** | |
* @param int $dbType DB_PRIMARY or DB_REPLICA | |
* @return IDatabase | |
*/ | |
private static function getDB( int $dbType ): IDatabase { | |
return MediaWikiServices::getInstance() | |
->getDBLoadBalancer() | |
->getConnection( $dbType ); | |
} | |
} |