r66491 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66490‎ | r66491 | r66492 >
Date:19:13, 15 May 2010
Author:svip
Status:ok
Tags:
Comment:
Following up on r66057, r66106 & r66107. I really, really need to wrap my head around this issue completely. But I think this is a better solution for now, i18n wise. Where is that damn Ashlee\!? S/he needs to write some test code for this extension\!
Modified paths:
  • /trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.php (modified) (history)
  • /trunk/extensions/TemplateAdventures/Templates/Citation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.php
@@ -5,16 +5,17 @@
66 /** English */
77 $messages['en'] = array (
88 # citation separators
9 - 'ta-citesep-section' => ',', # separator between sections
10 - 'ta-citesep-name' => ', ', # separator between surname and givenname
11 - 'ta-citesep-author' => '&#059; ', # separator between authors
12 - 'ta-citesep-authorlast' => ' & ', # last separator between authors
 9+ 'ta-citesep-section' => '.', # separator between sections
 10+ 'ta-citesep-end' => '.', # final separator (not really a separator)
 11+ 'ta-citesep-name' => ',', # separator between surname and givenname
 12+ 'ta-citesep-author' => '&#059;', # separator between authors
 13+ 'ta-citesep-authorlast' => ' &', # last separator between authors
1314 'ta-citesep-beforepublication' => ':', # separator between periodical
1415 # and publication
1516
1617 # citation messages
1718 'ta-citeetal' => "$1 ''et al''.", # $1 = list of authors
18 - 'ta-citecoauthors' => '$1$2 $3', # $1 = authors, $2 = separator
 19+ 'ta-citecoauthors' => '$1$2 $3', # $1 = authors, $2 = separator
1920 'ta-citeauthordate' => '$1 ($2)', # $1 = authors or separator
2021 'ta-citeauthoryearnote' => '$1 [$2]', # $1 = date
2122 'ta-citeeditorsplural' => '$1, eds', # $1 = editors
@@ -22,27 +23,27 @@
2324 'ta-includedworktitle' => "''$1''",
2425 'ta-citepubmed-url' => 'http://www.pubmedcentral.nih.gov/articlerender.fcgi?tool=pmcentrez&artid=$1',
2526 'ta-citetranstitle-render' => '[$1]',
26 - 'ta-citewrittenat' => '$1 written at $2', # $1 = separator
27 - 'ta-citeother' => '$1 $2', # $1 = separator
 27+ 'ta-citewrittenat' => 'written at $1',
 28+ 'ta-citeother' => '$1',
2829 'ta-citeinlanguage' => '$1 (in $2)', # $1 = title/link
2930 'ta-citeformatrender' => '$1 ($2)', # $1 = title/link
3031 'ta-citeperiodical' => "''$1''",
3132 'ta-citeperiodicaltitle' => "''$1''",
32 - 'ta-series' => '$1 $2', # $1 = separator
33 - 'ta-citepublicationplaceandpublisher' => '$1 ($2: $3)', # $1 = separator
34 - 'ta-citepublicationplace' => '$1 ($2)', # $1 = separator
35 - 'ta-citevolumerender' => "$1 '''$2'''", # $1 = separator
 33+ 'ta-series' => '$1',
 34+ 'ta-citepublicationplaceandpublisher' => '($1: $2)',
 35+ 'ta-citepublicationplace' => '($1)',
 36+ 'ta-citevolumerender' => "'''$1'''",
3637 'ta-citeissuerender' => '$1 ($2)', # $1 = volume
3738 'ta-citeatrender' => '$1: $2', # $1 = title info
38 - 'ta-citeatseparated' => '$1 $2', # $1 = separator
 39+ 'ta-citeatseparated' => '$1',
3940 'ta-citetitletyperender' => '$1 ($2)', # $1 = title/link
40 - 'ta-citepublisherrender' => '$1 $2', # $1 = separator
 41+ 'ta-citepublisherrender' => '$1',
4142 'ta-citepublished' => '$1 (published $2)', # $1 = title/link
4243 'ta-citeeditionrender' => '$1',
43 - 'ta-citepublication' => '$1 $2', # $1 = separator
44 - 'ta-citepublicationdate' => '$1 $2', # $1 = separator
45 - 'ta-citeretrievedupper' => '$1 Retrieved $2', # $1 = separator
46 - 'ta-citeretrievedlower' => '$1 retrieved $2', # $1 = separator
 44+ 'ta-citepublication' => '$1',
 45+ 'ta-citepublicationdate' => '$1',
 46+ 'ta-citeretrievedupper' => 'Retrieved $1',
 47+ 'ta-citeretrievedlower' => 'retrieved $1',
4748
4849 # citation span messages
4950 'ta-citeprintonlyspan' => '<span class="printonly">$1</span>',
Index: trunk/extensions/TemplateAdventures/Templates/Citation.php
@@ -4,9 +4,10 @@
55
66 private $dSeparators = array( # separators between names, items, etc.
77 'section' => ',',
8 - 'author' => '&#059;&#32;',
9 - 'name' => ',&#32;',
10 - 'authorlast' => '&#32;&amp;&#32;',
 8+ 'end' => '.',
 9+ 'author' => '&#059;',
 10+ 'name' => ',',
 11+ 'authorlast' => '&#32;&amp;',
1112 'beforepublication' => ':',
1213 );
1314 private $dAuthorTruncate = 8; # the amount of authors it should display,
@@ -88,6 +89,7 @@
8990 $this->dSeparators['name'] = wfMsg ( 'ta-citesep-name' );
9091 $this->dSeparators['authorlast'] = wfMsg ( 'ta-citesep-authorlast' );
9192 $this->dSeparators['beforepublication'] = wfMsg ( 'ta-citesep-beforepublication' );
 93+ $this->dSeparators['end'] = wfMsg ( 'ta-citesep-end' );
9294 $this->readOptions( );
9395 $this->parseData();
9496 }
@@ -107,7 +109,7 @@
108110 if ( $this->notNull ( $this->dYearNote ) )
109111 $authorArea = wfMsg ( 'ta-citeauthoryearnote', $authorArea, $this->dYearNote );
110112 }
111 - $this->mOutput .= $authorArea;
 113+ $this->mOutput .= $authorArea . $this->getSeparator ( 'section' );
112114 # editors
113115 } elseif ( count ( $this->dEditors ) > 1 ) {
114116 $editorArea = $this->createWriterSection ( $this->dEditors, $this->dEditorLinks, $this->dEditorTruncate );
@@ -121,17 +123,13 @@
122124 if ( $this->notNull ( $this->dYearNote ) )
123125 $editorArea .= wfMsg ( 'ta-citeauthoryearnote', $editorArea, $this->dYearNote );
124126 }
125 - $this->mOutput .= $editorArea;
 127+ $this->mOutput .= $editorArea . $this->getSeparator ( 'section' );
126128 }
127129 # included work title
128130 if ( $this->notNull( $this->dWorkTitle['includedwork'] )
129131 && ( $this->notNull( $this->dPeriodical['name'] )
130132 || $this->notNull( $this->dWorkTitle['transitalic'] )
131133 || $this->notNull( $this->dWorkTitle['transtitle'] ) ) ) {
132 - if ( $authorArea != ''
133 - || $editorArea != '' ) {
134 - $this->mOutput .= $this->getSeparator( 'section' );
135 - }
136134 # let's get the url
137135 if ( $this->notNull ( $this->dWorkLink['includedwork'] ) ) {
138136 $url = $this->dWorkLink['includedwork'];
@@ -173,7 +171,7 @@
174172 || $this->notNull ( $this->dWorkTitle['includedwork'] )
175173 )
176174 ) {
177 - $this->mOutput .= wfMsg ( 'ta-citewrittenat', $this->getSeparator ( 'section' ), $this->dPlace );
 175+ $this->mOutput .= wfMsg ( 'ta-citewrittenat', $this->dPlace ) . $this->getSeparator ( 'section' );
178176 }
179177 # editor of complication... eerrr...
180178 # TODO: we'll do this later...
@@ -182,11 +180,7 @@
183181 if ( $this->notNull ( $this->dPeriodical['name'] ) ) {
184182 $perArea = '';
185183 if ( $this->notNull ( $this->dOther ) )
186 - $perArea .= wfMsg ( 'ta-citeother', $this->getSeparator ( 'section' ), $this->dOther );
187 - if ( $authorArea != ''
188 - || $editorArea != ''
189 - || $this->notNull ( $this->dWorkTitle['includedwork'] ) )
190 - $perArea .= $this->getSeparator ( 'section' );
 184+ $perArea .= wfMsg ( 'ta-citeother', $this->dOther );
191185 # make the link!
192186 if ( $this->notNull ( $this->dWorkTitle['title'] ) || $this->notNull ( $this->dWorkTitle['transtitle'] ) ) {
193187 # let's get the url
@@ -225,68 +219,52 @@
226220 $tmp .= wfMsg ( 'ta-citetranstitle-render', $this->dWorkTitle['transtitle'] );
227221 }
228222 $title = "\"$tmp\"";
229 - $perArea .= $this->makeLink ( $url, $title );
 223+ $perArea .= $this->makeLink ( $url, $title ) . $this->getSeparator ( 'section' );
230224 if ( $this->notNull ( $this->dWorkTitle['note'] ) ) {
231 - $perArea .= $this->getSeparator ( 'section' ) . ' ' . $this->dWorkTitle['note'];
 225+ $perArea .= $this->dWorkTitle['note'] . $this->getSeparator ( 'section' );
232226 }
233227 }
234228 $this->mOutput .= $perArea;
235229 }
236230 # language
237231 if ( $this->notNull ( $this->dLanguage ) ) {
238 - # yes, I am cheating right now
239 - $this->mOutput .= wfMsg ( 'ta-citeinlanguage', '', $this->dLanguage );
 232+ $this->mOutput .= wfMsg ( 'ta-citeinlanguage', $this->dLanguage );
240233 }
241234 # format
242235 if ( $this->notNull ( $this->dFormat ) ) {
243 - # also here!
244 - $this->mOutput .= wfMsg ( 'ta-citeformatrender', '', $this->dFormat );
 236+ $this->mOutput .= wfMsg ( 'ta-citeformatrender', $this->dFormat );
245237 }
246238 # more periodical!
247239 if ( $this->notNull ( $this->dPeriodical['name'] ) ) {
248240 $newPerArea = '';
249 - if ( $this->notNull ( $this->dWorkTitle['includedwork'] )
250 - || $this->notNull ( $this->dWorkTitle['title'] )
251 - || $this->notNull ( $this->dWorkTitle['transtitle'] )
252 - ) {
253 - $newPerArea .= $this->getSeparator ( 'section' ) . ' ';
254 - }
255241 $newPerArea .= wfMsg ( 'ta-citeperiodical', $this->clean ( $this->dPeriodical['name'] ) );
256242 if ( $this->notNull ( $this->dSeries ) ) {
257 - $newPerArea .= wfMsg ( 'ta-citeseries', $this->getSeparator ( 'section' ), $this->dSeries );
 243+ $newPerArea .= wfMsg ( 'ta-citeseries', $this->dSeries );
258244 }
259245 if ( $this->notNull ( $this->dPublication['place'] ) ) {
260246 if ( $this->notNull ( $this->dPublisher ) ) {
261 - # so cheating with these messages, I think, blanks?!
262 - $newPerArea .= wfMsg ( 'ta-citepublicationplaceandpublisher', '', $this->dPublication['place'], $this->dPublisher );
 247+ $newPerArea .= wfMsg ( 'ta-citepublicationplaceandpublisher', $this->dPublication['place'], $this->dPublisher );
263248 } else {
264 - # Blank? BLANK!? You're not looking at the big picture!
265 - $newPerArea .= wfMsg ( 'ta-citepublicationplace', '', $this->dPublication['place'] );
 249+ $newPerArea .= wfMsg ( 'ta-citepublicationplace', $this->dPublication['place'] );
266250 }
267251 }
268252 if ( $this->notNull ( $this->dVolume ) ) {
269 - $newPerArea .= wfMsg ( 'ta-citevolumerender', '', $this->dVolume );
 253+ $newPerArea .= wfMsg ( 'ta-citevolumerender', $this->dVolume );
270254 if ( $this->notNUll ( $this->dIssue ) ) {
271 - $newPerArea .= wfMsg ( 'ta-citeissuerender', '', $this->dIssue );
 255+ $newPerArea .= wfMsg ( 'ta-citeissuerender', $this->dIssue );
272256 }
273257 } else {
274258 if ( $this->notNUll ( $this->dIssue ) ) {
275 - $newPerArea .= wfMsg ( 'ta-citeissuerender', '', $this->dIssue );
 259+ $newPerArea .= wfMsg ( 'ta-citeissuerender', $this->dIssue );
276260 }
277261 }
278262 if ( $this->notNull ( $this->dAt ) ) {
279 - $newPerArea .= wfMsg ( 'ta-citeatrender', '', $this->dAt );
 263+ $newPerArea .= wfMsg ( 'ta-citeatrender', $this->dAt );
280264 }
 265+ $newPerArea .= $this->getSeparator ( 'section' );
281266 # now we get to the title! Exciting stuff!
282267 if ( $this->notNull ( $this->dWorkTitle['title'] )
283268 || $this->notNull ( $this->dWorkTitle['transitalic'] ) ) {
284 - if ( $authorArea != ''
285 - || $editorArea != ''
286 - || $this->notNull ( $this->dWorkTitle['includedwork'] )
287 - || $this->notNull ( $this->dPeriodical['name'] )
288 - ) {
289 - $newPerArea .= $this->getSeparator ( 'section' );
290 - }
291269 # let's get the url
292270 if ( $this->notNull ( $this->dWorkTitle['includedwork'] ) ) {
293271 if ( $this->notNull ( $this->dWorkLink['includedwork'] ) ) {
@@ -330,55 +308,59 @@
331309 # it is easier to write this, but it also means that all of the
332310 # second input is actually evaluated, even if it contains nothing.
333311 $newPerArea .= $this->addNotNull ( $this->dWorkTitle['type'],
334 - wfMsg ( 'ta-citetitletyperender', '', $this->dWorkTitle['type'] ) );
 312+ wfMsg ( 'ta-citetitletyperender', $this->dWorkTitle['type'] ) . $this->getSeparator ( 'section' ) );
335313 $newPerArea .= $this->addNotNull ( $this->dSeries,
336 - wfMsg ( 'ta-citeseries', $this->getSeparator ( 'section' ), $this->dSeries ) );
 314+ wfMsg ( 'ta-citeseries', $this->dSeries ) . $this->getSeparator ( 'section' ) );
337315 $newPerArea .= $this->addNotNull ( $this->dVolume,
338 - wfMsg ( 'ta-citevolumerender', $this->getSeparator ( 'section' ), $this->dVolume ) );
 316+ wfMsg ( 'ta-citevolumerender', $this->dVolume ) . $this->getSeparator ( 'section' ) );
339317 $newPerArea .= $this->addNotNull ( $this->dOther,
340 - wfMsg ( 'ta-citeother', $this->getSeparator ( 'section' ), $this->dOther ) );
 318+ wfMsg ( 'ta-citeother', $this->dOther ) );
341319 $newPerArea .= $this->addNotNull ( $this->dEdition,
342 - wfMsg ( 'ta-citeeditionrender', $this->dEdition ) );
 320+ wfMsg ( 'ta-citeeditionrender', $this->dEdition ) . $this->getSeparator ( 'section' ) );
343321 $newPerArea .= $this->addNotNull ( $this->dPublication['place'],
344 - wfMsg ( 'ta-citepublication', $this->getSeparator ( 'section' ), $this->dPublication['place'] ) );
 322+ wfMsg ( 'ta-citepublication', $this->dPublication['place'] ) );
345323 if ( $this->notNull ( $this->dPublisher ) ) {
346324 if ( $this->notNull ( $this->dPublication['place'] ) ) {
347325 $sep = $this->getSeparator ( 'beforepublication' );
348326 } else {
349327 $sep = $this->getSeparator ( 'section' );
350328 }
351 - $newPerArea .= wfMsg ( 'ta-citepublisherrender', $sep, $this->dPublisher );
 329+ $newPerArea .= $sep . wfMsg ( 'ta-citepublisherrender', $this->dPublisher );
352330 }
353 - $this->mOutput .= $newPerArea;
 331+ $this->mOutput .= $newPerArea . $this->getSeparator ( 'section' );
354332 }
355333 # date if no author/editor
356334 if ( $authorArea == '' && $editorArea == '' ) {
357335 if ( $this->notNull ( $this->dDate ) ) {
358 - $this->mOutput .= wfMsg ( 'ta-citeauthordate', $this->getSeparator ( 'section' ), $this->dDate );
 336+ $this->mOutput .= wfMsg ( 'ta-citeauthordate', $this->dDate );
359337 if ( $this->notNull ( $this->dYearNote ) ) {
360 - $this->mOutput .= wfMsg ( 'ta-citeauthoryearnote', '', $this->dYearNote );
 338+ $this->mOutput .= wfMsg ( 'ta-citeauthoryearnote', $this->dYearNote );
361339 }
 340+ $this->mOutput .= $this->getSeparator ( 'section' );
362341 }
363342 }
364343 # publication date
365 - if ( $this->notNull ( $this->dPublication['date'] ) && $this->dPublication['date'] != $this->dDate ) {
 344+ if ( $this->notNull ( $this->dPublication['date'] )
 345+ && $this->dPublication['date'] != $this->dDate ) {
366346 if ( isset ( $this->dEditors[1] ) ) {
367347 if ( isset ( $this->dAuthors[1] ) ) {
368 - $this->mOutput .= wfMsg ( 'ta-citepublicationdate', $this->getSeparator ( 'section' ), $this->dPublication['date'] );
 348+ $this->mOutput .= wfMsg ( 'ta-citepublicationdate', $this->dPublication['date'] );
369349 } else {
370 - $this->mOutput .= wfMsg ( 'ta-citepublished', '', $this->dPublication['date'] );
 350+ $this->mOutput .= wfMsg ( 'ta-citepublished', $this->dPublication['date'] );
371351 }
372352 } else {
373353 if ( $this->notNull ( $this->dPeriodical['name'] ) ) {
374 - $this->mOutput .= wfMsg ( 'ta-citepublicationdate', $this->getSeparator ( 'section' ), $this->dPublication['date'] );
 354+ $this->mOutput .= wfMsg ( 'ta-citepublicationdate', $this->dPublication['date'] );
375355 } else {
376 - $this->mOutput .= wfMsg ( 'ta-citepublished', '', $this->dPublication['date'] );
 356+ $this->mOutput .= wfMsg ( 'ta-citepublished', $this->dPublication['date'] );
377357 }
378358 }
 359+ $this->mOutput .= $this->getSeparator ( 'section' );
379360 }
380361 # page within included work
381 - if ( !$this->notNull ( $this->dPeriodical['name'] ) && $this->notNull ( $this->dAt ) ) {
382 - $this->mOutput .= wfMsg ( 'ta-citeatseparated', $this->getSeparator ( 'section' ), $this->dAt );
 362+ if ( !$this->notNull ( $this->dPeriodical['name'] )
 363+ && $this->notNull ( $this->dAt ) ) {
 364+ $this->mOutput .= wfMsg ( 'ta-citeatseparated', $this->dAt );
383365 }
384366 # doi
385367 # TODO: I'll do this code later:
@@ -437,12 +419,11 @@
438420 || $this->notNull ( $this->dWorkTitle['includedwork'] )
439421 || $this->notNull ( $this->dWorkTitle['transtitle'] ) ) {
440422 $this->mOutput .= $this->printOnly (
441 - $this->getSeparator ( 'section' ) . ' ' .
442423 ( $this->notNull ( $this->dWorkLink['includedwork'] )
443424 ? $this->dWorkLink['includedwork']
444425 : $this->dWorkLink['url'] ) );
445426 } else {
446 - $this->mOutput .= $this->getSeparator ( 'section' ) . ' ' .
 427+ $this->mOutput .=
447428 ( $this->notNull ( $this->dWorkLink['includedwork'] )
448429 ? $this->dWorkLink['includedwork']
449430 : $this->dWorkLink['url'] );
@@ -465,6 +446,12 @@
466447 # some other shit nobody cares about.
467448 # COinS? waaaaat
468449 # TODO
 450+ $this->mOutput = trim($this->mOutput);
 451+ if ( $this->mOutput[strlen($this->mOutput)-1] == $this->getSeparator ( 'section', false ) ) {
 452+ $this->mOutput[strlen($this->mOutput)-1] = $this->getSeparator ( 'end', false );
 453+ } elseif ( $this->mOutput[strlen($this->mOutput)-1] != $this->getSeparator ( 'end', false ) ) {
 454+ $this->mOutput .= $this->getSeparator ( 'end', false );
 455+ }
469456 }
470457
471458 /**
@@ -513,7 +500,7 @@
514501 break;
515502 }
516503 if ( $n == count($writers)-1 && $i != 1 )
517 - $area .= $this->getSeparator( 'ampersand' );
 504+ $area .= $this->getSeparator( 'authorlast' );
518505 elseif ( $n > 1 )
519506 $area .= $this->getSeparator( 'author' );
520507 $tmp = '';
@@ -553,12 +540,15 @@
554541 * they are using a set separator message or just using a default one.
555542 *
556543 * @param $name Name of separator; section, author, name or authorlast
 544+ * @param $addSpace Whether to add a space at the end; default true
557545 * @return $separator Blank if none found.
558546 */
559 - private function getSeparator ( $name ) {
 547+ private function getSeparator ( $name, $addSpace=true ) {
560548 if ( !isset($this->dSeparators[$name]) )
561549 return '';
562550 $sep = $this->dSeparators[$name];
 551+ if ( $addSpace )
 552+ return $sep.' ';
563553 return $sep;
564554 }
565555

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r66057Far more render logic added. Still not added so much to parse input data.svip23:57, 7 May 2010
r66106Follow up/fix to r66057, hopefully this suffice greatly regarding the spaces ...svip13:52, 9 May 2010
r66107Fix to r66106; maybe I should test my code before I commit. >_>svip13:58, 9 May 2010

Status & tagging log