Index: trunk/extensions/RefHelper/RefHelper.i18n.php |
— | — | @@ -1,42 +1,41 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Internationalisation file for extension RefHelper. |
5 | | - * |
6 | | - * @addtogroup Extensions |
7 | | -*/ |
8 | | - |
9 | | -$messages = array(); |
10 | | - |
11 | | -$messages['en'] = array( |
12 | | - 'refhelper' => 'Reference helper', |
13 | | - 'refsearch' => 'Reference search', /* not sure how to use the below */ |
14 | | - 'refhelper-desc' => 'Helps to create pages for references', |
15 | | - 'refhelper-refsearch' => 'Reference search', |
16 | | - 'refhelper-refcreate_legend' => 'Create new reference', |
17 | | - 'refhelper-refsearch_legend' => 'Search PubMed for references', |
18 | | - 'refhelper-refcreate_another' => 'Create another reference', |
19 | | - 'refhelper-refcreate_autocomment' => 'Automated page creation.', |
20 | | - 'refhelper-refcreate_success' => "The page [[$1]] didn't exist and has been created.", |
21 | | - 'refhelper-refcreate_failure' => 'The page [[$1]] already exists!', |
22 | | - 'refhelper-label_workspace' => 'Workspace (copy and paste area):', |
23 | | - 'refhelper-label_authorforename' => "Author $1's first name:", |
24 | | - 'refhelper-label_authorsurname' => 'Surname:', |
25 | | - 'refhelper-title' => 'Title:', |
26 | | - 'refhelper-journal' => 'Journal:', |
27 | | - 'refhelper-volume' => 'Volume:', |
28 | | - 'refhelper-pages' => 'Pages:', |
29 | | - 'refhelper-year' => 'Year:', |
30 | | - 'refhelper-refname' => 'Ref name:', |
31 | | - 'refhelper-category' => 'Category $1:', |
32 | | - 'refhelper-create' => 'Create', |
33 | | - 'refhelper-search' => 'Search', |
34 | | - 'refhelper-toolbox_link_create' => 'Create reference', |
35 | | - 'refhelper-toolbox_link_search' => 'Create reference from search', |
36 | | - 'refhelper-newarticle_nocitation' => 'There is currently no citation with this name.', |
37 | | - 'refhelper-newarticle_suggestions' => 'If there is a matching citation from below, you can create this page by clicking on the corresponding "Create" button. |
38 | | - |
39 | | -<h2>Suggestions</h2>', |
40 | | - 'refhelper-newarticle_nosuggestions' => 'Unfortunately, I was unable to suggest any references. |
41 | | -You can [[Special:RefHelper|add the reference manually]] or [[Special:RefSearch|search for the citation to add]].', |
42 | | -); |
43 | | - |
| 2 | +<?php
|
| 3 | +/**
|
| 4 | + * Internationalisation file for extension RefHelper.
|
| 5 | + *
|
| 6 | + * @addtogroup Extensions
|
| 7 | +*/
|
| 8 | +
|
| 9 | +$messages = array();
|
| 10 | +
|
| 11 | +$messages['en'] = array(
|
| 12 | + 'refhelper' => 'Reference helper',
|
| 13 | + 'refsearch' => 'Reference search', /* not sure how to use the below */
|
| 14 | + 'refhelper-desc' => 'Helps to create pages for references',
|
| 15 | + 'refhelper-refsearch' => 'Reference search',
|
| 16 | + 'refhelper-refcreate_legend' => 'Create new reference',
|
| 17 | + 'refhelper-refsearch_legend' => 'Search PubMed for references',
|
| 18 | + 'refhelper-refcreate_another' => 'Create another reference',
|
| 19 | + 'refhelper-refcreate_autocomment' => 'Automated page creation.',
|
| 20 | + 'refhelper-refcreate_success' => "The page [[$1]] didn't exist and has been created.",
|
| 21 | + 'refhelper-refcreate_failure' => 'The page [[$1]] already exists!',
|
| 22 | + 'refhelper-label_workspace' => 'Workspace (copy and paste area):',
|
| 23 | + 'refhelper-label_authorforename' => "Author $1's first name:",
|
| 24 | + 'refhelper-label_authorsurname' => 'Surname:',
|
| 25 | + 'refhelper-title' => 'Title:',
|
| 26 | + 'refhelper-journal' => 'Journal:',
|
| 27 | + 'refhelper-volume' => 'Volume:',
|
| 28 | + 'refhelper-pages' => 'Pages:',
|
| 29 | + 'refhelper-year' => 'Year:',
|
| 30 | + 'refhelper-refname' => 'Ref name:',
|
| 31 | + 'refhelper-category' => 'Category $1:',
|
| 32 | + 'refhelper-create' => 'Create',
|
| 33 | + 'refhelper-search' => 'Search',
|
| 34 | + 'refhelper-toolbox_link_create' => 'Create reference',
|
| 35 | + 'refhelper-toolbox_link_search' => 'Create reference from search',
|
| 36 | + 'refhelper-newarticle_nocitation' => 'There is currently no citation with this name.',
|
| 37 | + 'refhelper-newarticle_suggestions' => 'If there is a matching citation from below, you can create this page by clicking on the corresponding "Create" button.
|
| 38 | +
|
| 39 | +<h2>Suggestions</h2>',
|
| 40 | + 'refhelper-newarticle_nosuggestions' => 'Unfortunately, I was unable to suggest any references.
|
| 41 | +You can [[Special:RefHelper|add the reference manually]] or [[Special:RefSearch|search for the citation to add]].',
|
| 42 | +);
|
Index: trunk/extensions/RefHelper/RefHelper.php |
— | — | @@ -1,62 +1,61 @@ |
2 | | -<?php |
3 | | -/* |
4 | | - The RefHelper extension is free software: you can redistribute it |
5 | | - and/or modify it under the terms of the GNU General Public License |
6 | | - as published by the Free Software Foundation, either version 3 of |
7 | | - the License, or (at your option) any later version. |
8 | | - |
9 | | - This program is distributed WITHOUT ANY WARRANTY. See |
10 | | - http://www.gnu.org/licenses/#GPL for more details. |
11 | | -*/ |
12 | | - |
13 | | -if (!defined('MEDIAWIKI')) { |
14 | | - echo <<<EOT |
15 | | -To install my extension, put the following line in LocalSettings.php: |
16 | | -require_once( "\$IP/extensions/RefHelper/RefHelper.php" ); |
17 | | -EOT; |
18 | | - exit( 1 ); |
19 | | -} |
20 | | - |
21 | | -$wgExtensionCredits['specialpage'][] = array( |
22 | | - 'path' => __FILE__, |
23 | | - 'name' => 'RefHelper', |
24 | | - 'author' => 'Jonathan Williford', |
25 | | - 'url' => 'http://www.mediawiki.org/wiki/Extension:RefHelper', |
26 | | - 'description' => 'This extension helps create pages for references.', |
27 | | - 'descriptionmsg' => 'refhelper-desc', |
28 | | - 'version' => '0.0.2', |
29 | | -); |
30 | | - |
31 | | -// user configurable parameters |
32 | | -/** $wfRefHelperCiteTemplate specifies the template that is used to create |
33 | | - the citation page (the page in the $wgRefHelperCiteNS namespace). Prefix |
34 | | - with subst if you want a substitution performed. |
35 | | -*/ |
36 | | -$wgRefHelperCiteTemplate = "subst:Template:RefHelperCite"; |
37 | | -/** $wfRefHelperPageTemplate specifies the template that is used to create |
38 | | - the normal page (the page in MAIN_NS). */ |
39 | | -$wgRefHelperPageTemplate = "subst:Template:RefHelperPage"; |
40 | | -/** The name of the namespace used for the citations. */ |
41 | | -$wgRefHelperCiteNS = "Cite"; |
42 | | -/** The http path to the extension, used to find the javascript file */ |
43 | | -$wgRefHelperExtensionPath = "/w/extensions/RefHelper/"; |
44 | | - |
45 | | -global $wgHooks; |
46 | | - |
47 | | -$wgHooks['SkinTemplateToolboxEnd'][] = 'RefHelperHooks::addRefHelperLink'; |
48 | | -$wgHooks['BeforePageDisplay'][] = 'RefHelperHooks::addRefHelperJavascript'; |
49 | | -$wgHooks['AlternateEdit'][] = 'RefSearch::newArticleHook'; |
50 | | - |
51 | | - |
52 | | -$dir = dirname(__FILE__) . '/'; |
53 | | - |
54 | | -$wgAutoloadClasses['RefHelperHooks'] = $dir . 'RefHelper.hooks.php'; |
55 | | -$wgAutoloadClasses['RefHelper'] = $dir . 'RefHelper.create.php'; |
56 | | -$wgAutoloadClasses['RefSearch'] = $dir . 'RefHelper.search.php'; |
57 | | -$wgExtensionMessagesFiles['RefHelper'] = $dir . 'RefHelper.i18n.php'; |
58 | | -$wgExtensionAliasesFiles['RefHelper'] = $dir . 'RefHelper.alias.php'; |
59 | | -$wgSpecialPages['RefHelper'] = 'RefHelper'; |
60 | | -$wgSpecialPages['RefSearch'] = 'RefSearch'; |
61 | | -$wgSpecialPageGroups['RefHelper'] = 'other'; |
62 | | -$wgSpecialPageGroups['RefSearch'] = 'other'; |
63 | | - |
| 2 | +<?php
|
| 3 | +/*
|
| 4 | + The RefHelper extension is free software: you can redistribute it
|
| 5 | + and/or modify it under the terms of the GNU General Public License
|
| 6 | + as published by the Free Software Foundation, either version 3 of
|
| 7 | + the License, or (at your option) any later version.
|
| 8 | +
|
| 9 | + This program is distributed WITHOUT ANY WARRANTY. See
|
| 10 | + http://www.gnu.org/licenses/#GPL for more details.
|
| 11 | +*/
|
| 12 | +
|
| 13 | +if ( !defined( 'MEDIAWIKI' ) ) {
|
| 14 | + echo <<<EOT
|
| 15 | +To install my extension, put the following line in LocalSettings.php:
|
| 16 | +require_once( "\$IP/extensions/RefHelper/RefHelper.php" );
|
| 17 | +EOT;
|
| 18 | + exit( 1 );
|
| 19 | +}
|
| 20 | +
|
| 21 | +$wgExtensionCredits['specialpage'][] = array(
|
| 22 | + 'path' => __FILE__,
|
| 23 | + 'name' => 'RefHelper',
|
| 24 | + 'author' => 'Jonathan Williford',
|
| 25 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:RefHelper',
|
| 26 | + 'description' => 'This extension helps create pages for references.',
|
| 27 | + 'descriptionmsg' => 'refhelper-desc',
|
| 28 | + 'version' => '0.0.2',
|
| 29 | +);
|
| 30 | +
|
| 31 | +// user configurable parameters
|
| 32 | +/** $wfRefHelperCiteTemplate specifies the template that is used to create
|
| 33 | + the citation page (the page in the $wgRefHelperCiteNS namespace). Prefix
|
| 34 | + with subst if you want a substitution performed.
|
| 35 | +*/
|
| 36 | +$wgRefHelperCiteTemplate = "subst:Template:RefHelperCite";
|
| 37 | +/** $wfRefHelperPageTemplate specifies the template that is used to create
|
| 38 | + the normal page (the page in MAIN_NS). */
|
| 39 | +$wgRefHelperPageTemplate = "subst:Template:RefHelperPage";
|
| 40 | +/** The name of the namespace used for the citations. */
|
| 41 | +$wgRefHelperCiteNS = "Cite";
|
| 42 | +/** The http path to the extension, used to find the javascript file */
|
| 43 | +$wgRefHelperExtensionPath = "/w/extensions/RefHelper/";
|
| 44 | +
|
| 45 | +global $wgHooks;
|
| 46 | +
|
| 47 | +$wgHooks['SkinTemplateToolboxEnd'][] = 'RefHelperHooks::addRefHelperLink';
|
| 48 | +$wgHooks['BeforePageDisplay'][] = 'RefHelperHooks::addRefHelperJavascript';
|
| 49 | +$wgHooks['AlternateEdit'][] = 'RefSearch::newArticleHook';
|
| 50 | +
|
| 51 | +
|
| 52 | +$dir = dirname( __FILE__ ) . '/';
|
| 53 | +
|
| 54 | +$wgAutoloadClasses['RefHelperHooks'] = $dir . 'RefHelper.hooks.php';
|
| 55 | +$wgAutoloadClasses['RefHelper'] = $dir . 'RefHelper.create.php';
|
| 56 | +$wgAutoloadClasses['RefSearch'] = $dir . 'RefHelper.search.php';
|
| 57 | +$wgExtensionMessagesFiles['RefHelper'] = $dir . 'RefHelper.i18n.php';
|
| 58 | +$wgExtensionAliasesFiles['RefHelper'] = $dir . 'RefHelper.alias.php';
|
| 59 | +$wgSpecialPages['RefHelper'] = 'RefHelper';
|
| 60 | +$wgSpecialPages['RefSearch'] = 'RefSearch';
|
| 61 | +$wgSpecialPageGroups['RefHelper'] = 'other';
|
| 62 | +$wgSpecialPageGroups['RefSearch'] = 'other';
|
Index: trunk/extensions/RefHelper/RefHelper.create.php |
— | — | @@ -1,235 +1,238 @@ |
2 | | -<?php |
3 | | -class RefHelper extends SpecialPage { |
4 | | - const MSG = 'refhelper-'; |
5 | | - function __construct() { |
6 | | - parent::__construct( 'RefHelper','edit',true,false,'default',false ); |
7 | | - wfLoadExtensionMessages('RefHelper'); |
8 | | - } |
9 | | - /** A simple helper function to output the html of a table row with an input box. |
10 | | - @param $out $wgOut should be passed |
11 | | - @param $varname the string of the GET variable name |
12 | | - @param $varval the value of the GET variable name |
13 | | - @param $label the text describing the variable |
14 | | - */ |
15 | | - private function addTableRow( &$out, $varname, $varval, $label, $size = 50 ) { |
16 | | - $out->addHTML( Xml::openElement('tr')); |
17 | | - $out->addHTML( Xml::openElement('td',array('class'=>'mw-label'))); |
18 | | - $out->addHTML( Xml::element('label',array('for'=>$varname),"$label")); |
19 | | - $out->addHTML( Xml::closeElement('td')); |
20 | | - $out->addHTML( Xml::openElement('td')); |
21 | | - $out->addHTML( Xml::input($varname,$size,$varval,array('id'=>"inp_$varname"))); |
22 | | - $out->addHTML( Xml::closeElement('td')); |
23 | | - $out->addHTML( Xml::closeElement('tr')); |
24 | | - } |
25 | | - /** Another simple helper function to output the html of a table row, but with two input boxes. |
26 | | - See addTableRow for parameter details |
27 | | - */ |
28 | | - private function add2ColTableRow( &$out, $varname1, $varname2, $varval1, $varval2, $label1, $label2 ) { |
29 | | - $out->addHTML( Xml::openElement('tr')); |
30 | | - $out->addHTML( Xml::openElement('td',array('class'=>'mw-label'))); |
31 | | - $out->addHTML( Xml::element('label', array('for'=>$varname1),"$label1")); |
32 | | - $out->addHTML( Xml::closeElement('td')); |
33 | | - $out->addHTML( Xml::openElement('td')); |
34 | | - $out->addHTML( Xml::input($varname1,15,$varval1,array('id'=>"inp_$varname1",'oninput'=>'updateFirstName(event)'))); |
35 | | - $out->addHTML( Xml::element('label', array('for'=>$varname2)," $label2: ")); |
36 | | - $out->addHTML( Xml::input($varname2,20,$varval2,array('id'=>"inp_$varname2",'oninput'=>'updateSurname(event)'))); |
37 | | - $out->addHTML( Xml::closeElement('td')); |
38 | | - $out->addHTML( Xml::closeElement('tr')); |
39 | | - } |
40 | | - |
41 | | - /** Create the html body and (depending on the GET variables) creates the page. |
42 | | - */ |
43 | | - function execute( $par ) { |
44 | | - global $wgRequest, $wgOut, $wgScript; |
45 | | - |
46 | | - $this->setHeaders(); |
47 | | - |
48 | | - # Get request data from, e.g. |
49 | | - $action = $wgRequest->getText('action'); |
50 | | - $refname = htmlentities($wgRequest->getText('refname')); |
51 | | - $author1 = htmlentities($wgRequest->getText('author1'), ENT_COMPAT, "UTF-8"); |
52 | | - $author2 = htmlentities($wgRequest->getText('author2'), ENT_COMPAT, "UTF-8"); |
53 | | - $author3 = htmlentities($wgRequest->getText('author3'), ENT_COMPAT, "UTF-8"); |
54 | | - $author4 = htmlentities($wgRequest->getText('author4'), ENT_COMPAT, "UTF-8"); |
55 | | - $author5 = htmlentities($wgRequest->getText('author5'), ENT_COMPAT, "UTF-8"); |
56 | | - |
57 | | - $surname1 = htmlentities($wgRequest->getText('surname1'), ENT_COMPAT, "UTF-8"); |
58 | | - $surname2 = htmlentities($wgRequest->getText('surname2'), ENT_COMPAT, "UTF-8"); |
59 | | - $surname3 = htmlentities($wgRequest->getText('surname3'), ENT_COMPAT, "UTF-8"); |
60 | | - $surname4 = htmlentities($wgRequest->getText('surname4'), ENT_COMPAT, "UTF-8"); |
61 | | - $surname5 = htmlentities($wgRequest->getText('surname5'), ENT_COMPAT, "UTF-8"); |
62 | | - |
63 | | - $pmid = htmlentities($wgRequest->getText('pmid'), ENT_COMPAT, "UTF-8"); |
64 | | - |
65 | | - $articletitle = htmlentities($wgRequest->getText('articletitle')); |
66 | | - $journal = htmlentities($wgRequest->getText('journal')); |
67 | | - $volume = htmlentities($wgRequest->getText('volume')); |
68 | | - $pages = htmlentities($wgRequest->getText('pages')); |
69 | | - $year = htmlentities($wgRequest->getText('year')); |
70 | | - |
71 | | - $cat1 = htmlentities($wgRequest->getText('cat1')); |
72 | | - $cat2 = htmlentities($wgRequest->getText('cat2')); |
73 | | - $cat3 = htmlentities($wgRequest->getText('cat3')); |
74 | | - $cat4 = htmlentities($wgRequest->getText('cat4')); |
75 | | - |
76 | | - $reqfilled = strlen($author1) && strlen($articletitle) && strlen($journal) && strlen($year) && strlen($refname); |
77 | | - if( $action!="submit" || !$reqfilled ) { |
78 | | - if( strlen($pmid) ) { |
79 | | - $result = RefSearch::query_pmid($pmid); |
80 | | - $articletitle = $result["title"]; |
81 | | - $journal = $result["journal"]; |
82 | | - $volume = $result["volume"]; |
83 | | - $pages = $result["pages"]; |
84 | | - $year = $result["year"]; |
85 | | - $auths = $result["authors"]; |
86 | | - if( isset( $auths[0] ) ) { |
87 | | - $author1 = $auths[0][0]; |
88 | | - $surname1 = $auths[0][1]; |
89 | | - } |
90 | | - if( isset( $auths[1] ) ) { |
91 | | - $author2 = $auths[1][0]; |
92 | | - $surname2 = $auths[1][1]; |
93 | | - } |
94 | | - if( isset( $auths[2] ) ) { |
95 | | - $author3 = $auths[2][0]; |
96 | | - $surname3 = $auths[2][1]; |
97 | | - } |
98 | | - if( isset( $auths[3] ) ) { |
99 | | - $author4 = $auths[3][0]; |
100 | | - $surname4 = $auths[3][1]; |
101 | | - } |
102 | | - if( isset( $auths[4] ) ) { |
103 | | - $author5 = $auths[4][0]; |
104 | | - $surname5 = $auths[4][1]; |
105 | | - } |
106 | | - } |
107 | | - |
108 | | - # Output |
109 | | - $wgOut->addHTML( |
110 | | - Xml::fieldset( wfMsg(self::MSG.'refcreate_legend') ) . |
111 | | - Xml::openElement( 'form', array('action'=>$wgScript,'id'=>'mw_create-ref-form') ) . |
112 | | - Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) . |
113 | | - Xml::hidden( 'action', 'submit' ) . |
114 | | - Xml::openElement('table',array('id'=>'mw_create-ref-table')) . |
115 | | - Xml::openElement('tbody') ); |
116 | | - |
117 | | - $wgOut->addHTML( |
118 | | - Xml::openElement('tr') . |
119 | | - Xml::openElement('td',array('class'=>'mw-label')) . |
120 | | - Xml::element('label',array('for'=>'inp_pastearea'), wfMsg(self::MSG.'label_workspace').":") . |
121 | | - Xml::closeElement('td') . |
122 | | - Xml::openElement('td') . |
123 | | - Xml::textarea('inp_pastearea','',20,5,array('oninput'=>'autoPopulateRefFields()')) . |
124 | | - Xml::closeElement('td') . |
125 | | - Xml::closeElement('tr')); |
126 | | - |
127 | | - self::addTableRow( $wgOut, "pmid", $pmid, 'PMID', 15 ); |
128 | | - |
129 | | - self::add2ColTableRow( $wgOut, 'author1', 'surname1', $author1, $surname1, |
130 | | - wfMsg(self::MSG.'label_authorforename','1'),wfMsg(self::MSG.'label_authorsurname','1')); |
131 | | - self::add2ColTableRow( $wgOut, 'author2', 'surname2', $author2, $surname2, |
132 | | - wfMsg(self::MSG.'label_authorforename','2'),wfMsg(self::MSG.'label_authorsurname','2')); |
133 | | - self::add2ColTableRow( $wgOut, 'author3', 'surname3', $author3, $surname3, |
134 | | - wfMsg(self::MSG.'label_authorforename','3'),wfMsg(self::MSG.'label_authorsurname','3')); |
135 | | - self::add2ColTableRow( $wgOut, 'author4', 'surname4', $author4, $surname4, |
136 | | - wfMsg(self::MSG.'label_authorforename','4'),wfMsg(self::MSG.'label_authorsurname','4')); |
137 | | - self::add2ColTableRow( $wgOut, 'author5', 'surname5', $author5, $surname5, |
138 | | - wfMsg(self::MSG.'label_authorforename','5'),wfMsg(self::MSG.'label_authorsurname','5')); |
139 | | - |
140 | | - self::addTableRow( $wgOut, "articletitle", $articletitle, wfMsg(self::MSG.'title') ); |
141 | | - self::addTableRow( $wgOut, "journal", $journal, wfMsg(self::MSG.'journal') ); |
142 | | - self::addTableRow( $wgOut, "pages", $pages, wfMsg(self::MSG.'pages') ); |
143 | | - self::addTableRow( $wgOut, "year", $year, wfMsg(self::MSG.'year') ); |
144 | | - self::addTableRow( $wgOut, "refname", $refname, wfMsg(self::MSG.'refname') ); |
145 | | - self::addTableRow( $wgOut, "cat1", $cat1, wfMsg(self::MSG.'category','1') ); |
146 | | - self::addTableRow( $wgOut, "cat2", $cat2, wfMsg(self::MSG.'category','2') ); |
147 | | - self::addTableRow( $wgOut, "cat3", $cat3, wfMsg(self::MSG.'category','3') ); |
148 | | - self::addTableRow( $wgOut, "cat4", $cat4, wfMsg(self::MSG.'category','4') ); |
149 | | - |
150 | | - $wgOut->addHTML( |
151 | | - Xml::openElement('tr') . |
152 | | - Xml::openElement('td',array('class'=>'mw-submit') ) . |
153 | | - Xml::element('input',array('value'=>wfMsg(self::MSG.'create'),'type'=>'submit') ) . |
154 | | - Xml::closeElement('td') . |
155 | | - Xml::closeElement('tr') . |
156 | | - Xml::closeElement('tbody') . |
157 | | - Xml::closeElement('table') . |
158 | | - Xml::closeElement('form') . |
159 | | - Xml::closeElement('fieldset') ); |
160 | | - } |
161 | | - else |
162 | | - { |
163 | | - global $wgRefHelperCiteTemplate, $wgRefHelperPageTemplate, $wgRefHelperCiteNS; |
164 | | - $db = wfGetDB(DB_MASTER); |
165 | | - |
166 | | - $citeTitle = null; |
167 | | - if( strlen($wgRefHelperCiteNS) ) $citeTitle = Title::newFromText("$wgRefHelperCiteNS:$refname"); |
168 | | - $pageTitle = Title::newFromText($refname); |
169 | | - |
170 | | - |
171 | | - $paramtext = ''; |
172 | | - $paramtext .= "| first1 = $author1\n"; |
173 | | - $paramtext .= "| last1 = $surname1\n"; |
174 | | - |
175 | | - if( strlen( $author2 ) || strlen( $surname2 )) { |
176 | | - $paramtext .= "| first2 = $author2\n"; |
177 | | - $paramtext .= "| last2 = $surname2\n"; |
178 | | - } |
179 | | - if( strlen( $author3 ) || strlen( $surname3 )) { |
180 | | - $paramtext .= "| first3 = $author3\n"; |
181 | | - $paramtext .= "| last3 = $surname3\n"; |
182 | | - } |
183 | | - if( strlen( $author4 ) || strlen( $surname4 )) { |
184 | | - $paramtext .= "| first4 = $author4\n"; |
185 | | - $paramtext .= "| last4 = $surname4\n"; |
186 | | - } |
187 | | - if( strlen( $author5 ) || strlen( $surname5 )) { |
188 | | - $paramtext .= "| first5 = $author5\n"; |
189 | | - $paramtext .= "| last5 = $surname5\n"; |
190 | | - } |
191 | | - |
192 | | - $paramtext .= "| refname = $refname\n"; |
193 | | - $paramtext .= "| articletitle = $articletitle\n"; |
194 | | - $paramtext .= "| titlelink = [[$refname|$articletitle]]\n"; |
195 | | - $paramtext .= "| journal = $journal\n"; |
196 | | - $paramtext .= "| volume = $volume\n"; |
197 | | - $paramtext .= "| pages = $pages\n"; |
198 | | - $paramtext .= "| pmid = $pmid\n"; |
199 | | - $paramtext .= "| year = $year\n"; |
200 | | - $paramtext .= "| lt = <\n"; // can be used to allow templates to create pages with onlyinclude, etc. |
201 | | - $paramtext .= "| categories = "; |
202 | | - if( strlen( $cat1 ) ) $paramtext .= "[[Category:$cat1]]\n"; |
203 | | - if( strlen( $cat2 ) ) $paramtext .= "[[Category:$cat2]]\n"; |
204 | | - if( strlen( $cat3 ) ) $paramtext .= "[[Category:$cat3]]\n"; |
205 | | - if( strlen( $cat4 ) ) $paramtext .= "[[Category:$cat4]]\n"; |
206 | | - |
207 | | - if( $citeTitle->exists()==false ) { |
208 | | - $newcontent = '{{'."$wgRefHelperCiteTemplate\n$paramtext}}\n"; |
209 | | - |
210 | | - $citePage = new Article( $citeTitle ); |
211 | | - $citePage->doEdit( $newcontent, wfMsg(self::MSG.'refcreate_autocomment') ); |
212 | | - $rev_id = $citePage->insertOn( $db ); |
213 | | - |
214 | | - $wgOut->addWikiText( wfMsg(self::MSG.'refcreate_success', array("$wgRefHelperCiteNS:$refname") ) ); |
215 | | - } |
216 | | - else { |
217 | | - $wgOut->addWikiText( wfMsg(self::MSG.'refcreate_failure', array("$wgRefHelperCiteNS:$refname") ) ); |
218 | | - } |
219 | | - if( $pageTitle->exists()==false ) { |
220 | | - $newcontent = '{{'."$wgRefHelperPageTemplate\n$paramtext}}\n"; |
221 | | - |
222 | | - $newPage = new Article( $pageTitle ); |
223 | | - $newPage->doEdit( $newcontent, wfMsg(self::MSG.'refcreate_autocomment') ); |
224 | | - $rev_id = $newPage->insertOn( $db ); |
225 | | - |
226 | | - $wgOut->addWikiText( wfMsg(self::MSG.'refcreate_success', array($refname) ) ); |
227 | | - } |
228 | | - else { |
229 | | - $wgOut->addWikiText( wfMsg(self::MSG.'refcreate_failure', array($refname) ) ); |
230 | | - } |
231 | | - |
232 | | - $wgOut->addWikiText('[[Special:RefHelper|'.wfMsg(self::MSG.'refcreate_another').']]'); |
233 | | - } |
234 | | - } |
235 | | -} |
236 | | - |
| 2 | +<?php
|
| 3 | +class RefHelper extends SpecialPage {
|
| 4 | + const MSG = 'refhelper-';
|
| 5 | + function __construct() {
|
| 6 | + parent::__construct( 'RefHelper', 'edit', true, false, 'default', false );
|
| 7 | + wfLoadExtensionMessages( 'RefHelper' );
|
| 8 | + }
|
| 9 | +
|
| 10 | + /** A simple helper function to output the html of a table row with an input box.
|
| 11 | + @param $out $wgOut should be passed
|
| 12 | + @param $varname the string of the GET variable name
|
| 13 | + @param $varval the value of the GET variable name
|
| 14 | + @param $label the text describing the variable
|
| 15 | + */
|
| 16 | + private function addTableRow( &$out, $varname, $varval, $label, $size = 50 ) {
|
| 17 | + $out->addHTML( Xml::openElement( 'tr' ) );
|
| 18 | + $out->addHTML( Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) );
|
| 19 | + $out->addHTML( Xml::element( 'label', array( 'for' => $varname ), "$label" ) );
|
| 20 | + $out->addHTML( Xml::closeElement( 'td' ) );
|
| 21 | + $out->addHTML( Xml::openElement( 'td' ) );
|
| 22 | + $out->addHTML( Xml::input( $varname, $size, $varval, array( 'id' => "inp_$varname" ) ) );
|
| 23 | + $out->addHTML( Xml::closeElement( 'td' ) );
|
| 24 | + $out->addHTML( Xml::closeElement( 'tr' ) );
|
| 25 | + }
|
| 26 | +
|
| 27 | + /**
|
| 28 | + * Another simple helper function to output the html of a table row, but with two input boxes.
|
| 29 | + * See addTableRow for parameter details
|
| 30 | + */
|
| 31 | + private function add2ColTableRow( &$out, $varname1, $varname2, $varval1, $varval2, $label1, $label2 ) {
|
| 32 | + $out->addHTML( Xml::openElement( 'tr' ) );
|
| 33 | + $out->addHTML( Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) );
|
| 34 | + $out->addHTML( Xml::element( 'label', array( 'for' => $varname1 ), "$label1" ) );
|
| 35 | + $out->addHTML( Xml::closeElement( 'td' ) );
|
| 36 | + $out->addHTML( Xml::openElement( 'td' ) );
|
| 37 | + $out->addHTML( Xml::input( $varname1, 15, $varval1, array( 'id' => "inp_$varname1", 'oninput' => 'updateFirstName(event)' ) ) );
|
| 38 | + $out->addHTML( Xml::element( 'label', array( 'for' => $varname2 ), " $label2: " ) );
|
| 39 | + $out->addHTML( Xml::input( $varname2, 20, $varval2, array( 'id' => "inp_$varname2", 'oninput' => 'updateSurname(event)' ) ) );
|
| 40 | + $out->addHTML( Xml::closeElement( 'td' ) );
|
| 41 | + $out->addHTML( Xml::closeElement( 'tr' ) );
|
| 42 | + }
|
| 43 | +
|
| 44 | + /**
|
| 45 | + * Create the html body and (depending on the GET variables) creates the page.
|
| 46 | + */
|
| 47 | + function execute( $par ) {
|
| 48 | + global $wgRequest, $wgOut, $wgScript;
|
| 49 | +
|
| 50 | + $this->setHeaders();
|
| 51 | +
|
| 52 | + # Get request data from, e.g.
|
| 53 | + $action = $wgRequest->getText( 'action' );
|
| 54 | + $refname = htmlentities( $wgRequest->getText( 'refname' ) );
|
| 55 | + $author1 = htmlentities( $wgRequest->getText( 'author1' ), ENT_COMPAT, "UTF-8" );
|
| 56 | + $author2 = htmlentities( $wgRequest->getText( 'author2' ), ENT_COMPAT, "UTF-8" );
|
| 57 | + $author3 = htmlentities( $wgRequest->getText( 'author3' ), ENT_COMPAT, "UTF-8" );
|
| 58 | + $author4 = htmlentities( $wgRequest->getText( 'author4' ), ENT_COMPAT, "UTF-8" );
|
| 59 | + $author5 = htmlentities( $wgRequest->getText( 'author5' ), ENT_COMPAT, "UTF-8" );
|
| 60 | +
|
| 61 | + $surname1 = htmlentities( $wgRequest->getText( 'surname1' ), ENT_COMPAT, "UTF-8" );
|
| 62 | + $surname2 = htmlentities( $wgRequest->getText( 'surname2' ), ENT_COMPAT, "UTF-8" );
|
| 63 | + $surname3 = htmlentities( $wgRequest->getText( 'surname3' ), ENT_COMPAT, "UTF-8" );
|
| 64 | + $surname4 = htmlentities( $wgRequest->getText( 'surname4' ), ENT_COMPAT, "UTF-8" );
|
| 65 | + $surname5 = htmlentities( $wgRequest->getText( 'surname5' ), ENT_COMPAT, "UTF-8" );
|
| 66 | +
|
| 67 | + $pmid = htmlentities( $wgRequest->getText( 'pmid' ), ENT_COMPAT, "UTF-8" );
|
| 68 | +
|
| 69 | + $articletitle = htmlentities( $wgRequest->getText( 'articletitle' ) );
|
| 70 | + $journal = htmlentities( $wgRequest->getText( 'journal' ) );
|
| 71 | + $volume = htmlentities( $wgRequest->getText( 'volume' ) );
|
| 72 | + $pages = htmlentities( $wgRequest->getText( 'pages' ) );
|
| 73 | + $year = htmlentities( $wgRequest->getText( 'year' ) );
|
| 74 | +
|
| 75 | + $cat1 = htmlentities( $wgRequest->getText( 'cat1' ) );
|
| 76 | + $cat2 = htmlentities( $wgRequest->getText( 'cat2' ) );
|
| 77 | + $cat3 = htmlentities( $wgRequest->getText( 'cat3' ) );
|
| 78 | + $cat4 = htmlentities( $wgRequest->getText( 'cat4' ) );
|
| 79 | +
|
| 80 | + $reqfilled = strlen( $author1 ) && strlen( $articletitle ) && strlen( $journal ) && strlen( $year ) && strlen( $refname );
|
| 81 | + if ( $action != "submit" || !$reqfilled ) {
|
| 82 | + if ( strlen( $pmid ) ) {
|
| 83 | + $result = RefSearch::query_pmid( $pmid );
|
| 84 | + $articletitle = $result["title"];
|
| 85 | + $journal = $result["journal"];
|
| 86 | + $volume = $result["volume"];
|
| 87 | + $pages = $result["pages"];
|
| 88 | + $year = $result["year"];
|
| 89 | + $auths = $result["authors"];
|
| 90 | + if ( isset( $auths[0] ) ) {
|
| 91 | + $author1 = $auths[0][0];
|
| 92 | + $surname1 = $auths[0][1];
|
| 93 | + }
|
| 94 | + if ( isset( $auths[1] ) ) {
|
| 95 | + $author2 = $auths[1][0];
|
| 96 | + $surname2 = $auths[1][1];
|
| 97 | + }
|
| 98 | + if ( isset( $auths[2] ) ) {
|
| 99 | + $author3 = $auths[2][0];
|
| 100 | + $surname3 = $auths[2][1];
|
| 101 | + }
|
| 102 | + if ( isset( $auths[3] ) ) {
|
| 103 | + $author4 = $auths[3][0];
|
| 104 | + $surname4 = $auths[3][1];
|
| 105 | + }
|
| 106 | + if ( isset( $auths[4] ) ) {
|
| 107 | + $author5 = $auths[4][0];
|
| 108 | + $surname5 = $auths[4][1];
|
| 109 | + }
|
| 110 | + }
|
| 111 | +
|
| 112 | + # Output
|
| 113 | + $wgOut->addHTML(
|
| 114 | + Xml::fieldset( wfMsg( self::MSG . 'refcreate_legend' ) ) .
|
| 115 | + Xml::openElement( 'form', array( 'action' => $wgScript, 'id' => 'mw_create-ref-form' ) ) .
|
| 116 | + Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
|
| 117 | + Xml::hidden( 'action', 'submit' ) .
|
| 118 | + Xml::openElement( 'table', array( 'id' => 'mw_create-ref-table' ) ) .
|
| 119 | + Xml::openElement( 'tbody' ) );
|
| 120 | +
|
| 121 | + $wgOut->addHTML(
|
| 122 | + Xml::openElement( 'tr' ) .
|
| 123 | + Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) .
|
| 124 | + Xml::element( 'label', array( 'for' => 'inp_pastearea' ), wfMsg( self::MSG . 'label_workspace' ) . ":" ) .
|
| 125 | + Xml::closeElement( 'td' ) .
|
| 126 | + Xml::openElement( 'td' ) .
|
| 127 | + Xml::textarea( 'inp_pastearea', '', 20, 5, array( 'oninput' => 'autoPopulateRefFields()' ) ) .
|
| 128 | + Xml::closeElement( 'td' ) .
|
| 129 | + Xml::closeElement( 'tr' ) );
|
| 130 | +
|
| 131 | + self::addTableRow( $wgOut, "pmid", $pmid, 'PMID', 15 );
|
| 132 | +
|
| 133 | + self::add2ColTableRow( $wgOut, 'author1', 'surname1', $author1, $surname1,
|
| 134 | + wfMsg( self::MSG . 'label_authorforename', '1' ), wfMsg( self::MSG . 'label_authorsurname', '1' ) );
|
| 135 | + self::add2ColTableRow( $wgOut, 'author2', 'surname2', $author2, $surname2,
|
| 136 | + wfMsg( self::MSG . 'label_authorforename', '2' ), wfMsg( self::MSG . 'label_authorsurname', '2' ) );
|
| 137 | + self::add2ColTableRow( $wgOut, 'author3', 'surname3', $author3, $surname3,
|
| 138 | + wfMsg( self::MSG . 'label_authorforename', '3' ), wfMsg( self::MSG . 'label_authorsurname', '3' ) );
|
| 139 | + self::add2ColTableRow( $wgOut, 'author4', 'surname4', $author4, $surname4,
|
| 140 | + wfMsg( self::MSG . 'label_authorforename', '4' ), wfMsg( self::MSG . 'label_authorsurname', '4' ) );
|
| 141 | + self::add2ColTableRow( $wgOut, 'author5', 'surname5', $author5, $surname5,
|
| 142 | + wfMsg( self::MSG . 'label_authorforename', '5' ), wfMsg( self::MSG . 'label_authorsurname', '5' ) );
|
| 143 | +
|
| 144 | + self::addTableRow( $wgOut, "articletitle", $articletitle, wfMsg( self::MSG . 'title' ) );
|
| 145 | + self::addTableRow( $wgOut, "journal", $journal, wfMsg( self::MSG . 'journal' ) );
|
| 146 | + self::addTableRow( $wgOut, "pages", $pages, wfMsg( self::MSG . 'pages' ) );
|
| 147 | + self::addTableRow( $wgOut, "year", $year, wfMsg( self::MSG . 'year' ) );
|
| 148 | + self::addTableRow( $wgOut, "refname", $refname, wfMsg( self::MSG . 'refname' ) );
|
| 149 | + self::addTableRow( $wgOut, "cat1", $cat1, wfMsg( self::MSG . 'category', '1' ) );
|
| 150 | + self::addTableRow( $wgOut, "cat2", $cat2, wfMsg( self::MSG . 'category', '2' ) );
|
| 151 | + self::addTableRow( $wgOut, "cat3", $cat3, wfMsg( self::MSG . 'category', '3' ) );
|
| 152 | + self::addTableRow( $wgOut, "cat4", $cat4, wfMsg( self::MSG . 'category', '4' ) );
|
| 153 | +
|
| 154 | + $wgOut->addHTML(
|
| 155 | + Xml::openElement( 'tr' ) .
|
| 156 | + Xml::openElement( 'td', array( 'class' => 'mw-submit' ) ) .
|
| 157 | + Xml::element( 'input', array( 'value' => wfMsg( self::MSG . 'create' ), 'type' => 'submit' ) ) .
|
| 158 | + Xml::closeElement( 'td' ) .
|
| 159 | + Xml::closeElement( 'tr' ) .
|
| 160 | + Xml::closeElement( 'tbody' ) .
|
| 161 | + Xml::closeElement( 'table' ) .
|
| 162 | + Xml::closeElement( 'form' ) .
|
| 163 | + Xml::closeElement( 'fieldset' ) );
|
| 164 | + }
|
| 165 | + else
|
| 166 | + {
|
| 167 | + global $wgRefHelperCiteTemplate, $wgRefHelperPageTemplate, $wgRefHelperCiteNS;
|
| 168 | + $db = wfGetDB( DB_MASTER );
|
| 169 | +
|
| 170 | + $citeTitle = null;
|
| 171 | + if ( strlen( $wgRefHelperCiteNS ) ) $citeTitle = Title::newFromText( "$wgRefHelperCiteNS:$refname" );
|
| 172 | + $pageTitle = Title::newFromText( $refname );
|
| 173 | +
|
| 174 | +
|
| 175 | + $paramtext = '';
|
| 176 | + $paramtext .= "| first1 = $author1\n";
|
| 177 | + $paramtext .= "| last1 = $surname1\n";
|
| 178 | +
|
| 179 | + if ( strlen( $author2 ) || strlen( $surname2 ) ) {
|
| 180 | + $paramtext .= "| first2 = $author2\n";
|
| 181 | + $paramtext .= "| last2 = $surname2\n";
|
| 182 | + }
|
| 183 | + if ( strlen( $author3 ) || strlen( $surname3 ) ) {
|
| 184 | + $paramtext .= "| first3 = $author3\n";
|
| 185 | + $paramtext .= "| last3 = $surname3\n";
|
| 186 | + }
|
| 187 | + if ( strlen( $author4 ) || strlen( $surname4 ) ) {
|
| 188 | + $paramtext .= "| first4 = $author4\n";
|
| 189 | + $paramtext .= "| last4 = $surname4\n";
|
| 190 | + }
|
| 191 | + if ( strlen( $author5 ) || strlen( $surname5 ) ) {
|
| 192 | + $paramtext .= "| first5 = $author5\n";
|
| 193 | + $paramtext .= "| last5 = $surname5\n";
|
| 194 | + }
|
| 195 | +
|
| 196 | + $paramtext .= "| refname = $refname\n";
|
| 197 | + $paramtext .= "| articletitle = $articletitle\n";
|
| 198 | + $paramtext .= "| titlelink = [[$refname|$articletitle]]\n";
|
| 199 | + $paramtext .= "| journal = $journal\n";
|
| 200 | + $paramtext .= "| volume = $volume\n";
|
| 201 | + $paramtext .= "| pages = $pages\n";
|
| 202 | + $paramtext .= "| pmid = $pmid\n";
|
| 203 | + $paramtext .= "| year = $year\n";
|
| 204 | + $paramtext .= "| lt = <\n"; // can be used to allow templates to create pages with onlyinclude, etc.
|
| 205 | + $paramtext .= "| categories = ";
|
| 206 | + if ( strlen( $cat1 ) ) $paramtext .= "[[Category:$cat1]]\n";
|
| 207 | + if ( strlen( $cat2 ) ) $paramtext .= "[[Category:$cat2]]\n";
|
| 208 | + if ( strlen( $cat3 ) ) $paramtext .= "[[Category:$cat3]]\n";
|
| 209 | + if ( strlen( $cat4 ) ) $paramtext .= "[[Category:$cat4]]\n";
|
| 210 | +
|
| 211 | + if ( $citeTitle->exists() == false ) {
|
| 212 | + $newcontent = '{{' . "$wgRefHelperCiteTemplate\n$paramtext}}\n";
|
| 213 | +
|
| 214 | + $citePage = new Article( $citeTitle );
|
| 215 | + $citePage->doEdit( $newcontent, wfMsg( self::MSG . 'refcreate_autocomment' ) );
|
| 216 | + $rev_id = $citePage->insertOn( $db );
|
| 217 | +
|
| 218 | + $wgOut->addWikiText( wfMsg( self::MSG . 'refcreate_success', array( "$wgRefHelperCiteNS:$refname" ) ) );
|
| 219 | + }
|
| 220 | + else {
|
| 221 | + $wgOut->addWikiText( wfMsg( self::MSG . 'refcreate_failure', array( "$wgRefHelperCiteNS:$refname" ) ) );
|
| 222 | + }
|
| 223 | + if ( $pageTitle->exists() == false ) {
|
| 224 | + $newcontent = '{{' . "$wgRefHelperPageTemplate\n$paramtext}}\n";
|
| 225 | +
|
| 226 | + $newPage = new Article( $pageTitle );
|
| 227 | + $newPage->doEdit( $newcontent, wfMsg( self::MSG . 'refcreate_autocomment' ) );
|
| 228 | + $rev_id = $newPage->insertOn( $db );
|
| 229 | +
|
| 230 | + $wgOut->addWikiText( wfMsg( self::MSG . 'refcreate_success', array( $refname ) ) );
|
| 231 | + }
|
| 232 | + else {
|
| 233 | + $wgOut->addWikiText( wfMsg( self::MSG . 'refcreate_failure', array( $refname ) ) );
|
| 234 | + }
|
| 235 | +
|
| 236 | + $wgOut->addWikiText( '[[Special:RefHelper|' . wfMsg( self::MSG . 'refcreate_another' ) . ']]' );
|
| 237 | + }
|
| 238 | + }
|
| 239 | +}
|
Index: trunk/extensions/RefHelper/RefHelper.hooks.php |
— | — | @@ -1,27 +1,26 @@ |
2 | | -<?php |
3 | | - |
4 | | -if (!defined('MEDIAWIKI')) { |
5 | | - exit( 1 ); |
6 | | -} |
7 | | - |
8 | | -class RefHelperHooks { |
9 | | - static function addRefHelperJavascript( $pageObj ) { |
10 | | - wfLoadExtensionMessages('RefHelper'); |
11 | | - global $wgRefHelperExtensionPath; |
12 | | - $pageObj->addScript( |
13 | | - Xml::element('script',array('src'=>"$wgRefHelperExtensionPath/refhelper.js", 'type'=>'text/javascript') ) ); |
14 | | - return true; |
15 | | - } |
16 | | - |
17 | | - static function addRefHelperLink( $tpl ) { |
18 | | - wfLoadExtensionMessages('RefHelper'); |
19 | | - global $wgScript; |
20 | | - echo Xml::openElement('li',array('class'=>'t-reflink')) . |
21 | | - Xml::element('a',array('href'=>"$wgScript?title=Special:RefHelper"), wfMsg( RefHelper::MSG . 'toolbox_link_create' ) ) . |
22 | | - Xml::closeElement('li'); |
23 | | - echo Xml::openElement('li',array('class'=>'t-reflink')) . |
24 | | - Xml::element('a',array('href'=>"$wgScript?title=Special:RefSearch"), wfMsg( RefHelper::MSG . 'toolbox_link_search' ) ) . |
25 | | - Xml::closeElement('li'); |
26 | | - return true; |
27 | | - } |
28 | | -} |
| 2 | +<?php
|
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) {
|
| 4 | + exit( 1 );
|
| 5 | +}
|
| 6 | +
|
| 7 | +class RefHelperHooks {
|
| 8 | + static function addRefHelperJavascript( $pageObj ) {
|
| 9 | + wfLoadExtensionMessages( 'RefHelper' );
|
| 10 | + global $wgRefHelperExtensionPath;
|
| 11 | + $pageObj->addScript(
|
| 12 | + Xml::element( 'script', array( 'src' => "$wgRefHelperExtensionPath/refhelper.js", 'type' => 'text/javascript' ) ) );
|
| 13 | + return true;
|
| 14 | + }
|
| 15 | +
|
| 16 | + static function addRefHelperLink( $tpl ) {
|
| 17 | + wfLoadExtensionMessages( 'RefHelper' );
|
| 18 | + global $wgScript;
|
| 19 | + echo Xml::openElement( 'li', array( 'class' => 't-reflink' ) ) .
|
| 20 | + Xml::element( 'a', array( 'href' => "$wgScript?title=Special:RefHelper" ), wfMsg( RefHelper::MSG . 'toolbox_link_create' ) ) .
|
| 21 | + Xml::closeElement( 'li' );
|
| 22 | + echo Xml::openElement( 'li', array( 'class' => 't-reflink' ) ) .
|
| 23 | + Xml::element( 'a', array( 'href' => "$wgScript?title=Special:RefSearch" ), wfMsg( RefHelper::MSG . 'toolbox_link_search' ) ) .
|
| 24 | + Xml::closeElement( 'li' );
|
| 25 | + return true;
|
| 26 | + }
|
| 27 | +}
|
Index: trunk/extensions/RefHelper/RefHelper.search.php |
— | — | @@ -1,186 +1,188 @@ |
2 | | -<?php |
3 | | -class RefSearch extends SpecialPage { |
4 | | - |
5 | | - function __construct() { |
6 | | - parent::__construct( 'RefSearch','edit',true,false,'default',false ); |
7 | | - wfLoadExtensionMessages('RefHelper'); |
8 | | - } |
9 | | - |
10 | | - function execute( $par ) { |
11 | | - global $wgRequest, $wgOut, $wgScript; |
12 | | - |
13 | | - $this->setHeaders(); |
14 | | - |
15 | | - # Get request data from, e.g. |
16 | | - $action = $wgRequest->getText('action'); |
17 | | - |
18 | | - $query = htmlentities($wgRequest->getText('query')); |
19 | | - |
20 | | - # Output |
21 | | - $wgOut->addHTML( |
22 | | - Xml::fieldset( wfMsg(RefHelper::MSG.'refsearch_legend') ) . |
23 | | - Xml::openElement( 'form', array('action'=>$wgScript,'id'=>'mw_search-ref-form') ) . |
24 | | - Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) . |
25 | | - Xml::hidden( 'action', 'submit' ) . |
26 | | - Xml::openElement('table',array('id'=>'mw_search-ref-table')) . |
27 | | - Xml::openElement('tbody') ); |
28 | | - |
29 | | - $wgOut->addHTML( |
30 | | - Xml::openElement('tr') . |
31 | | - Xml::openElement('td', array('class'=>'mw-input')) . |
32 | | - Xml::input('query', 50, $query ) . |
33 | | - Xml::closeElement('td') . |
34 | | - Xml::openElement('td', array('class'=>'mw-submit')) . |
35 | | - Xml::element('input',array('value'=>wfMsg(RefHelper::MSG.'search'), 'type'=>'submit') ) . |
36 | | - Xml::closeElement('td') . |
37 | | - Xml::closeElement('tr') ); |
38 | | - |
39 | | - $wgOut->addHTML( |
40 | | - Xml::closeElement('tbody') . |
41 | | - Xml::closeElement('table') . |
42 | | - Xml::closeElement('form') ); |
43 | | - |
44 | | - $reqfilled = strlen($query); |
45 | | - if( $action=="submit" || $reqfilled ) { |
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; |
53 | | - |
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 | | - |
59 | | - $editpage->setHeaders(); |
60 | | - |
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 ); |
72 | | - } |
73 | | - else { |
74 | | - $wgOut->addWikiMsg( RefHelper::MSG . 'newarticle_nosuggestions'); |
75 | | - } |
76 | | - return false; |
77 | | - } |
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 ) { |
118 | | - $field = strtoupper($field); |
119 | | - $num = preg_match_all("|\n$field\s*- (.*)(?>\n (.*))*|", $text, $matches, PREG_SET_ORDER ); |
120 | | - $ret = array(); |
121 | | - for( $i = 0; $i < $num; $i++ ) |
122 | | - { |
123 | | - array_shift($matches[$i]); |
124 | | - $ret[] = implode( " ", $matches[$i] ); |
125 | | - } |
126 | | - return $ret; |
127 | | - } |
128 | | - static function query_pmid( $pmid ) { |
129 | | - $ret = array(); |
130 | | - $ret["query_url"] = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&report=medline&mode=text&id=$pmid&email=jonwilliford@gmail.com&tool=mediawiki_refhelper"; |
131 | | - $ch = curl_init( $ret["query_url"] ); |
132 | | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
133 | | - $result = curl_exec($ch); |
134 | | - curl_close($ch); |
135 | | - |
136 | | - $ret["title"] = array_shift( self::parse_medline( $result, "TI" )); |
137 | | - $ret["journal"] = array_shift( self::parse_medline( $result, "TA" )); |
138 | | - $ret["year"] = substr( array_shift( self::parse_medline( $result, "DP" )), 0, 4 ); |
139 | | - $ret["volume"] = array_shift( self::parse_medline( $result, "VI" )); |
140 | | - $ret["issue"] = array_shift( self::parse_medline( $result, "IP" )); |
141 | | - $ret["pages"] = array_shift( self::parse_medline( $result, "PG" )); |
142 | | - |
143 | | - $ret["firstlasts"] = self::parse_medline( $result, "FAU" ); |
144 | | - $ret["AU"] = self::parse_medline( $result, "AU" ); |
145 | | - |
146 | | - $ret["authors"] = array(); |
147 | | - |
148 | | - /* This wasn't working as I was wanting previously. I want to test more before uncommenting. |
149 | | - if( isset( $ret["firstlasts"] ) ) |
150 | | - { |
151 | | - for( $i = 0; $i < count( $ret["firstlasts"] ); $i++ ) { |
152 | | - |
153 | | - $auth = $ret["firstlasts"][$i]; |
154 | | - |
155 | | - if( preg_match("|(.+), (.+)|", $auth, $matches ) ) { |
156 | | - |
157 | | - // index 0 for first name, index 1 for surname |
158 | | - $ret["authors"][$i][1] = $matches[1]; |
159 | | - $ret["authors"][$i][0] = $matches[2]; |
160 | | - } |
161 | | - else { |
162 | | - $ret["authors"][$i] = array(0=>"",1=>$auth); |
163 | | - } |
164 | | - } |
165 | | - } |
166 | | - else*/ |
167 | | - { |
168 | | - for( $i = 0; $i < count( $ret["AU"] ); $i++ ) { |
169 | | - |
170 | | - $auth = $ret["AU"][$i]; |
171 | | - |
172 | | - if( preg_match("|^(.+) (.+)$|", $auth, $matches ) ) { |
173 | | - |
174 | | - // index 0 for first name, index 1 for surname |
175 | | - $ret["authors"][$i][1] = $matches[1]; |
176 | | - $ret["authors"][$i][0] = $matches[2]; |
177 | | - } |
178 | | - else { |
179 | | - $ret["authors"][$i] = array(0=>"",1=>$auth); |
180 | | - } |
181 | | - } |
182 | | - } |
183 | | - |
184 | | - return $ret; |
185 | | - } |
186 | | -} |
187 | | - |
| 2 | +<?php
|
| 3 | +class RefSearch extends SpecialPage {
|
| 4 | + function __construct() {
|
| 5 | + parent::__construct( 'RefSearch', 'edit', true, false, 'default', false );
|
| 6 | + wfLoadExtensionMessages( 'RefHelper' );
|
| 7 | + }
|
| 8 | +
|
| 9 | + function execute( $par ) {
|
| 10 | + global $wgRequest, $wgOut, $wgScript;
|
| 11 | +
|
| 12 | + $this->setHeaders();
|
| 13 | +
|
| 14 | + # Get request data from, e.g.
|
| 15 | + $action = $wgRequest->getText( 'action' );
|
| 16 | +
|
| 17 | + $query = htmlentities( $wgRequest->getText( 'query' ) );
|
| 18 | +
|
| 19 | + # Output
|
| 20 | + $wgOut->addHTML(
|
| 21 | + Xml::fieldset( wfMsg( RefHelper::MSG . 'refsearch_legend' ) ) .
|
| 22 | + Xml::openElement( 'form', array( 'action' => $wgScript, 'id' => 'mw_search-ref-form' ) ) .
|
| 23 | + Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
|
| 24 | + Xml::hidden( 'action', 'submit' ) .
|
| 25 | + Xml::openElement( 'table', array( 'id' => 'mw_search-ref-table' ) ) .
|
| 26 | + Xml::openElement( 'tbody' ) );
|
| 27 | +
|
| 28 | + $wgOut->addHTML(
|
| 29 | + Xml::openElement( 'tr' ) .
|
| 30 | + Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) .
|
| 31 | + Xml::input( 'query', 50, $query ) .
|
| 32 | + Xml::closeElement( 'td' ) .
|
| 33 | + Xml::openElement( 'td', array( 'class' => 'mw-submit' ) ) .
|
| 34 | + Xml::element( 'input', array( 'value' => wfMsg( RefHelper::MSG . 'search' ), 'type' => 'submit' ) ) .
|
| 35 | + Xml::closeElement( 'td' ) .
|
| 36 | + Xml::closeElement( 'tr' ) );
|
| 37 | +
|
| 38 | + $wgOut->addHTML(
|
| 39 | + Xml::closeElement( 'tbody' ) .
|
| 40 | + Xml::closeElement( 'table' ) .
|
| 41 | + Xml::closeElement( 'form' ) );
|
| 42 | +
|
| 43 | + $reqfilled = strlen( $query );
|
| 44 | + if ( $action == "submit" || $reqfilled ) {
|
| 45 | + $wgOut->addHTML( self::perform_search( $query ) );
|
| 46 | + }
|
| 47 | + $wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
|
| 48 | + }
|
| 49 | +
|
| 50 | + static function newArticleHook( &$editpage ) {
|
| 51 | + wfLoadExtensionMessages( 'RefHelper' );
|
| 52 | + global $wgOut, $wgRefHelperCiteNS;
|
| 53 | +
|
| 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 | +
|
| 59 | + $editpage->setHeaders();
|
| 60 | +
|
| 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 );
|
| 72 | + }
|
| 73 | + else {
|
| 74 | + $wgOut->addWikiMsg( RefHelper::MSG . 'newarticle_nosuggestions' );
|
| 75 | + }
|
| 76 | + return false;
|
| 77 | + }
|
| 78 | +
|
| 79 | + static function perform_search( $query ) {
|
| 80 | + global $wgScript;
|
| 81 | + $query = str_replace( " ", "+", $query );
|
| 82 | + $ch = curl_init( "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?term=$query&tool=mediawiki_refhelper" );
|
| 83 | + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
| 84 | + $result = curl_exec( $ch );
|
| 85 | + curl_close( $ch );
|
| 86 | +
|
| 87 | + $num = preg_match_all( "|<Id>(\d+)</Id>|", $result, $matches );
|
| 88 | + if ( $num === 0 || $num === false ) return false;
|
| 89 | +
|
| 90 | + $ret = Xml::openElement( 'table' );
|
| 91 | + for ( $i = 0; $i < $num; $i++ ) {
|
| 92 | + $pmid = $matches[1][$i];
|
| 93 | + $result = self::query_pmid( $pmid );
|
| 94 | +
|
| 95 | + $author = array_shift( $result["authors"] );
|
| 96 | + if ( isset( $author ) ) $author = $author[1];
|
| 97 | + $title = $result["title"];
|
| 98 | + $query = $result["query_url"];
|
| 99 | + $year = $result["year"];
|
| 100 | + if ( count( $result["AU"] ) > 1 ) $etal = " et al.";
|
| 101 | + else $etal = "";
|
| 102 | +
|
| 103 | + $ret .=
|
| 104 | + Xml::openElement( 'tr' ) .
|
| 105 | + Xml::element( 'td', null, "$author $etal ($year) \"$title\"" ) .
|
| 106 | + Xml::openElement( 'td' ) .
|
| 107 | + Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => "mw-create-ref-form$i" ) ) .
|
| 108 | + Xml::hidden( 'title', 'Special:RefHelper' ) .
|
| 109 | + Xml::hidden( 'pmid', $pmid ) .
|
| 110 | + Xml::element( 'input', array( 'value' => wfMsg( RefHelper::MSG . 'create' ), 'type' => 'submit' ) ) .
|
| 111 | + Xml::closeElement( 'form' ) .
|
| 112 | + Xml::closeElement( 'td' ) .
|
| 113 | + Xml::closeElement( 'tr' );
|
| 114 | + }
|
| 115 | + $ret .= Xml::closeElement( 'table' );
|
| 116 | + return $ret;
|
| 117 | + }
|
| 118 | +
|
| 119 | + private static function parse_medline( $text, $field ) {
|
| 120 | + $field = strtoupper( $field );
|
| 121 | + $num = preg_match_all( "|\n$field\s*- (.*)(?>\n (.*))*|", $text, $matches, PREG_SET_ORDER );
|
| 122 | + $ret = array();
|
| 123 | + for ( $i = 0; $i < $num; $i++ )
|
| 124 | + {
|
| 125 | + array_shift( $matches[$i] );
|
| 126 | + $ret[] = implode( " ", $matches[$i] );
|
| 127 | + }
|
| 128 | + return $ret;
|
| 129 | + }
|
| 130 | +
|
| 131 | + static function query_pmid( $pmid ) {
|
| 132 | + $ret = array();
|
| 133 | + $ret["query_url"] = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&report=medline&mode=text&id=$pmid&email=jonwilliford@gmail.com&tool=mediawiki_refhelper";
|
| 134 | + $ch = curl_init( $ret["query_url"] );
|
| 135 | + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
| 136 | + $result = curl_exec( $ch );
|
| 137 | + curl_close( $ch );
|
| 138 | +
|
| 139 | + $ret["title"] = array_shift( self::parse_medline( $result, "TI" ) );
|
| 140 | + $ret["journal"] = array_shift( self::parse_medline( $result, "TA" ) );
|
| 141 | + $ret["year"] = substr( array_shift( self::parse_medline( $result, "DP" ) ), 0, 4 );
|
| 142 | + $ret["volume"] = array_shift( self::parse_medline( $result, "VI" ) );
|
| 143 | + $ret["issue"] = array_shift( self::parse_medline( $result, "IP" ) );
|
| 144 | + $ret["pages"] = array_shift( self::parse_medline( $result, "PG" ) );
|
| 145 | +
|
| 146 | + $ret["firstlasts"] = self::parse_medline( $result, "FAU" );
|
| 147 | + $ret["AU"] = self::parse_medline( $result, "AU" );
|
| 148 | +
|
| 149 | + $ret["authors"] = array();
|
| 150 | +
|
| 151 | + /* This wasn't working as I was wanting previously. I want to test more before uncommenting.
|
| 152 | + if( isset( $ret["firstlasts"] ) )
|
| 153 | + {
|
| 154 | + for( $i = 0; $i < count( $ret["firstlasts"] ); $i++ ) {
|
| 155 | +
|
| 156 | + $auth = $ret["firstlasts"][$i];
|
| 157 | +
|
| 158 | + if( preg_match("|(.+), (.+)|", $auth, $matches ) ) {
|
| 159 | +
|
| 160 | + // index 0 for first name, index 1 for surname
|
| 161 | + $ret["authors"][$i][1] = $matches[1];
|
| 162 | + $ret["authors"][$i][0] = $matches[2];
|
| 163 | + }
|
| 164 | + else {
|
| 165 | + $ret["authors"][$i] = array(0=>"",1=>$auth);
|
| 166 | + }
|
| 167 | + }
|
| 168 | + }
|
| 169 | + else*/
|
| 170 | + {
|
| 171 | + for ( $i = 0; $i < count( $ret["AU"] ); $i++ ) {
|
| 172 | +
|
| 173 | + $auth = $ret["AU"][$i];
|
| 174 | +
|
| 175 | + if ( preg_match( "|^(.+) (.+)$|", $auth, $matches ) ) {
|
| 176 | +
|
| 177 | + // index 0 for first name, index 1 for surname
|
| 178 | + $ret["authors"][$i][1] = $matches[1];
|
| 179 | + $ret["authors"][$i][0] = $matches[2];
|
| 180 | + }
|
| 181 | + else {
|
| 182 | + $ret["authors"][$i] = array( 0 => "", 1 => $auth );
|
| 183 | + }
|
| 184 | + }
|
| 185 | + }
|
| 186 | +
|
| 187 | + return $ret;
|
| 188 | + }
|
| 189 | +}
|
Index: trunk/extensions/RefHelper/RefHelper.alias.php |
— | — | @@ -1,8 +1,7 @@ |
2 | | -<?php |
3 | | -$aliases = array(); |
4 | | - |
5 | | -/** English */ |
6 | | -$aliases['en'] = array( |
7 | | - 'RefHelper' => array( 'RefHelper' ), |
8 | | -); |
9 | | - |
| 2 | +<?php
|
| 3 | +$aliases = array();
|
| 4 | +
|
| 5 | +/** English */
|
| 6 | +$aliases['en'] = array(
|
| 7 | + 'RefHelper' => array( 'RefHelper' ),
|
| 8 | +);
|