Index: trunk/extensions/TemplateAdventures/Templates/Citation.php |
— | — | @@ -112,11 +112,14 @@ |
113 | 113 | * |
114 | 114 | * @param $content The content of section. |
115 | 115 | * @param $tags [default: array()] Some information regarding the content. |
| 116 | + * @param $separator [default: true] Whether it shall have a separator at |
| 117 | + * the end. |
116 | 118 | */ |
117 | | - private function addCiteSection ( $content, $tags = array () ) { |
| 119 | + private function addSection ( $content, $tags = array (), $separator = true ) { |
118 | 120 | $this->mSections[] = array ( |
| 121 | + $content, |
119 | 122 | $tags, |
120 | | - $content |
| 123 | + $separator |
121 | 124 | ); |
122 | 125 | $this->mTags = array_merge ( $this->mTags, $tags ); |
123 | 126 | } |
— | — | @@ -136,8 +139,8 @@ |
137 | 140 | private function isTagInSections ( $tag, $parent = null ) { |
138 | 141 | if ( $this->notNull ( $parent ) ) { |
139 | 142 | foreach ( $this->mSection as $section ) { |
140 | | - if ( in_array ( $tag, $section[0] ) |
141 | | - && $section[0][0] == $parent ) |
| 143 | + if ( in_array ( $tag, $section[1] ) |
| 144 | + && $section[1][0] == $parent ) |
142 | 145 | return true; |
143 | 146 | } |
144 | 147 | return false; |
— | — | @@ -152,16 +155,6 @@ |
153 | 156 | * TODO: Clean this baby up, probably be assigning some help functions. |
154 | 157 | */ |
155 | 158 | public function render() { |
156 | | - # boolean variables to keep track of output |
157 | | - # TODO: Once the section system is entirely written into this function, |
158 | | - # these can be replaced by the isTagInSections() function. |
159 | | - $urlDisplayed = false; # whether the url has been displayed |
160 | | - $authorDisplayed = false; # whether authors or editors have been |
161 | | - # displayed |
162 | | - $publisherDisplayed = false; # whether publisher have been displayed |
163 | | - $languageDisplayed = false; |
164 | | - # output |
165 | | - $this->mOutput = ''; |
166 | 159 | # authors |
167 | 160 | if ( count( $this->dAuthors ) > 1 ) { |
168 | 161 | # remember element 0 is always set |
— | — | @@ -185,9 +178,6 @@ |
186 | 179 | $this->dYearNote ); |
187 | 180 | } |
188 | 181 | $this->addSection ( $authorArea, array ( 'writer', 'author' ) ); |
189 | | - # TODO: remove this |
190 | | - $this->mOutput .= $authorArea . $this->getSeparator ( 'section' ); |
191 | | - $authorDisplayed = true; |
192 | 182 | # editors |
193 | 183 | } elseif ( count ( $this->dEditors ) > 1 ) { |
194 | 184 | # remember element 0 is always set |
— | — | @@ -210,9 +200,6 @@ |
211 | 201 | $editorArea, $this->dYearNote ); |
212 | 202 | } |
213 | 203 | $this->addSection ( $editorArea, array ( 'writer', 'editor' ) ); |
214 | | - # TODO: remove this |
215 | | - $this->mOutput .= $editorArea . $this->getSeparator ( 'section' ); |
216 | | - $authorDisplayed = true; |
217 | 204 | } |
218 | 205 | # included work title |
219 | 206 | if ( $this->notNull( $this->dWorkTitle['includedwork'] ) |
— | — | @@ -251,9 +238,6 @@ |
252 | 239 | } |
253 | 240 | $this->addSection ( $this->makeLink ( $url, $title ), |
254 | 241 | array ( 'title', 'includedlink' ) ); |
255 | | - # TODO: Remove this |
256 | | - $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' ); |
257 | | - $urlDisplayed = true; |
258 | 242 | } else if ( $this->notNull ( $this->dWorkTitle['title'] ) ) { |
259 | 243 | # if only the title is set, assume url is the URL of the title |
260 | 244 | $url = $this->dWorkLink['url']; |
— | — | @@ -265,37 +249,28 @@ |
266 | 250 | $this->addSection ( wfMsg ( 'ta-citeinlanguage', |
267 | 251 | $this->makeLink ( $url, $title ), $this->dLanguage ), |
268 | 252 | array ( 'title', 'transtitle', 'language' ) ); |
269 | | - # TODO: Remove this |
270 | | - $this->mOutput .= wfMsg ( 'ta-citeinlanguage', $this->makeLink ( $url, $title ), $this->dLanguage ) . $this->getSeparator( 'section' ); |
271 | | - $languageDisplayed = true; |
272 | 253 | } else { |
273 | 254 | $this->addSection ( $this->makeLink ( $url, $title ), |
274 | 255 | array ( 'title', 'transtitle' ) ); |
275 | | - # TODO: Remove this |
276 | | - $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' ); |
277 | 256 | } |
278 | 257 | } else { |
279 | 258 | $title = $this->dWorkTitle['title']; |
280 | 259 | $this->addSection ( $this->makeLink ( $url, $title ), |
281 | 260 | array ( 'title' ) ); |
282 | | - # TODO: Remove this |
283 | | - $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' ); |
284 | 261 | } |
285 | 262 | $urlDisplayed = true; |
286 | 263 | } else if ( $this->citeType == 'book' |
287 | 264 | && $this->notNull ( $this->dBook['title'] ) ) { |
288 | 265 | $this->addSection ( wfMsg ( 'ta-citebooktitle', $this->dBook['title'] ), |
289 | 266 | array ( 'title', 'book' ) ); |
290 | | - # TODO: Remove this |
291 | | - $this->mOutput .= wfMsg ( 'ta-citebooktitle', $this->dBook['title'] ) .$this->getSeparator ( 'section' ); |
292 | 267 | } |
293 | 268 | # place, but only if different from publication place. |
294 | | - if ( $this->notNull( $this->dPlace ) |
| 269 | + if ( $this->notNull ( $this->dPlace ) |
295 | 270 | && ( |
296 | 271 | !$this->notNull ( $this->dPublication['place'] ) |
297 | 272 | || $this->dPlace != $this->dPublication['place'] |
298 | 273 | ) && ( |
299 | | - $authorDisplayed |
| 274 | + $this->isTagInSections ( 'writer' ) |
300 | 275 | || $this->notNull ( $this->dWorkTitle['includedwork'] ) |
301 | 276 | ) && ( !in_array ( $this->citeType, array ( 'news', 'book' ) ) ) |
302 | 277 | ) { |
— | — | @@ -304,44 +279,51 @@ |
305 | 280 | $this->addSection ( wfMsg ( 'ta-citeplacepublisher', |
306 | 281 | $this->dPlace, $this->dPublisher ), |
307 | 282 | array ( 'place', 'publisher' ) ); |
308 | | - # TODO: Remove this |
309 | | - $this->mOutput .= wfMsg ( 'ta-citeplacepublisher', $this->dPlace,$this->dPublisher ) . $this->getSeparator ( 'section' ); |
310 | | - $publisherDisplayed = true; |
311 | 283 | } else { |
312 | 284 | $this->addSection ( wfMsg ( 'ta-citewrittenat', $this->dPlace ), |
313 | 285 | array ( 'place' ) ); |
314 | | - # TODO: Remove this |
315 | | - $this->mOutput .= wfMsg ( 'ta-citewrittenat', $this->dPlace ) . $this->getSeparator ( 'section' ); |
316 | 286 | } |
317 | 287 | } |
318 | 288 | if ( ( $this->citeType == 'news' ) |
319 | 289 | && $this->notNull ( $this->dPublisher ) ) { |
320 | 290 | if ( $this->notNull ( $this->dPlace ) ) { |
321 | | - $this->mOutput .= wfMsg ( 'ta-citenewspublisherplace', $this->dPublisher, $this->dPlace ) . $this->getSeparator ( 'section' ); |
| 291 | + $this->addSection ( wfMsg ( 'ta-citenewspublisherplace', |
| 292 | + $this->dPublisher, $this->dPlace ), |
| 293 | + array ( 'publisher', 'place', 'news' ) ); |
322 | 294 | } else { |
323 | | - $this->mOutput .= wfMsg ( 'ta-citenewspublisher', $this->dPublisher ) . $this->getSeparator ( 'section' ); |
| 295 | + $this->addSection ( wfMsg ( 'ta-citenewspublisher', |
| 296 | + $this->dPublisher ), |
| 297 | + array ( 'publisher', 'news' ) ); |
324 | 298 | } |
325 | 299 | } |
326 | 300 | if ( ( $this->citeType == 'journal' ) |
327 | 301 | && $this->notNull ( $this->dJournal['title'] ) ) { |
328 | 302 | if ( $this->notNull ( $this->dJournal['page'] ) ) { |
329 | | - $this->mOutput .= wfMsg ( 'ta-citejournalpage', |
| 303 | + $this->addSection ( wfMsg ( 'ta-citejournalpage', |
330 | 304 | $this->dJournal['title'], |
331 | | - $this->dJournal['page'] ) . $this->getSeparator ( 'section' ); |
| 305 | + $this->dJournal['page'] ), |
| 306 | + array ( 'journal', 'page' ) ); |
332 | 307 | } else { |
333 | | - $this->mOutput .= wfMsg ( 'ta-citejournal', |
334 | | - $this->dJournal['title'] ) . $this->getSeparator ( 'section' ); |
| 308 | + $this->addSection ( wfMsg ( 'ta-citejournal', |
| 309 | + $this->dJournal['title'] ), |
| 310 | + array ( 'journal' ) ); |
335 | 311 | } |
336 | 312 | } |
337 | 313 | if ( ( $this->citeType == 'book' ) |
338 | 314 | && $this->notNull ( $this->dPublisher ) ) { |
339 | 315 | if ( $this->notNull ( $this->dPlace ) ) { |
340 | | - $this->mOutput .= wfMsg ( 'ta-citebookpubplace', $this->dPlace, $this->dPublisher ) . $this->getSeparator ( 'section' ); |
| 316 | + $this->addSection ( wfMsg ( 'ta-citebookpubplace', |
| 317 | + $this->dPlace, $this->dPublisher ), |
| 318 | + array ( 'publisher', 'place', 'book' ) ); |
341 | 319 | } else { |
342 | | - $this->mOutput .= wfMsg ( 'ta-citebookpublisher', $this->dPublisher ) . $this->getSeparator ( 'section' ); |
| 320 | + $this->addSection ( wfMsg ( 'ta-citebookpublisher', |
| 321 | + $this->dPublisher ), |
| 322 | + array ( 'publisher', 'book' ) ); |
343 | 323 | } |
344 | 324 | if ( $this->notNull ( $this->dBook['page'] ) ) { |
345 | | - $this->mOutput .= wfMsg ( 'ta-citebookpage', $this->dBook['page'] ) . $this->getSeparator ( 'section' ); |
| 325 | + $this->addSection ( wfMsg ( 'ta-citebookpage', |
| 326 | + $this->dBook['page'] ), |
| 327 | + array ( 'page', 'book' ) ); |
346 | 328 | } |
347 | 329 | } |
348 | 330 | # editor of complication... eerrr... |
— | — | @@ -395,17 +377,19 @@ |
396 | 378 | $perArea .= $this->dWorkTitle['note'] . $this->getSeparator ( 'section' ); |
397 | 379 | } |
398 | 380 | } |
399 | | - $this->mOutput .= $perArea; |
| 381 | + $this->addSection ( $perArea, |
| 382 | + array ( 'title', 'periodicals' ) ); |
400 | 383 | } |
401 | 384 | # language |
402 | 385 | if ( $this->notNull ( $this->dLanguage ) |
403 | | - && !$languageDisplayed ) { |
404 | | - $this->mOutput .= wfMsg ( 'ta-citeinlanguage', $this->dLanguage ); |
405 | | - $languageDisplayed = true; |
| 386 | + && !$this->isTagInSections ( 'language' ) ) { |
| 387 | + $this->addSection ( wfMsg ( 'ta-citeinlanguage', |
| 388 | + $this->dLanguage ), array ( 'language' ) ); |
406 | 389 | } |
407 | 390 | # format |
408 | 391 | if ( $this->notNull ( $this->dFormat ) ) { |
409 | | - $this->mOutput .= wfMsg ( 'ta-citeformatrender', $this->dFormat ); |
| 392 | + $this->addSection ( wfMsg ( 'ta-citeformatrender', |
| 393 | + $this->dFormat ), array ( 'format' ) ); |
410 | 394 | } |
411 | 395 | # more periodical! |
412 | 396 | if ( $this->notNull ( $this->dPeriodical['name'] ) ) { |
— | — | @@ -500,41 +484,46 @@ |
501 | 485 | } |
502 | 486 | $newPerArea .= $sep . wfMsg ( 'ta-citepublisherrender', $this->dPublisher ); |
503 | 487 | } |
504 | | - $this->mOutput .= $newPerArea . $this->getSeparator ( 'section' ); |
| 488 | + $this->addSection ( $newPerArea, |
| 489 | + array ( 'details', 'periodicals' ) ); |
505 | 490 | } |
506 | 491 | # date if no author/editor |
507 | | - if ( !$authorDisplayed ) { |
| 492 | + if ( !$this->isTagInSections ( 'writer' ) ) { |
508 | 493 | if ( $this->notNull ( $this->dDate ) |
509 | 494 | || $this->notNull ( $this->dYear ) ) { |
510 | 495 | $tmp = wfMsg ( 'ta-citealonedate', $this->notNull ( $this->dDate ) ? $this->dDate : $this->dYear ); |
511 | 496 | if ( $this->notNull ( $this->dYearNote ) ) { |
512 | 497 | $tmp = wfMsg ( 'ta-citeauthoryearnote', $tmp, $this->dYearNote ); |
513 | 498 | } |
514 | | - $this->mOutput .= $tmp . $this->getSeparator ( 'section' ); |
| 499 | + $this->addSection ( $tmp, array ( 'date' ) ); |
515 | 500 | } |
516 | 501 | } |
517 | 502 | # publication date |
518 | 503 | if ( $this->notNull ( $this->dPublication['date'] ) |
519 | 504 | && $this->dPublication['date'] != $this->dDate ) { |
520 | | - if ( isset ( $this->dEditors[1] ) ) { |
521 | | - if ( isset ( $this->dAuthors[1] ) ) { |
522 | | - $this->mOutput .= wfMsg ( 'ta-citepublicationdate', $this->dPublication['date'] ); |
| 505 | + if ( $this->isTagInSections ( 'editor' ) ) { |
| 506 | + if ( $this->isTagInSections ( 'author' ) ) { |
| 507 | + $this->addSection ( wfMsg ( 'ta-citepublicationdate', $this->dPublication['date'] ), |
| 508 | + array ( 'publication date', 'periodical' ) ); |
523 | 509 | } else { |
524 | | - $this->mOutput .= wfMsg ( 'ta-citepublished', $this->dPublication['date'] ); |
| 510 | + $this->addSection ( wfMsg ( 'ta-citepublished', $this->dPublication['date'] ), |
| 511 | + array ( 'publication date', 'periodical' ) ); |
525 | 512 | } |
526 | 513 | } else { |
527 | 514 | if ( $this->notNull ( $this->dPeriodical['name'] ) ) { |
528 | | - $this->mOutput .= wfMsg ( 'ta-citepublicationdate', $this->dPublication['date'] ); |
| 515 | + $this->addSection ( wfMsg ( 'ta-citepublicationdate', $this->dPublication['date'] ), |
| 516 | + array ( 'publication date', 'periodical' ) ); |
529 | 517 | } else { |
530 | | - $this->mOutput .= wfMsg ( 'ta-citepublished', $this->dPublication['date'] ); |
| 518 | + $this->addSection ( wfMsg ( 'ta-citepublished', $this->dPublication['date'] ), |
| 519 | + array ( 'publication date', 'periodical' ) ); |
531 | 520 | } |
532 | 521 | } |
533 | | - $this->mOutput .= $this->getSeparator ( 'section' ); |
534 | 522 | } |
535 | 523 | # page within included work |
536 | 524 | if ( !$this->notNull ( $this->dPeriodical['name'] ) |
537 | 525 | && $this->notNull ( $this->dAt ) ) { |
538 | | - $this->mOutput .= wfMsg ( 'ta-citeatseparated', $this->dAt ); |
| 526 | + $this->addSection ( wfMsg ( 'ta-citeatseparated', $this->dAt ), |
| 527 | + array ( 'at', 'periodical' ) ); |
539 | 528 | } |
540 | 529 | # doi |
541 | 530 | # TODO: I'll do this code later: |
— | — | @@ -551,10 +540,10 @@ |
552 | 541 | # isbn |
553 | 542 | if ( $this->citeType == 'book' |
554 | 543 | && $this->notNull ( $this->dBook['isbn'] ) ) { |
555 | | - $this->mOutput .= wfMsg ( 'ta-citebookisbn', |
556 | | - $this->dBook['isbn'], |
557 | | - $this->createDisplayISBN ( $this->dBook['isbn'] ) |
558 | | - ) . $this->getSeparator ( 'section' ); |
| 544 | + $this->addSection ( wfMsg ( 'ta-citebookisbn', |
| 545 | + $this->dBook['isbn'], |
| 546 | + $this->createDisplayISBN ( $this->dBook['isbn'] ) ), |
| 547 | + array ( 'isbn' ) ); |
559 | 548 | } |
560 | 549 | |
561 | 550 | # more identifiers: |
— | — | @@ -596,15 +585,19 @@ |
597 | 586 | if ( $this->notNull ( $this->dWorkTitle['title'] ) |
598 | 587 | || $this->notNull ( $this->dWorkTitle['includedwork'] ) |
599 | 588 | || $this->notNull ( $this->dWorkTitle['transtitle'] ) ) { |
600 | | - $this->mOutput .= $this->printOnly ( |
| 589 | + $this->addSection ( $this->printOnly ( |
601 | 590 | ( $this->notNull ( $this->dWorkLink['includedwork'] ) |
602 | 591 | ? $this->dWorkLink['includedwork'] |
603 | | - : $this->dWorkLink['url'] ) ); |
| 592 | + : $this->dWorkLink['url'] ) ), |
| 593 | + array ( 'url', 'printonly' ), |
| 594 | + false ); |
604 | 595 | } else { |
605 | | - $this->mOutput .= |
| 596 | + $this->addSection ( |
606 | 597 | ( $this->notNull ( $this->dWorkLink['includedwork'] ) |
607 | 598 | ? $this->dWorkLink['includedwork'] |
608 | | - : $this->dWorkLink['url'] ); |
| 599 | + : $this->dWorkLink['url'] ), |
| 600 | + array ( 'url' ), |
| 601 | + false ); |
609 | 602 | } |
610 | 603 | } |
611 | 604 | if ( $this->notNull ( $this->dAccessDate ) ) { |
— | — | @@ -612,7 +605,8 @@ |
613 | 606 | $tmp = wfMsg ( 'ta-citeretrievedupper', $this->dAccessDate ); |
614 | 607 | else |
615 | 608 | $tmp = wfMsg ( 'ta-citeretrievedlower', $this->dAccessDate ); |
616 | | - $this->mOutput .= wfMsg ( 'ta-citeaccessdatespan', $tmp ); |
| 609 | + $this->addSection ( wfMsg ( 'ta-citeaccessdatespan', $tmp ), |
| 610 | + array ( 'accessdate' ) ); |
617 | 611 | } |
618 | 612 | } |
619 | 613 | |
— | — | @@ -625,12 +619,20 @@ |
626 | 620 | # some other shit nobody cares about. |
627 | 621 | # COinS? waaaaat |
628 | 622 | # TODO |
629 | | - $this->mOutput = trim($this->mOutput); |
630 | | - if ( $this->mOutput[strlen($this->mOutput)-1] == $this->getSeparator ( 'section', false ) ) { |
631 | | - $this->mOutput[strlen($this->mOutput)-1] = $this->getSeparator ( 'end', false ); |
632 | | - } elseif ( $this->mOutput[strlen($this->mOutput)-1] != $this->getSeparator ( 'end', false ) ) { |
633 | | - $this->mOutput .= $this->getSeparator ( 'end', false ); |
| 623 | + |
| 624 | + $this->mOutput = ''; |
| 625 | + |
| 626 | + $len = count ( $this->mSections ); |
| 627 | + |
| 628 | + foreach ( $this->mSections as $i => $section ) { |
| 629 | + $this->mOutput .= $section[0]; |
| 630 | + if ( ( $i + 1 < $len ) |
| 631 | + && $section[2] ) |
| 632 | + $this->mOutput .= $this->getSeparator ( 'section' ); |
634 | 633 | } |
| 634 | + |
| 635 | + $this->mOutput .= $this->getSeparator ( 'end' ); |
| 636 | + |
635 | 637 | # if the end 'separator' is blank, so we trim |
636 | 638 | $this->mOutput = wfMsg ( 'ta-citationspan', trim($this->mOutput), $this->citeType ); |
637 | 639 | } |