[MediaWiki-commits] [Gerrit] labs...heritage[master]: Require that orderby parameters are included in requested rows

2016-10-19 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Require that orderby parameters are included in requested rows
..


Require that orderby parameters are included in requested rows

Also move format specific order by from ApiMonuments to the format
file.

Bug: T132644
Change-Id: I3e555ce6f197095b5d3fe0ded850c5050be9b45c
---
M api/includes/ApiMonuments.php
M api/includes/FormatBase.php
M api/includes/FormatHtml.php
M api/includes/FormatKml.php
4 files changed, 26 insertions(+), 3 deletions(-)

Approvals:
  Jean-Frédéric: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/api/includes/ApiMonuments.php b/api/includes/ApiMonuments.php
index 108c1ab..0be7803 100644
--- a/api/includes/ApiMonuments.php
+++ b/api/includes/ApiMonuments.php
@@ -133,6 +133,7 @@
$forceIndex = false;
$orderby = Monuments::$dbPrimaryKey;
$db = Database::getDb();
+   $formatter = $this->getFormatter();
$enableUseLang = true;
$useDefaultLang = false;
$smartFilter = false;
@@ -251,9 +252,12 @@
}
 
/* FIXME: User should be able to set sort fields and order */
-   if ( in_array( $this->getParam( 'format' ), [ 'kml', 'html' ] ) 
) {
-   $orderby = [ 'country', 'municipality', 'address' ];
+   // add format specific order_by
+   $formatOrderby = $formatter->getRequiredOrderBy();
+   if ( $formatOrderby ){
+   $orderby = $formatOrderby;
}
+
$continue = $this->getParam( 'srcontinue' );
if ( $continue && !$spatialMode ) {
$v = explode( '|', $continue );
@@ -267,6 +271,9 @@
}
 
$limit = $this->getParam( 'limit' );
+
+   // add any properties expected to be ordered by
+   $props = array_unique( array_merge( $orderby, $props ) );
 
$res = $db->select( array_merge( Monuments::$dbPrimaryKey, 
$props ), Monuments::$dbTable, $where,
$orderby, $spatialMode ? null : ( $limit + 1 ), 
$forceIndex );
@@ -321,7 +328,6 @@
$res = $rows;
}
 
-   $formatter = $this->getFormatter();
$formatter->setRowFilter(
function( $row ) {
if ( isset( $row->lat ) && isset( $row->lon )
diff --git a/api/includes/FormatBase.php b/api/includes/FormatBase.php
index 80e2181..2d85a40 100644
--- a/api/includes/FormatBase.php
+++ b/api/includes/FormatBase.php
@@ -26,6 +26,15 @@
$this->filter = $callback;
}
 
+   /**
+* Returns an array of properties which are used by the format to
+* order the results by.
+* @return array|null
+*/
+   function getRequiredOrderBy() {
+   return null;
+   }
+
abstract function getContentType();
abstract function outputBegin( $selectedItems );
abstract function outputContinue( $row, $continueKey, $primaryKey );
diff --git a/api/includes/FormatHtml.php b/api/includes/FormatHtml.php
index b177640..7042dff 100644
--- a/api/includes/FormatHtml.php
+++ b/api/includes/FormatHtml.php
@@ -12,6 +12,10 @@
return "text/html";
}
 
+   function getRequiredOrderBy() {
+   return [ 'country', 'municipality', 'address' ];
+   }
+
function headers() {
parent::headers();
echo 'http://www.w3.org/TR/html4/loose.dtd;>';
diff --git a/api/includes/FormatKml.php b/api/includes/FormatKml.php
index 9d4577d..146c5ab 100644
--- a/api/includes/FormatKml.php
+++ b/api/includes/FormatKml.php
@@ -15,6 +15,10 @@
return "application/vnd.google-earth.kml+xml";
}
 
+   function getRequiredOrderBy() {
+   return [ 'country', 'municipality', 'address' ];
+   }
+
function headers() {
parent::headers();
echo '';

-- 
To view, visit https://gerrit.wikimedia.org/r/315488
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3e555ce6f197095b5d3fe0ded850c5050be9b45c
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/heritage
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil 
Gerrit-Reviewer: Jean-Frédéric 
Gerrit-Reviewer: Multichill 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] labs...heritage[master]: Require that orderby parameters are included in requested rows

2016-10-12 Thread Lokal Profil (Code Review)
Lokal Profil has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/315488

Change subject: Require that orderby parameters are included in requested rows
..

Require that orderby parameters are included in requested rows

Also move format specific order by from ApiMonuments to the format
file.

Bug: T132644
Change-Id: I3e555ce6f197095b5d3fe0ded850c5050be9b45c
---
M api/includes/ApiMonuments.php
M api/includes/FormatBase.php
M api/includes/FormatHtml.php
M api/includes/FormatKml.php
4 files changed, 26 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/tools/heritage 
refs/changes/88/315488/1

diff --git a/api/includes/ApiMonuments.php b/api/includes/ApiMonuments.php
index 108c1ab..0be7803 100644
--- a/api/includes/ApiMonuments.php
+++ b/api/includes/ApiMonuments.php
@@ -133,6 +133,7 @@
$forceIndex = false;
$orderby = Monuments::$dbPrimaryKey;
$db = Database::getDb();
+   $formatter = $this->getFormatter();
$enableUseLang = true;
$useDefaultLang = false;
$smartFilter = false;
@@ -251,9 +252,12 @@
}
 
