jenkins-bot has submitted this change and it was merged.

Change subject: Added the read class
......................................................................


Added the read class

Redirected from the create endpoint, receives the annotation ID and fetch the
annotations from the database.

Change-Id: I9289ccf830f3b3558d773f32b06b8ca11d121fa6
---
M Annotator.php
A api/ApiAnnotatorRead.php
M modules/Annotator.js
3 files changed, 49 insertions(+), 1 deletion(-)

Approvals:
  Mattflaschen: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Annotator.php b/Annotator.php
index 7aa2849..69e1e21 100755
--- a/Annotator.php
+++ b/Annotator.php
@@ -24,9 +24,11 @@
 //Autoloading
 $wgAutoloadClasses['AnnotatorHooks'] = $dir . 'Annotator.hooks.php';
 $wgAutoloadClasses['ApiAnnotatorCreate'] = $dir . 'api/ApiAnnotatorCreate.php';
+$wgAutoloadClasses['ApiAnnotatorRead'] = $dir . 'api/ApiAnnotatorRead.php';
 
 //Hooks
 $wgHooks['BeforePageDisplay'][] = 'AnnotatorHooks::onBeforePageDisplay';
 $wgHooks['LoadExtensionSchemaUpdates'][] = 
'AnnotatorHooks::loadExtensionSchemaUpdates';
 
 $wgAPIModules['annotator-create'] = 'ApiAnnotatorCreate';
+$wgAPIModules['annotator-read'] = 'ApiAnnotatorRead';
\ No newline at end of file
diff --git a/api/ApiAnnotatorRead.php b/api/ApiAnnotatorRead.php
new file mode 100644
index 0000000..c206858
--- /dev/null
+++ b/api/ApiAnnotatorRead.php
@@ -0,0 +1,46 @@
+<?php
+class ApiAnnotatorRead extends ApiBase {
+       public function execute() {
+               $params = $this->extractRequestParams();
+               $annotation_id = $params['id']; //get the annotation ID
+
+               $dbr = wfGetDB( DB_SLAVE );
+               //select the annotation object from the database
+               $res = $dbr->select(
+                               'annotator',
+                               array('annotation_json'),
+                               array(
+                                       'annotation_id' => $annotation_id
+                                       )
+                               );
+
+               $row = $dbr->fetchObject( $res );
+
+               //return 404 if annotation is not found
+               if( !$row ) {
+                       $this->dieUsage( "No annotation found", 
'annotation_not_found', 404 );
+               }
+
+               $annotation = json_decode($row->annotation_json);
+
+               $result = $this->getResult();
+
+               $result->addValue( null, 'id', $annotation_id );
+               $result->addValue( null, 'text' , $annotation->text );
+               $result->addValue( null, 'quote', $annotation->quote );
+               $result->addValue( 'ranges', 'start', 
$annotation->ranges[0]->start );
+               $result->addValue( 'ranges', 'startOffset', 
$annotation->ranges[0]->startOffset );
+               $result->addValue( 'ranges', 'end', $annotation->ranges[0]->end 
);
+               $result->addValue( 'ranges', 'endOffset', 
$annotation->ranges[0]->endOffset );
+               return true;
+       }
+
+       public function getAllowedParams() {
+               return array(
+                       'id' =>array(
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_REQUIRED => true
+                               )
+                       );
+       }
+}
\ No newline at end of file
diff --git a/modules/Annotator.js b/modules/Annotator.js
index b396b99..0220402 100755
--- a/modules/Annotator.js
+++ b/modules/Annotator.js
@@ -15,7 +15,7 @@
       urls: {
         create: '?action=annotator-create&format=json&revid=' + revid,
         update: '',
-        read: '',
+        read: '?action=annotator-read&format=json&id=:id',
         destroy: '',
       }
     });

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9289ccf830f3b3558d773f32b06b8ca11d121fa6
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/Annotator
Gerrit-Branch: master
Gerrit-Owner: Rjain <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: Rjain <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to