r66005 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66004‎ | r66005 | r66006 >
Date:11:23, 7 May 2010
Author:svip
Status:deferred
Tags:
Comment:
Further updates to citation, yet not done.
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
@@ -4,14 +4,21 @@
55
66 $magicWords['en'] = array(
77 # 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' ),
1825 );
Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.php
@@ -9,5 +9,8 @@
1010 'ta-citeauthoryearnote' => ' [$1]',
1111 'ta-editorsplural' => ', eds',
1212 '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',
1316 );
1417
Index: trunk/extensions/TemplateAdventures/Templates/Citation.php
@@ -92,36 +92,7 @@
9393 $this->mOutput = '';
9494 # authors
9595 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 );
12697 if ( $this->dCoAuthors != null )
12798 $authorArea .= $this->getSeparator( 'author' ) . $this->dCoAuthors;
12899 if ( $this->dDate != null ) {
@@ -130,37 +101,9 @@
131102 $authorArea .= wfMsg ( 'ta-citeauthoryearnote', $this->dYearNote );
132103 }
133104 $this->mOutput .= $authorArea;
 105+ # editors
134106 } 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 );
165108 if ( count ( $this->dEditors ) > 2 )
166109 $editorArea .= wfMsg ( 'ta-editorsplural' );
167110 else
@@ -173,9 +116,117 @@
174117 }
175118 $this->mOutput .= $editorArea;
176119 }
 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( "'", '&#39;', $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!
177175 }
178176
179177 /**
 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+ /**
180231 * This function should in the future do some wfMsg() magic to check if
181232 * they are using a set separator message or just using a default one.
182233 *
@@ -272,6 +323,20 @@
273324 } # let's not permit them to add authors/editors/etc. without a number
274325 }
275326
 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+
276341 /**
277342 * Checks whether the data provided is a known option.
278343 *
@@ -309,6 +374,15 @@
310375 case 'editorlink':
311376 $this->addEditorLink( $name, $value );
312377 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;
313387 default:
314388 # Wasn't an option after all
315389 return false;
@@ -334,6 +408,9 @@
335409 'ta_cc_coauthors',
336410 'ta_cc_editor', 'ta_cc_editorgiven',
337411 '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',
338415 ) );
339416 }
340417

Follow-up revisions

RevisionCommit summaryAuthorDate
r66006Follow up to r66005, fixed minor issue in writer section creation function.svip11:30, 7 May 2010
r66007Follow up to r66005 and r66006; I feel like such an idiot. Totally forgot to...svip11:31, 7 May 2010

Status & tagging log