Index: trunk/extensions/RefHelper/RefHelper.i18n.php |
— | — | @@ -25,5 +25,9 @@ |
26 | 26 | 'refhelper-search' => 'Search', |
27 | 27 | 'refhelper-toolbox_link_create' => 'Create reference', |
28 | 28 | 'refhelper-toolbox_link_search' => 'Create reference from search', |
| 29 | + 'refhelper-newarticle_nocitation' => 'There is currently no citation with this name. ', |
| 30 | + 'refhelper-newarticle_suggestions' => "If there is a matching citation from below, you can create this page by clicking on the corresponding \"Create\" button.\n<h2>Suggestions</h2>\n", |
| 31 | + 'refhelper-newarticle_nosuggestions' => "Unfortunately, I was unable to suggest any references. You can [[Special:RefHelper|add the reference manually]] or [[Special:RefSearch|search for the citation to add]].\n", |
| 32 | + |
29 | 33 | ); |
30 | 34 | ?> |
Index: trunk/extensions/RefHelper/RefHelper.php |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | |
46 | 46 | $wgHooks['SkinTemplateToolboxEnd'][] = 'RefHelperHooks::addRefHelperLink'; |
47 | 47 | $wgHooks['BeforePageDisplay'][] = 'RefHelperHooks::addRefHelperJavascript'; |
48 | | - |
| 48 | +$wgHooks['AlternateEdit'][] = 'RefSearch::newArticleHook'; |
49 | 49 | |
50 | 50 | |
51 | 51 | $dir = dirname(__FILE__) . '/'; |
Index: trunk/extensions/RefHelper/RefHelper.create.php |
— | — | @@ -207,7 +207,7 @@ |
208 | 208 | $newcontent = '{{'."$wgRefHelperCiteTemplate\n$paramtext}}\n"; |
209 | 209 | |
210 | 210 | $citePage = new Article( $citeTitle ); |
211 | | - $citePage->doEdit( $newcontent, "Automated page creation." ); |
| 211 | + $citePage->doEdit( $newcontent, wfMsg(self::MSG.'refcreate_autocomment') ); |
212 | 212 | $rev_id = $citePage->insertOn( $db ); |
213 | 213 | |
214 | 214 | $wgOut->addWikiText( wfMsg(self::MSG.'refcreate_success', array("$wgRefHelperCiteNS:$refname") ) ); |
Index: trunk/extensions/RefHelper/RefHelper.hooks.php |
— | — | @@ -5,17 +5,16 @@ |
6 | 6 | } |
7 | 7 | |
8 | 8 | class RefHelperHooks { |
9 | | - function __construct() { |
| 9 | + static function addRefHelperJavascript( $pageObj ) { |
10 | 10 | wfLoadExtensionMessages('RefHelper'); |
11 | | - } |
12 | | - function addRefHelperJavascript( $pageObj ) { |
13 | 11 | global $wgRefHelperExtensionPath; |
14 | 12 | $pageObj->addScript( |
15 | 13 | Xml::element('script',array('src'=>"$wgRefHelperExtensionPath/refhelper.js", 'type'=>'text/javascript') ) ); |
16 | | - return TRUE; |
| 14 | + return true; |
17 | 15 | } |
18 | 16 | |
19 | | - function addRefHelperLink( $tpl ) { |
| 17 | + static function addRefHelperLink( $tpl ) { |
| 18 | + wfLoadExtensionMessages('RefHelper'); |
20 | 19 | global $wgScript; |
21 | 20 | echo Xml::openElement('li',array('class'=>'t-reflink')) . |
22 | 21 | Xml::element('a',array('href'=>"$wgScript?title=Special:RefHelper"), wfMsg( RefHelper::MSG . 'toolbox_link_create' ) ) . |
— | — | @@ -23,6 +22,6 @@ |
24 | 23 | echo Xml::openElement('li',array('class'=>'t-reflink')) . |
25 | 24 | Xml::element('a',array('href'=>"$wgScript?title=Special:RefSearch"), wfMsg( RefHelper::MSG . 'toolbox_link_search' ) ) . |
26 | 25 | Xml::closeElement('li'); |
27 | | - return TRUE; |
| 26 | + return true; |
28 | 27 | } |
29 | 28 | } |
Index: trunk/extensions/RefHelper/RefHelper.search.php |
— | — | @@ -15,8 +15,6 @@ |
16 | 16 | $action = $wgRequest->getText('action'); |
17 | 17 | |
18 | 18 | $query = htmlentities($wgRequest->getText('query')); |
19 | | - $query = str_replace(" ","+",$query); |
20 | | - $reqfilled = strlen($query); |
21 | 19 | |
22 | 20 | # Output |
23 | 21 | $wgOut->addHTML( |
— | — | @@ -42,44 +40,80 @@ |
43 | 41 | Xml::closeElement('table') . |
44 | 42 | Xml::closeElement('form') ); |
45 | 43 | |
| 44 | + $reqfilled = strlen($query); |
46 | 45 | if( $action=="submit" || $reqfilled ) { |
47 | | - $ch = curl_init("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?term=$query&tool=mediawiki_refhelper"); |
48 | | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
49 | | - $result = curl_exec($ch); |
50 | | - curl_close($ch); |
| 46 | + $wgOut->addHTML( self::perform_search( $query ) ); |
| 47 | + } |
| 48 | + $wgOut->addHTML( Xml::closeElement('fieldset') ); |
| 49 | + } |
| 50 | + static function newArticleHook(&$editpage ) { |
| 51 | + wfLoadExtensionMessages('RefHelper'); |
| 52 | + global $wgOut, $wgRefHelperCiteNS; |
51 | 53 | |
52 | | - $num = preg_match_all("|<Id>(\d+)</Id>|", $result, $matches ); |
53 | | - |
54 | | - $wgOut->addHTML(Xml::openElement('table')); |
55 | | - for( $i = 0; $i < $num; $i++ ) { |
56 | | - $pmid = $matches[1][$i]; |
57 | | - $result = self::query_pmid($pmid); |
| 54 | + // don't display if page already exists |
| 55 | + $title = $editpage->getArticle()->getTitle(); |
| 56 | + if( $title->exists() ) return true; |
| 57 | + if( $title->getNsText()!==$wgRefHelperCiteNS) return true; |
58 | 58 | |
59 | | - $author = array_shift($result["authors"]); |
60 | | - if( isset($author) ) $author = $author[1]; |
61 | | - $title = $result["title"]; |
62 | | - $query = $result["query_url"]; |
63 | | - $year = $result["year"]; |
64 | | - if( count($result["AU"]) > 1 ) $etal = " et al."; |
65 | | - else $etal = ""; |
| 59 | + $editpage->setHeaders(); |
66 | 60 | |
67 | | - $wgOut->addHTML( |
68 | | - Xml::openElement('tr') . |
69 | | - Xml::element('td',null,"$author $etal ($year) \"$title\"") . |
70 | | - Xml::openElement('td') . |
71 | | - Xml::openElement('form',array('method'=>'get', 'action'=>$wgScript, 'id'=>"mw-create-ref-form$i")) . |
72 | | - Xml::hidden( 'title', 'Special:RefHelper' ) . |
73 | | - Xml::hidden( 'pmid', $pmid ) . |
74 | | - Xml::element('input',array('value'=>wfMsg(RefHelper::MSG.'create'), 'type'=>'submit')) . |
75 | | - Xml::closeElement('form') . |
76 | | - Xml::closeElement('td') . |
77 | | - Xml::closeElement('tr') ); |
78 | | - } |
79 | | - $wgOut->addHTML( Xml::closeElement('table') ); |
| 61 | + $query = $title->getText(); |
| 62 | + $query = preg_replace('/ ((?>19|20)[0-9]{2})$/',' $1[PDAT]',$query); |
| 63 | + $query = preg_replace('/(?> |^)([^0-9]+) /',' $1[AUTH] ',$query); |
| 64 | + /*$query = preg_replace('/ ([0-9]{4})$/',' $1[PDAT]',$query);*/ |
| 65 | + |
| 66 | + $wgOut->addWikiMsg( RefHelper::MSG . 'newarticle_nocitation'); |
| 67 | + |
| 68 | + $result = self::perform_search( $query ); |
| 69 | + if( $result ) { |
| 70 | + $wgOut->addWikiMsg( RefHelper::MSG . 'newarticle_suggestions'); |
| 71 | + $wgOut->addHTML( $result ); |
80 | 72 | } |
81 | | - $wgOut->addHTML( Xml::closeElement('fieldset') ); |
| 73 | + else { |
| 74 | + $wgOut->addWikiMsg( RefHelper::MSG . 'newarticle_nosuggestions'); |
| 75 | + } |
| 76 | + return false; |
82 | 77 | } |
83 | | - static function parse_medline( $text, $field ) { |
| 78 | + static function perform_search( $query ) { |
| 79 | + global $wgScript; |
| 80 | + $query = str_replace(" ","+",$query); |
| 81 | + $ch = curl_init("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?term=$query&tool=mediawiki_refhelper"); |
| 82 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 83 | + $result = curl_exec($ch); |
| 84 | + curl_close($ch); |
| 85 | + |
| 86 | + $num = preg_match_all("|<Id>(\d+)</Id>|", $result, $matches ); |
| 87 | + if( $num === 0 || $num === false ) return false; |
| 88 | + |
| 89 | + $ret = Xml::openElement('table'); |
| 90 | + for( $i = 0; $i < $num; $i++ ) { |
| 91 | + $pmid = $matches[1][$i]; |
| 92 | + $result = self::query_pmid($pmid); |
| 93 | + |
| 94 | + $author = array_shift($result["authors"]); |
| 95 | + if( isset($author) ) $author = $author[1]; |
| 96 | + $title = $result["title"]; |
| 97 | + $query = $result["query_url"]; |
| 98 | + $year = $result["year"]; |
| 99 | + if( count($result["AU"]) > 1 ) $etal = " et al."; |
| 100 | + else $etal = ""; |
| 101 | + |
| 102 | + $ret .= |
| 103 | + Xml::openElement('tr') . |
| 104 | + Xml::element('td',null,"$author $etal ($year) \"$title\"") . |
| 105 | + Xml::openElement('td') . |
| 106 | + Xml::openElement('form',array('method'=>'get', 'action'=>$wgScript, 'id'=>"mw-create-ref-form$i")) . |
| 107 | + Xml::hidden( 'title', 'Special:RefHelper' ) . |
| 108 | + Xml::hidden( 'pmid', $pmid ) . |
| 109 | + Xml::element('input',array('value'=>wfMsg(RefHelper::MSG.'create'), 'type'=>'submit')) . |
| 110 | + Xml::closeElement('form') . |
| 111 | + Xml::closeElement('td') . |
| 112 | + Xml::closeElement('tr'); |
| 113 | + } |
| 114 | + $ret .= Xml::closeElement('table'); |
| 115 | + return $ret; |
| 116 | + } |
| 117 | + private static function parse_medline( $text, $field ) { |
84 | 118 | $field = strtoupper($field); |
85 | 119 | $num = preg_match_all("|\n$field\s*- (.*)(?>\n (.*))*|", $text, $matches, PREG_SET_ORDER ); |
86 | 120 | $ret = array(); |