Rjain has uploaded a new change for review. https://gerrit.wikimedia.org/r/78251
Change subject: Added support for creating annotations by logged out users ...................................................................... Added support for creating annotations by logged out users The annotations can be created by the logged out users by recording their IP in the annotation_user_text field. However, currently they are not authenticated to destroy and update it. Change-Id: I0f698d1279b796c5cd586f9af0c6f054a76988e2 --- M AnnotationRepository.php M api/ApiAnnotatorCreate.php M modules/Annotator.js M sql/annotator.sql 4 files changed, 16 insertions(+), 36 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Annotator refs/changes/51/78251/1 diff --git a/AnnotationRepository.php b/AnnotationRepository.php index 770570d..063e068 100644 --- a/AnnotationRepository.php +++ b/AnnotationRepository.php @@ -5,24 +5,14 @@ $dbr = wfGetDB( DB_SLAVE ); //select the annotation object from the database $res = $dbr->select( - array('annotator', 'user'), + array('annotator'), array( 'annotation_json', 'annotation_user_id', - 'user_name' + 'annotation_user_text' ), array( 'annotation_id' => $annotation_id - ), - __METHOD__, - array(), - array( - 'user' => array( - 'INNER JOIN', - array( - 'user_id = annotation_user_id' - ) - ) ) ); @@ -31,7 +21,7 @@ return null; } - $annotation = AnnotationRepository::populateAnnotation( $result->annotation_json, $annotation_id, $result->annotation_user_id, $result->user_name ); + $annotation = AnnotationRepository::populateAnnotation( $result->annotation_json, $annotation_id, $result->annotation_user_id, $result->annotation_user_text ); return $annotation; } @@ -39,25 +29,15 @@ //selects annotations of a particular revision ID $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select( - array('annotator', 'user'), + array('annotator'), array( 'annotation' => 'annotation_json', 'id' => 'annotation_id', 'userId' => 'annotation_user_id', - 'userName' => 'user_name' + 'userText' => 'annotation_user_text' ), array( 'rev_id' => $revid - ), - __METHOD__, - array(), - array( - 'user' => array( - 'INNER JOIN', - array( - 'user_id = annotation_user_id' - ) - ) ) ); @@ -65,18 +45,18 @@ $annotations['rows'] = array(); $total = 0; foreach($res as $result) { - $annotations['rows'][] = AnnotationRepository::populateAnnotation( $result->annotation, $result->id, $result->userId, $result->userName ); + $annotations['rows'][] = AnnotationRepository::populateAnnotation( $result->annotation, $result->id, $result->userId, $result->userText ); $total = $total + 1; } $annotations['total'] = $total; return $annotations; } - protected function populateAnnotation( $annotation_json, $annotation_id, $userId, $userName ) { + protected function populateAnnotation( $annotation_json, $annotation_id, $userId, $userText ) { $annotation = json_decode($annotation_json); $annotation->id = $annotation_id; //update the annotation object with the ID $annotation->user->id = $userId; - $annotation->user->username = $userName; + $annotation->user->username = $userText; return $annotation; } } \ No newline at end of file diff --git a/api/ApiAnnotatorCreate.php b/api/ApiAnnotatorCreate.php index 8a0fbda..60b39c7 100755 --- a/api/ApiAnnotatorCreate.php +++ b/api/ApiAnnotatorCreate.php @@ -14,11 +14,14 @@ //checks user log in if( !$user->isLoggedIn() ) { - $this->dieUsage( "Log in to create annotation", 'user_not_logged_in', 401 ); + $user_text = $_SERVER['REMOTE_ADDR']; //Get the IP address if the user is not logged in } //get the current user's ID $user_id = $user->getId(); + + //get the current user's name + $user_text = $user->getName(); //get the Revision ID of the page, sent as a parameter in the API request $params = $this->extractRequestParams(); @@ -41,7 +44,8 @@ array( 'annotation_json' => $annotation, 'rev_id' => $revid, - 'annotation_user_id' => $user_id + 'annotation_user_id' => $user_id, + 'annotation_user_text' => $user_text ) ); $annotation_id = $dbw->insertId(); //get the annotation ID diff --git a/modules/Annotator.js b/modules/Annotator.js index 3a25f07..02083c5 100755 --- a/modules/Annotator.js +++ b/modules/Annotator.js @@ -10,12 +10,7 @@ //Get the userId userId = mw.config.get( 'wgUserId' ); //Call the annotations - if( userId === null ) { - annotations = $( '#mw-content-text' ).annotator({ readOnly: true }); - } - else { - annotations = $( '#mw-content-text' ).annotator(); - } + annotations = $( '#mw-content-text' ).annotator();; //Add the store plugin and modify the urls according to mediawiki api annotations.annotator( 'addPlugin', 'Store', { prefix: mw.util.wikiScript( 'api' ), diff --git a/sql/annotator.sql b/sql/annotator.sql index 47ee692..312a877 100644 --- a/sql/annotator.sql +++ b/sql/annotator.sql @@ -7,5 +7,6 @@ annotation_json text NOT NULL, rev_id int(10) unsigned NOT NULL, annotation_user_id int(10) unsigned NOT NULL + annotation_user_text varchar(255) binary NOT NULL default '', ) /*$wgDBTableOptions*/; -- To view, visit https://gerrit.wikimedia.org/r/78251 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0f698d1279b796c5cd586f9af0c6f054a76988e2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Annotator Gerrit-Branch: master Gerrit-Owner: Rjain <richa.jain1...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits