r24871 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24870‎ | r24871 | r24872 >
Date:13:26, 17 August 2007
Author:mulligen
Status:old
Tags:
Comment:
automatically update pubmed labels
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/suggest.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/suggest.js
@@ -738,14 +738,41 @@
739739 return value.toLowerCase().substr(0, prefix.length) == prefix.toLowerCase();
740740 }
741741
 742+function IsNumeric(sText){
 743+ var ValidChars = "0123456789. ";
 744+ var IsNumber=true;
 745+ var Char;
 746+
 747+
 748+ for (i = 0; i < sText.length && IsNumber == true; i++){
 749+ Char = sText.charAt(i);
 750+ if (ValidChars.indexOf(Char) == -1){
 751+ IsNumber = false;
 752+ }
 753+ }
 754+ return IsNumber;
 755+}
 756+
 757+function trim(value){
 758+ value = value.replace(/^\s+/,'');
 759+ value = value.replace(/\s+$/,'');
 760+ return value;
 761+}
 762+
742763 function urlFieldChanged(urlField) {
743764 var labelField = document.getElementById(stripSuffix(urlField.id, "url") + "label");
744765 var url = urlField.value;
745 -
746 -// if (startsWith(url, "http://www.ncbi.nlm.nih.gov")) {
747 -// var pubMedId = 1000;
748 -// labelField.value = getPubMedTitle(pubMedId);
749 -// }
 766+
 767+ if (startsWith(url, "http://www.ncbi.nlm.nih.gov") ) {
 768+ pubMedIdRec = ExtractText( url, "TermToSearch=", 0, "&ordinalpos", 0 );
 769+ if ( pubMedIdRec != null ){
 770+ labelField.value = getPubMedTitle(pubMedIdRec[1]);
 771+ }
 772+ }
 773+ else if ( IsNumeric( url ) ){
 774+ labelField.value = getPubMedTitle(trim(url));
 775+ urlField.value = "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=ShowDetailView&TermToSearch=" + trim(url) + "&ordinalpos=1&itool=EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Pubmed_RVDocSum";
 776+ }
750777 }
751778
752779 // Knewco specific Javascript
@@ -815,10 +842,10 @@
816843 }
817844
818845 xmlhttp.open( "GET", "http://"+ HOST + "/knewco/get.py?http://www.ncbi.nlm.nih.gov/entrez/utils/pmfetch.fcgi?db=PubMed&id="+pmid+"&report=xml&mode=text", false );
819 - xmlhttp.send(null);
 846+ xmlhttp.send(null);
820847
821848 if ( xmlhttp.status == 200){
822 - AuthorsRec = ExtractText( xmlhttp.responseText, "<AuthorList>", 0, "</AuthorList>", 0 );
 849+ AuthorsRec = ExtractText( xmlhttp.responseText, "<AuthorList", 0, "</AuthorList>", 0 );
823850 if ( AuthorsRec != null ) {
824851 Authors = AuthorsRec[1];
825852 }
@@ -829,7 +856,7 @@
830857 var Offset = 0;
831858 var AuthorText = "";
832859 while (true) {
833 - AuthorRec = ExtractText( Authors.slice( Offset ), "<Author>", 0, "</Author>", 0 );
 860+ AuthorRec = ExtractText( Authors.slice( Offset ), "<Author", 0, "</Author>", 0 );
834861 if ( AuthorRec == null ){
835862 break;
836863 }
@@ -867,10 +894,15 @@
868895 }
869896 TitleRec = ExtractText( xmlhttp.responseText, "<ArticleTitle>", 0, "</ArticleTitle>", 0 );
870897 if ( TitleRec != null ){
871 - return [AuthorText, TitleRec[1]];
 898+ if ( AuthorText != "" ){
 899+ return AuthorText + ". " + TitleRec[1];
 900+ }
 901+ else {
 902+ return TitleRec[1];
 903+ }
872904 }
873905 else {
874 - return [AuthorText, "unknown title"];
 906+ return AuthorText;
875907 }
876908 }
877909 } catch(e){

Status & tagging log