MaxSem has uploaded a new change for review.
https://gerrit.wikimedia.org/r/120817
Change subject: Move a couple of classes into their own files
......................................................................
Move a couple of classes into their own files
Change-Id: I7c20071936d12d6514fbb7ca4091da74a6269f82
---
A Coord.php
A CoordinatesOutput.php
M CoordinatesParserFunction.php
M GeoData.body.php
M GeoData.php
5 files changed, 146 insertions(+), 144 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GeoData
refs/changes/17/120817/1
diff --git a/Coord.php b/Coord.php
new file mode 100644
index 0000000..3c619e3
--- /dev/null
+++ b/Coord.php
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * Class representing coordinates
+ */
+class Coord {
+ public $lat,
+ $lon,
+ $id,
+ $globe,
+ $primary = false,
+ $dim,
+ $type,
+ $name,
+ $country,
+ $region;
+
+ public function __construct( $lat, $lon, $globe = null ) {
+ global $wgDefaultGlobe;
+
+ $this->lat = $lat;
+ $this->lon = $lon;
+ $this->globe = isset( $globe ) ? $globe : $wgDefaultGlobe;
+ }
+
+ public static function newFromRow( $row ) {
+ $c = new Coord( $row->gt_lat, $row->gt_lon );
+ foreach ( self::$fieldMapping as $field => $column ) {
+ if ( isset( $row->$column ) ) {
+ $c->$field = $row->$column;
+ }
+ }
+ return $c;
+ }
+
+ /**
+ * Compares this coordinates with the given coordinates
+ *
+ * @param Coord $coord: Coordinate to compare with
+ * @param int $precision: Comparison precision
+ * @return Boolean
+ */
+ public function equalsTo( $coord, $precision = 6 ) {
+ return isset( $coord )
+ && round( $this->lat, $precision ) == round( $coord->lat,
$precision )
+ && round( $this->lon, $precision ) == round( $coord->lon,
$precision )
+ && $this->globe == $coord->globe;
+ }
+
+ /**
+ * Compares all the fields of this object with the given coordinates
object
+ *
+ * @param Coord $coord: Coordinate to compare with
+ * @param int $precision: Comparison precision
+ * @return Boolean
+ */
+ public function fullyEqualsTo( $coord, $precision = 6 ) {
+ return isset( $coord )
+ && round( $this->lat, $precision ) == round( $coord->lat,
$precision )
+ && round( $this->lon, $precision ) == round( $coord->lon,
$precision )
+ && $this->globe == $coord->globe
+ && $this->primary == $coord->primary
+ && $this->dim == $coord->dim
+ && $this->type == $coord->type
+ && $this->name == $coord->name
+ && $this->country == $coord->country
+ && $this->region == $coord->region;
+ }
+
+ /**
+ * Returns this object's representation suitable for insertion into the
DB via Databse::insert()
+ * @param int $pageId: ID of page associated with this coordinate
+ * @return Array: Associative array in format 'field' => 'value'
+ */
+ public function getRow( $pageId ) {
+ global $wgGeoDataIndexGranularity, $wgGeoDataBackend;
+ $row = array( 'gt_page_id' => $pageId );
+ foreach ( self::$fieldMapping as $field => $column ) {
+ $row[$column] = $this->$field;
+ }
+ if ( $wgGeoDataBackend == 'db' ) {
+ $row['gt_lat_int'] = round( $this->lat *
$wgGeoDataIndexGranularity );
+ $row['gt_lon_int'] = round( $this->lon *
$wgGeoDataIndexGranularity );
+ }
+ return $row;
+ }
+
+ public static $fieldMapping = array(
+ 'id' => 'gt_id',
+ 'lat' => 'gt_lat',
+ 'lon' => 'gt_lon',
+ 'globe' => 'gt_globe',
+ 'primary' => 'gt_primary',
+ 'dim' => 'gt_dim',
+ 'type' => 'gt_type',
+ 'name' => 'gt_name',
+ 'country' => 'gt_country',
+ 'region' => 'gt_region',
+ );
+}
diff --git a/CoordinatesOutput.php b/CoordinatesOutput.php
new file mode 100644
index 0000000..ffa01f0
--- /dev/null
+++ b/CoordinatesOutput.php
@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * Class that holds output of a parse opertion
+ */
+class CoordinatesOutput {
+ public $limitExceeded = false;
+ private $primary = false,
+ $secondary = array();
+
+ public function getCount() {
+ return count( $this->secondary ) + ( $this->primary ? 1 : 0 );
+ }
+
+ public function addPrimary( Coord $c ) {
+ if ( $this->primary ) {
+ throw new MWException( 'Attempted to insert a second
primary coordinate into ' . __CLASS__ );
+ }
+ $this->primary = $c;
+ }
+
+ public function addSecondary( Coord $c ) {
+ if ( $c->primary ) {
+ throw new MWException( 'Attempted to pass a primary
coordinate into ' . __METHOD__ );
+ }
+ $this->secondary[] = $c;
+ }
+
+ public function getPrimary() {
+ return $this->primary;
+ }
+
+ public function getSecondary() {
+ return $this->secondary;
+ }
+
+ public function getAll() {
+ $res = $this->secondary;
+ if ( $this->primary ) {
+ array_unshift( $res, $this->primary );
+ }
+ return $res;
+ }
+}
diff --git a/CoordinatesParserFunction.php b/CoordinatesParserFunction.php
index 214e257..b24af96 100644
--- a/CoordinatesParserFunction.php
+++ b/CoordinatesParserFunction.php
@@ -249,46 +249,3 @@
return wfMessage( $message )->params( $err
)->inContentLanguage()->plain();
}
}
-
-/**
- * Class that holds output of a parse opertion
- */
-class CoordinatesOutput {
- public $limitExceeded = false;
- private $primary = false,
- $secondary = array();
-
- public function getCount() {
- return count( $this->secondary ) + ( $this->primary ? 1 : 0 );
- }
-
- public function addPrimary( Coord $c ) {
- if ( $this->primary ) {
- throw new MWException( 'Attempted to insert a second
primary coordinate into ' . __CLASS__ );
- }
- $this->primary = $c;
- }
-
- public function addSecondary( Coord $c ) {
- if ( $c->primary ) {
- throw new MWException( 'Attempted to pass a primary
coordinate into ' . __METHOD__ );
- }
- $this->secondary[] = $c;
- }
-
- public function getPrimary() {
- return $this->primary;
- }
-
- public function getSecondary() {
- return $this->secondary;
- }
-
- public function getAll() {
- $res = $this->secondary;
- if ( $this->primary ) {
- array_unshift( $res, $this->primary );
- }
- return $res;
- }
-}
diff --git a/GeoData.body.php b/GeoData.body.php
index e9cb1dc..d9288dd 100644
--- a/GeoData.body.php
+++ b/GeoData.body.php
@@ -192,102 +192,3 @@
}
}
}
-
-/**
- * Class representing coordinates
- */
-class Coord {
- public $lat,
- $lon,
- $id,
- $globe,
- $primary = false,
- $dim,
- $type,
- $name,
- $country,
- $region;
-
- public function __construct( $lat, $lon, $globe = null ) {
- global $wgDefaultGlobe;
-
- $this->lat = $lat;
- $this->lon = $lon;
- $this->globe = isset( $globe ) ? $globe : $wgDefaultGlobe;
- }
-
- public static function newFromRow( $row ) {
- $c = new Coord( $row->gt_lat, $row->gt_lon );
- foreach ( self::$fieldMapping as $field => $column ) {
- if ( isset( $row->$column ) ) {
- $c->$field = $row->$column;
- }
- }
- return $c;
- }
-
- /**
- * Compares this coordinates with the given coordinates
- *
- * @param Coord $coord: Coordinate to compare with
- * @param int $precision: Comparison precision
- * @return Boolean
- */
- public function equalsTo( $coord, $precision = 6 ) {
- return isset( $coord )
- && round( $this->lat, $precision ) == round(
$coord->lat, $precision )
- && round( $this->lon, $precision ) == round(
$coord->lon, $precision )
- && $this->globe == $coord->globe;
- }
-
- /**
- * Compares all the fields of this object with the given coordinates
object
- *
- * @param Coord $coord: Coordinate to compare with
- * @param int $precision: Comparison precision
- * @return Boolean
- */
- public function fullyEqualsTo( $coord, $precision = 6 ) {
- return isset( $coord )
- && round( $this->lat, $precision ) == round(
$coord->lat, $precision )
- && round( $this->lon, $precision ) == round(
$coord->lon, $precision )
- && $this->globe == $coord->globe
- && $this->primary == $coord->primary
- && $this->dim == $coord->dim
- && $this->type == $coord->type
- && $this->name == $coord->name
- && $this->country == $coord->country
- && $this->region == $coord->region;
- }
-
- /**
- * Returns this object's representation suitable for insertion into the
DB via Databse::insert()
- * @param int $pageId: ID of page associated with this coordinate
- * @return Array: Associative array in format 'field' => 'value'
- */
- public function getRow( $pageId ) {
- global $wgGeoDataIndexGranularity, $wgGeoDataBackend;
- $row = array( 'gt_page_id' => $pageId );
- foreach ( self::$fieldMapping as $field => $column ) {
- $row[$column] = $this->$field;
- }
- if ( $wgGeoDataBackend == 'db' ) {
- $row['gt_lat_int'] = round( $this->lat *
$wgGeoDataIndexGranularity );
- $row['gt_lon_int'] = round( $this->lon *
$wgGeoDataIndexGranularity );
- }
- return $row;
- }
-
- public static $fieldMapping = array(
- 'id' => 'gt_id',
- 'lat' => 'gt_lat',
- 'lon' => 'gt_lon',
- 'globe' => 'gt_globe',
- 'primary' => 'gt_primary',
- 'dim' => 'gt_dim',
- 'type' => 'gt_type',
- 'name' => 'gt_name',
- 'country' => 'gt_country',
- 'region' => 'gt_region',
- );
-}
diff --git a/GeoData.php b/GeoData.php
index 90d4f89..24457ba 100644
--- a/GeoData.php
+++ b/GeoData.php
@@ -21,8 +21,8 @@
$wgAutoloadClasses['ApiQueryCategoryMembers_GeoData'] =
"$dir/api/ApiQueryCategoryMembers_GeoData.php";
$wgAutoloadClasses['GeoDataQueryExtender'] =
"$dir/api/GeoDataQueryExtender.php";
-$wgAutoloadClasses['Coord'] = "$dir/GeoData.body.php";
-$wgAutoloadClasses['CoordinatesOutput'] = "$dir/CoordinatesParserFunction.php";
+$wgAutoloadClasses['Coord'] = "$dir/Coord.php";
+$wgAutoloadClasses['CoordinatesOutput'] = "$dir/CoordinatesOutput.php";
$wgAutoloadClasses['CoordinatesParserFunction'] =
"$dir/CoordinatesParserFunction.php";
$wgAutoloadClasses['GeoData'] = "$dir/GeoData.body.php";
$wgAutoloadClasses['GeoDataHooks'] = "$dir/GeoDataHooks.php";
--
To view, visit https://gerrit.wikimedia.org/r/120817
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7c20071936d12d6514fbb7ca4091da74a6269f82
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GeoData
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits