r86338 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86337‎ | r86338 | r86339 >
Date:19:21, 18 April 2011
Author:svip
Status:deferred
Tags:
Comment:
Added more sophistication...
Modified paths:
  • /trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.magic.php (modified) (history)
  • /trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.php (modified) (history)
  • /trunk/extensions/TemplateAdventures/Templates/Citation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.magic.php
@@ -6,8 +6,8 @@
77 # citation magic words
88 'citation' => array( 1, 'citation' ),
99 'ta_cc_author' => array( 0, 'author' ),
10 - 'ta_cc_authorsurname' => array( 0, 'surname' ),
11 - 'ta_cc_authorgiven' => array( 0, 'given' ),
 10+ 'ta_cc_authorsurname' => array( 0, 'surname', 'last' ),
 11+ 'ta_cc_authorgiven' => array( 0, 'given', 'first' ),
1212 'ta_cc_authorlink' => array( 0, 'authorlink' ),
1313 'ta_cc_coauthors' => array( 0, 'coauthors' ),
1414 'ta_cc_editor' => array( 0, 'editor' ),
@@ -21,4 +21,7 @@
2222 'ta_cc_periodical' => array( 0, 'periodical' ),
2323 'ta_cc_transitalic' => array( 0, 'transitalic' ),
2424 'ta_cc_transtitle' => array( 0, 'transtitle' ),
 25+ 'ta_cc_year' => array( 0, 'year' ),
 26+ 'ta_cc_publisher' => array( 0, 'publisher' ),
 27+ 'ta_cc_place' => array( 0, 'place' ),
2528 );
Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.php
@@ -26,6 +26,7 @@
2727 'ta-citepubmed-url' => 'http://www.pubmedcentral.nih.gov/articlerender.fcgi?tool=pmcentrez&artid=$1',
2828 'ta-citetranstitle-render' => '[$1]',
2929 'ta-citewrittenat' => 'written at $1',
 30+ 'ta-citeplacepublisher' => '$1: $2', # $1 = place, $2 = publisher
3031 'ta-citeother' => '$1',
3132 'ta-citeinlanguage' => '$1 (in $2)', # $1 = title/link
3233 'ta-citeformatrender' => '$1 ($2)', # $1 = title/link
Index: trunk/extensions/TemplateAdventures/Templates/Citation.php
@@ -98,18 +98,26 @@
9999 * Render the data after the data have been read.
100100 */
101101 public function render() {
 102+ # boolean variables to keep track of output
 103+ $urlDisplayed = false; # whether the url has been displayed
 104+ $authorDisplayed = false; # whether authors or editors have been
 105+ # displayed
 106+ $publisherDisplayed = false; # whether publisher have been displayed
 107+ # output
102108 $this->mOutput = '';
103109 # authors
104110 if ( count( $this->dAuthors ) > 1 ) {
105111 $authorArea = $this->createWriterSection ( $this->dAuthors, $this->dAuthorLinks, $this->dAuthorTruncate );
106112 if ( $this->notNull ( $this->dCoAuthors ) )
107113 $authorArea = wfMsg ( 'ta-citecoauthors', $authorArea, $this->getSeparator( 'author' ), $this->dCoAuthors );
108 - if ( $this->notNull ( $this->dDate ) ) {
109 - $authorArea = wfMsg ( 'ta-citeauthordate', $authorArea, $this->dDate);
 114+ if ( $this->notNull ( $this->dDate )
 115+ || $this->notNull ( $this->dYear ) ) {
 116+ $authorArea = wfMsg ( 'ta-citeauthordate', $authorArea, $this->notNull ( $this->dDate ) ? $this->dDate : $this->dYear );
110117 if ( $this->notNull ( $this->dYearNote ) )
111118 $authorArea = wfMsg ( 'ta-citeauthoryearnote', $authorArea, $this->dYearNote );
112119 }
113120 $this->mOutput .= $authorArea . $this->getSeparator ( 'section' );
 121+ $authorDisplayed = true;
114122 # editors
115123 } elseif ( count ( $this->dEditors ) > 1 ) {
116124 $editorArea = $this->createWriterSection ( $this->dEditors, $this->dEditorLinks, $this->dEditorTruncate );
@@ -118,12 +126,14 @@
119127 else
120128 $editorArea = wfMsg ( 'ta-citeeditorssingular', $editorArea );
121129 $editorArea .= $this->getSeparator ( 'section' );
122 - if ( $this->notNull ( $this->dDate ) ) {
123 - $editorArea = wfMsg ( 'ta-citeauthordate', $editorArea, $this->dDate);
 130+ if ( $this->notNull ( $this->dDate )
 131+ || $this->notNull ( $this->dYear ) ) {
 132+ $editorArea = wfMsg ( 'ta-citeauthordate', $editorArea, $this->notNull ( $this->dDate ) ? $this->dDate : $this->dYear );
124133 if ( $this->notNull ( $this->dYearNote ) )
125134 $editorArea .= wfMsg ( 'ta-citeauthoryearnote', $editorArea, $this->dYearNote );
126135 }
127136 $this->mOutput .= $editorArea . $this->getSeparator ( 'section' );
 137+ $authorDisplayed = true;
128138 }
129139 # included work title
130140 if ( $this->notNull( $this->dWorkTitle['includedwork'] )
@@ -160,18 +170,31 @@
161171 }
162172 $title = $tmp;
163173 }
164 - $this->mOutput .= $this->makeLink ( $url, $title );
 174+ $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
 175+ $urlDisplayed = true;
 176+ } else if ( $this->notNull ( $this->dWorkTitle['title'] ) ) {
 177+ # if only the title is set, assume url is the URL of the title
 178+ $url = $this->dWorkLink['url'];
 179+ $title = $this->dWorkTitle['title'];
 180+ $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
 181+ $urlDisplayed = true;
165182 }
166183 # place, but only if different from publication place.
167184 if ( $this->notNull( $this->dPlace )
168 - && $this->dPlace != $this->dPublication['place']
169 - && (
170 - $this->notNull ( $authorArea )
171 - || $this->notNull ( $editorArea )
 185+ && (
 186+ !$this->notNull ( $this->dPublication['place'] )
 187+ || $this->dPlace != $this->dPublication['place']
 188+ ) && (
 189+ $authorDisplayed
172190 || $this->notNull ( $this->dWorkTitle['includedwork'] )
173191 )
174192 ) {
175 - $this->mOutput .= wfMsg ( 'ta-citewrittenat', $this->dPlace ) . $this->getSeparator ( 'section' );
 193+ if ( $this->notNull ( $this->dPublisher ) ) {
 194+ $this->mOutput .= wfMsg ( 'ta-citeplacepublisher', $this->dPlace,$this->dPublisher ) . $this->getSeparator ( 'section' );
 195+ $publisherDisplayed = true;
 196+ } else {
 197+ $this->mOutput .= wfMsg ( 'ta-citewrittenat', $this->dPlace ) . $this->getSeparator ( 'section' );
 198+ }
176199 }
177200 # editor of complication... eerrr...
178201 # TODO: we'll do this later...
@@ -330,9 +353,10 @@
331354 $this->mOutput .= $newPerArea . $this->getSeparator ( 'section' );
332355 }
333356 # date if no author/editor
334 - if ( $authorArea == '' && $editorArea == '' ) {
335 - if ( $this->notNull ( $this->dDate ) ) {
336 - $this->mOutput .= wfMsg ( 'ta-citeauthordate', $this->dDate );
 357+ if ( !$authorDisplayed ) {
 358+ if ( $this->notNull ( $this->dDate )
 359+ || $this->notNull ( $this->dYear ) ) {
 360+ $this->mOutput .= wfMsg ( 'ta-citeauthordate', $this->notNull ( $this->dDate ) ? $this->dDate : $this->dYear );
337361 if ( $this->notNull ( $this->dYearNote ) ) {
338362 $this->mOutput .= wfMsg ( 'ta-citeauthoryearnote', $this->dYearNote );
339363 }
@@ -415,18 +439,20 @@
416440 # URL and accessdate
417441 if ( $this->notNull ( $this->dWorkLink['url'] )
418442 || $this->notNull ( $this->dWorkLink['includedwork'] ) ) {
419 - if ( $this->notNull ( $this->dWorkTitle['title'] )
420 - || $this->notNull ( $this->dWorkTitle['includedwork'] )
421 - || $this->notNull ( $this->dWorkTitle['transtitle'] ) ) {
422 - $this->mOutput .= $this->printOnly (
 443+ if ( !$urlDisplayed ) {
 444+ if ( $this->notNull ( $this->dWorkTitle['title'] )
 445+ || $this->notNull ( $this->dWorkTitle['includedwork'] )
 446+ || $this->notNull ( $this->dWorkTitle['transtitle'] ) ) {
 447+ $this->mOutput .= $this->printOnly (
 448+ ( $this->notNull ( $this->dWorkLink['includedwork'] )
 449+ ? $this->dWorkLink['includedwork']
 450+ : $this->dWorkLink['url'] ) );
 451+ } else {
 452+ $this->mOutput .=
423453 ( $this->notNull ( $this->dWorkLink['includedwork'] )
424454 ? $this->dWorkLink['includedwork']
425 - : $this->dWorkLink['url'] ) );
426 - } else {
427 - $this->mOutput .=
428 - ( $this->notNull ( $this->dWorkLink['includedwork'] )
429 - ? $this->dWorkLink['includedwork']
430 - : $this->dWorkLink['url'] );
 455+ : $this->dWorkLink['url'] );
 456+ }
431457 }
432458 if ( $this->notNull ( $this->dAccessDate ) ) {
433459 if ( $this->getSeparator ( 'section' ) == '.' )
@@ -452,6 +478,8 @@
453479 } elseif ( $this->mOutput[strlen($this->mOutput)-1] != $this->getSeparator ( 'end', false ) ) {
454480 $this->mOutput .= $this->getSeparator ( 'end', false );
455481 }
 482+ # if the end 'separator' is blank
 483+ $this->mOutput = trim($this->mOutput);
456484 }
457485
458486 /**
@@ -620,19 +648,20 @@
621649
622650 private function appendWriterData( &$array, $num, $name ) {
623651 $split = is_array( $name );
624 - if ( $num != null ) {
625 - if ( isset($array[$num]) && $array[$num][0] ) {
626 - if ( $name[0] != null )
627 - $array[$num][1][0] = $name[0];
628 - else
629 - $array[$num][1][1] = $name[1];
630 - } else {
631 - $array[$num] = array (
632 - $split,
633 - $name
634 - );
635 - }
636 - } # let's not permit them to add authors/editors/etc. without a number
 652+ if ( $num == null )
 653+ # if no number, assume it is the first.
 654+ $num = 1;
 655+ if ( isset($array[$num]) && $array[$num][0] ) {
 656+ if ( $name[0] != null )
 657+ $array[$num][1][0] = $name[0];
 658+ else
 659+ $array[$num][1][1] = $name[1];
 660+ } else {
 661+ $array[$num] = array (
 662+ $split,
 663+ $name
 664+ );
 665+ }
637666 }
638667
639668 private function addOtherStringValue ( $name, $value ) {
@@ -649,6 +678,15 @@
650679 case 'periodical':
651680 $this->dPeriodical['name'] = $value;
652681 break;
 682+ case 'year':
 683+ $this->dYear = $value;
 684+ break;
 685+ case 'place':
 686+ $this->dPlace = $value;
 687+ break;
 688+ case 'publisher':
 689+ $this->dPublisher = $value;
 690+ break;
653691 }
654692 }
655693
@@ -696,6 +734,9 @@
697735 case 'periodical':
698736 case 'transitalic':
699737 case 'transtitle':
 738+ case 'year':
 739+ case 'place':
 740+ case 'publisher':
700741 $this->addOtherStringValue( $name, $value );
701742 break;
702743 default:
@@ -727,6 +768,8 @@
728769 'ta_cc_url', 'ta_cc_title', 'ta_cc_pmc',
729770 'ta_cc_includedworktitle', 'ta_cc_periodical',
730771 'ta_cc_transitalic', 'ta_cc_transtitle',
 772+ 'ta_cc_year', 'ta_cc_publisher',
 773+ 'ta_cc_place',
731774 ) );
732775 }
733776

Status & tagging log