Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.magic.php |
— | — | @@ -4,14 +4,21 @@ |
5 | 5 | |
6 | 6 | $magicWords['en'] = array( |
7 | 7 | # citation magic words |
8 | | - 'citation' => array( 1, 'citation' ), |
9 | | - 'ta_cc_author' => array( 0, 'author' ), |
10 | | - 'ta_cc_authorsurname' => array( 0, 'surname' ), |
11 | | - 'ta_cc_authorgiven' => array( 0, 'given' ), |
12 | | - 'ta_cc_authorlink' => array( 0, 'authorlink' ), |
13 | | - 'ta_cc_coauthors' => array( 0, 'coauthors' ), |
14 | | - 'ta_cc_editor' => array( 0, 'editor' ), |
15 | | - 'ta_cc_editorsurname' => array( 0, 'editorsurname' ), |
16 | | - 'ta_cc_editorgiven' => array( 0, 'editorgiven' ), |
17 | | - 'ta_cc_editorlink' => array( 0, 'editorlink' ), |
| 8 | + 'citation' => array( 1, 'citation' ), |
| 9 | + 'ta_cc_author' => array( 0, 'author' ), |
| 10 | + 'ta_cc_authorsurname' => array( 0, 'surname' ), |
| 11 | + 'ta_cc_authorgiven' => array( 0, 'given' ), |
| 12 | + 'ta_cc_authorlink' => array( 0, 'authorlink' ), |
| 13 | + 'ta_cc_coauthors' => array( 0, 'coauthors' ), |
| 14 | + 'ta_cc_editor' => array( 0, 'editor' ), |
| 15 | + 'ta_cc_editorsurname' => array( 0, 'editorsurname' ), |
| 16 | + 'ta_cc_editorgiven' => array( 0, 'editorgiven' ), |
| 17 | + 'ta_cc_editorlink' => array( 0, 'editorlink' ), |
| 18 | + 'ta_cc_url' => array( 0, 'url', 'URL' ), |
| 19 | + 'ta_cc_title' => array( 0, 'title', 'Title' ), |
| 20 | + 'ta_cc_pmc' => array( 0, 'pmc', 'PMC' ), |
| 21 | + 'ta_cc_includedworktitle' => array( 0, 'includedworktitle' ), |
| 22 | + 'ta_cc_periodical' => array( 0, 'periodical' ), |
| 23 | + 'ta_cc_transitalic' => array( 0, 'transitalic' ), |
| 24 | + 'ta_cc_transtitle' => array( 0, 'transtitle' ), |
18 | 25 | ); |
Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.php |
— | — | @@ -9,5 +9,8 @@ |
10 | 10 | 'ta-citeauthoryearnote' => ' [$1]', |
11 | 11 | 'ta-editorsplural' => ', eds', |
12 | 12 | 'ta-editorssingular' => ', ed', |
| 13 | + 'ta-pubmed-url' => 'http://www.pubmedcentral.nih.gov/articlerender.fcgi?tool=pmcentrez&artid=$1', |
| 14 | + 'ta-transtitle-render' => '[$1]', |
| 15 | + 'ta-writtenat' => 'written at $1', |
13 | 16 | ); |
14 | 17 | |
Index: trunk/extensions/TemplateAdventures/Templates/Citation.php |
— | — | @@ -92,36 +92,7 @@ |
93 | 93 | $this->mOutput = ''; |
94 | 94 | # authors |
95 | 95 | if ( count( $this->dAuthors ) > 1 ) { |
96 | | - $authorArea = ''; |
97 | | - $n = 1; |
98 | | - foreach ( $this->dAuthors as $i => $author ) { |
99 | | - if ( $i == 0 ) |
100 | | - continue; |
101 | | - if ( $i > 1 && $this->dAuthorTruncate <= $i ) { |
102 | | - $authorArea .= wfMsg( "ta-etal" ); |
103 | | - break; |
104 | | - } |
105 | | - if ( $n == count($this->dAuthors)-1 && $i != 1 ) |
106 | | - $authorArea .= $this->getSeparator( 'ampersand' ); |
107 | | - elseif ( $n > 1 ) |
108 | | - $authorArea .= $this->getSeparator( 'author' ); |
109 | | - $tmp = ''; |
110 | | - if ( $author[0] ) { |
111 | | - if ( $author[1][1] == null ) |
112 | | - continue; |
113 | | - $tmp .= $author[1][1]; |
114 | | - if ( $author[1][0] != null ) |
115 | | - $tmp .= $this->getSeparator( 'name' ) . $author[1][0]; |
116 | | - } else { |
117 | | - # maybe we shan't support no surname/given name structure |
118 | | - # in the future, but we'll leave it like this for now. |
119 | | - $tmp .= $author[1][1]; |
120 | | - } |
121 | | - if ( isset ( $this->dAuthorLinks[$i] ) ) |
122 | | - $tmp = "[{$this->dAuthorLinks[$i]} $tmp]"; |
123 | | - $authorArea .= $tmp; |
124 | | - $n++; |
125 | | - } |
| 96 | + $authorArea = $this->createWriterSection ( $this->dAuthors, $this->dAuthorLinks, $this->dAuthorTruncate ); |
126 | 97 | if ( $this->dCoAuthors != null ) |
127 | 98 | $authorArea .= $this->getSeparator( 'author' ) . $this->dCoAuthors; |
128 | 99 | if ( $this->dDate != null ) { |
— | — | @@ -130,37 +101,9 @@ |
131 | 102 | $authorArea .= wfMsg ( 'ta-citeauthoryearnote', $this->dYearNote ); |
132 | 103 | } |
133 | 104 | $this->mOutput .= $authorArea; |
| 105 | + # editors |
134 | 106 | } elseif ( count ( $this->dEditors ) > 1 ) { |
135 | | - $editorArea = ''; |
136 | | - $n = 1; |
137 | | - foreach ( $this->dEditors as $i => $editor ) { |
138 | | - if ( $i == 0 ) |
139 | | - continue; |
140 | | - if ( $i > 1 && $this->dEditorTruncate <= $i ) { |
141 | | - $editorArea .= wfMsg( "ta-etal" ); |
142 | | - break; |
143 | | - } |
144 | | - if ( $n == count($this->dEditors)-1 && $i != 1 ) |
145 | | - $editorArea .= $this->getSeparator( 'ampersand' ); |
146 | | - elseif ( $n > 1 ) |
147 | | - $editorArea .= $this->getSeparator( 'author' ); |
148 | | - $tmp = ''; |
149 | | - if ( $editor[0] ) { |
150 | | - if ( $editor[1][1] == null ) |
151 | | - continue; |
152 | | - $tmp .= $editor[1][1]; |
153 | | - if ( $editor[1][0] != null ) |
154 | | - $tmp .= $this->getSeparator( 'name' ) . $editor[1][0]; |
155 | | - } else { |
156 | | - # maybe we shan't support no surname/given name structure |
157 | | - # in the future, but we'll leave it like this for now. |
158 | | - $tmp .= $editor[1][1]; |
159 | | - } |
160 | | - if ( isset ( $this->dEditorLinks[$i] ) ) |
161 | | - $tmp = "[{$this->dEditorLinks[$i]} $tmp]"; |
162 | | - $editorArea .= $tmp; |
163 | | - $n++; |
164 | | - } |
| 107 | + $editorArea = $this->createWriterSection ( $this->dEditors, $this->dEditorLinks, $this->dEditorTruncate ); |
165 | 108 | if ( count ( $this->dEditors ) > 2 ) |
166 | 109 | $editorArea .= wfMsg ( 'ta-editorsplural' ); |
167 | 110 | else |
— | — | @@ -173,9 +116,117 @@ |
174 | 117 | } |
175 | 118 | $this->mOutput .= $editorArea; |
176 | 119 | } |
| 120 | + # included work title |
| 121 | + if ( $this->notNull( $this->dWorkTitle['includedwork'] ) && ( $this->notNull( $this->dPeriodical ) || $this->notNull( $this->dWorkTitle['transitalic'] ) || $this->notNull( $this->dWorkTitle['transtitle'] ) ) ) { |
| 122 | + # I am no way certain this is a correct copy of the following logic: |
| 123 | + # {{#if: {{{IncludedWorkTitle|}}}{{#if:{{{Periodical|}}}||{{#if:{{{TransItalic|}}}||{{{TransTitle|}}}}}}} | ... | ... }} |
| 124 | + if ( $authorArea != '' || $editorArea != '' ) { |
| 125 | + $this->mOutput .= $this->getSeparator( 'section' ); |
| 126 | + } |
| 127 | + # let's get the url |
| 128 | + if ( $this->dWorkLink['includedwork'] != null ) { |
| 129 | + $url = $this->dWorkLink['includedwork']; |
| 130 | + } else { |
| 131 | + if ( $this->dWorkLink['url'] != null ) { |
| 132 | + $url = $this->dWorkLink['url']; |
| 133 | + } else { |
| 134 | + # some explain to me what exactly the following is supposed to mean: |
| 135 | + # <!-- Only link URL if to a free full text - as at PubMedCentral (PMC)--> |
| 136 | + # |{{#ifexpr:{{#time: U}} > {{#time: U | {{{Embargo|2001-10-10}}} }} |
| 137 | + if ( $this->dPubMed['pmc'] != null ) { |
| 138 | + $url = wfMsg ( 'ta-pubmed-url', $this->dPubMed['pmc'] ); |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + # and now the title |
| 143 | + if ( $this->dPeriodical != null ) { |
| 144 | + $tmp = str_replace( "'", ''', $this->dWorkTitle['includedwork']); |
| 145 | + $title = "''$tmp''"; |
| 146 | + } else { |
| 147 | + $tmp = ( $this->dWorkTitle['includedwork'] != null |
| 148 | + ? $this->dWorkTitle['includedwork'] |
| 149 | + : '' ); |
| 150 | + if ( $this->dWorkTitle['transtitle'] ) { |
| 151 | + if ( $tmp != '' ) |
| 152 | + $tmp .= ' '; |
| 153 | + $tmp .= wfMsg( 'ta-transtitle-render', $this->dWorkTitle['transtitle'] ); |
| 154 | + } |
| 155 | + $title = $tmp; |
| 156 | + } |
| 157 | + $this->mOutput .= $this->makeLink ( $url, $title ); |
| 158 | + } |
| 159 | + # place, but only if different from publication place. |
| 160 | + if ( $this->notNull( $this->dPlace ) |
| 161 | + && $this->dPlace != $this->dPublication['place'] |
| 162 | + && ( |
| 163 | + $this->notNull ( $authorArea ) |
| 164 | + || $this->notNull ( $editorArea ) |
| 165 | + || $this->notNull ( $this->dWorkTitle['includedwork'] ) |
| 166 | + ) |
| 167 | + ) { |
| 168 | + $this->mOutput .= $this->getSeparator ( 'section' ) . ' ' . wfMsg ( 'ta-writtenat', $this->dPlace ); |
| 169 | + } |
| 170 | + # editor of complication... eerrr... |
| 171 | + # TODO: we'll do this later... |
| 172 | + |
| 173 | + # periodicals |
| 174 | + # TODO: I'll get on it! |
177 | 175 | } |
178 | 176 | |
179 | 177 | /** |
| 178 | + * Create the section for authors, editors, etc. in a neat similar function. |
| 179 | + * |
| 180 | + * @param $writers Authors, editors, etc. array |
| 181 | + * @param $links Their links if any |
| 182 | + * @param $truncate When to truncate the amount of data. |
| 183 | + * @return The created area. |
| 184 | + */ |
| 185 | + private function createWriterSection ( $writers, $links, $truncate ) { |
| 186 | + $area = ''; |
| 187 | + foreach ( $writers as $i => $writer ) { |
| 188 | + if ( $i == 0 ) |
| 189 | + continue; |
| 190 | + if ( $i > 1 && $truncate <= $i ) { |
| 191 | + $area .= wfMsg( "ta-etal" ); |
| 192 | + break; |
| 193 | + } |
| 194 | + if ( $n == count($writers)-1 && $i != 1 ) |
| 195 | + $area .= $this->getSeparator( 'ampersand' ); |
| 196 | + elseif ( $n > 1 ) |
| 197 | + $area .= $this->getSeparator( 'author' ); |
| 198 | + $tmp = ''; |
| 199 | + if ( $writer[0] ) { |
| 200 | + if ( $writer[1][1] == null ) |
| 201 | + continue; |
| 202 | + $tmp .= $writer[1][1]; |
| 203 | + if ( $editor[1][0] != null ) |
| 204 | + $tmp .= $this->getSeparator( 'name' ) . $writer[1][0]; |
| 205 | + } else { |
| 206 | + # maybe we shan't support no surname/given name structure |
| 207 | + # in the future, but we'll leave it like this for now. |
| 208 | + $tmp .= $writer[1][1]; |
| 209 | + } |
| 210 | + if ( isset ( $links[$i] ) ) |
| 211 | + $tmp = "[{$links[$i]} $tmp]"; |
| 212 | + $area .= $tmp; |
| 213 | + $n++; |
| 214 | + } |
| 215 | + return $area; |
| 216 | + } |
| 217 | + |
| 218 | + private function makeLink ( $url, $title ) { |
| 219 | + if ( !$url ) |
| 220 | + return $title; |
| 221 | + return "[$url $title]"; |
| 222 | + } |
| 223 | + |
| 224 | + private function notNull ( $check ) { |
| 225 | + if ( $check == null && $check == '' ) |
| 226 | + return false; |
| 227 | + return true; |
| 228 | + } |
| 229 | + |
| 230 | + /** |
180 | 231 | * This function should in the future do some wfMsg() magic to check if |
181 | 232 | * they are using a set separator message or just using a default one. |
182 | 233 | * |
— | — | @@ -272,6 +323,20 @@ |
273 | 324 | } # let's not permit them to add authors/editors/etc. without a number |
274 | 325 | } |
275 | 326 | |
| 327 | + private function addOtherStringValue ( $name, $value ) { |
| 328 | + switch ( $name[0] ) { |
| 329 | + case 'url': |
| 330 | + $this->dWorkLink['url'] = $value; |
| 331 | + break; |
| 332 | + case 'title': |
| 333 | + $this->dWorkTitle['title'] = $value; |
| 334 | + break; |
| 335 | + case 'includedworktitle': |
| 336 | + $this->dWorkTitle['includedwork'] = $value; |
| 337 | + break; |
| 338 | + } |
| 339 | + } |
| 340 | + |
276 | 341 | /** |
277 | 342 | * Checks whether the data provided is a known option. |
278 | 343 | * |
— | — | @@ -309,6 +374,15 @@ |
310 | 375 | case 'editorlink': |
311 | 376 | $this->addEditorLink( $name, $value ); |
312 | 377 | break; |
| 378 | + case 'url': |
| 379 | + case 'title': |
| 380 | + case 'pmc': |
| 381 | + case 'includedworktitle': |
| 382 | + case 'periodical': |
| 383 | + case 'transitalic': |
| 384 | + case 'transtitle': |
| 385 | + $this->addOtherStringValue( $name, $value ); |
| 386 | + break; |
313 | 387 | default: |
314 | 388 | # Wasn't an option after all |
315 | 389 | return false; |
— | — | @@ -334,6 +408,9 @@ |
335 | 409 | 'ta_cc_coauthors', |
336 | 410 | 'ta_cc_editor', 'ta_cc_editorgiven', |
337 | 411 | 'ta_cc_editorsurname', 'ta_cc_editorlink', |
| 412 | + 'ta_cc_url', 'ta_cc_title', 'ta_cc_pmc', |
| 413 | + 'ta_cc_includedworktitle', 'ta_cc_periodical', |
| 414 | + 'ta_cc_transitalic', 'ta_cc_transtitle', |
338 | 415 | ) ); |
339 | 416 | } |
340 | 417 | |