/* FIXME: User should be able to set sort fields and order */
-   if ( in_array( $this->getParam( 'format' ), [ 'kml', 'html' ] ) 
) {
-   $orderby = [ 'country', 'municipality', 'address' ];
+   // add format specific order_by
+   $formatOrderby = $formatter->getRequiredOrderBy();
+   if ( $formatOrderby ){
+   $orderby = $formatOrderby;
}
+
$continue = $this->getParam( 'srcontinue' );
if ( $continue && !$spatialMode ) {
$v = explode( '|', $continue );
@@ -267,6 +271,9 @@
}
 
$limit = $this->getParam( 'limit' );
+
+   // add any properties expected to be ordered by
+   $props = array_unique( array_merge( $orderby, $props ) );
 
$res = $db->select( array_merge( Monuments::$dbPrimaryKey, 
$props ), Monuments::$dbTable, $where,
$orderby, $spatialMode ? null : ( $limit + 1 ), 
$forceIndex );
@@ -321,7 +328,6 @@
$res = $rows;
}
 
-   $formatter = $this->getFormatter();
$formatter->setRowFilter(
function( $row ) {
if ( isset( $row->lat ) && isset( $row->lon )
diff --git a/api/includes/FormatBase.php b/api/includes/FormatBase.php
index 80e2181..2d85a40 100644
--- a/api/includes/FormatBase.php
+++ b/api/includes/FormatBase.php
@@ -26,6 +26,15 @@
$this->filter = $callback;
}
 
+   /**
+* Returns an array of properties which are used by the format to
+* order the results by.
+* @return array|null
+*/
+   function getRequiredOrderBy() {
+   return null;
+   }
+
abstract function getContentType();
abstract function outputBegin( $selectedItems );
abstract function outputContinue( $row, $continueKey, $primaryKey );
diff --git a/api/includes/FormatHtml.php b/api/includes/FormatHtml.php
index b177640..7042dff 100644
--- a/api/includes/FormatHtml.php
+++ b/api/includes/FormatHtml.php
@@ -12,6 +12,10 @@
return "text/html";
}
 
+   function getRequiredOrderBy() {
+   return [ 'country', 'municipality', 'address' ];
+   }
+
function headers() {
parent::headers();
echo 'http://www.w3.org/TR/html4/loose.dtd;>';
diff --git a/api/includes/FormatKml.php b/api/includes/FormatKml.php
index 9d4577d..146c5ab 100644
--- a/api/includes/FormatKml.php
+++ b/api/includes/FormatKml.php
@@ -15,6 +15,10 @@
return "application/vnd.google-earth.kml+xml";
}
 
+   function getRequiredOrderBy() {
+   return [ 'country', 'municipality', 'address' ];
+   }
+
function headers() {
parent::headers();
echo '';

-- 
To view, visit https://gerrit.wikimedia.org/r/315488
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e555ce6f197095b5d3fe0ded850c5050be9b45c
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/heritage
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits