Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.magic.php |
— | — | @@ -4,7 +4,7 @@ |
5 | 5 | |
6 | 6 | $magicWords['en'] = array( |
7 | 7 | # citation magic words |
8 | | - 'citation' => array( 1, 'citation' ), |
| 8 | + 'ta_citation' => array( 1, 'citation' ), |
9 | 9 | 'ta_cc_author' => array( 0, 'author' ), |
10 | 10 | 'ta_cc_authorsurname' => array( 0, 'surname', 'last' ), |
11 | 11 | 'ta_cc_authorgiven' => array( 0, 'given', 'first' ), |
Index: trunk/extensions/TemplateAdventures/TemplateAdventures.php |
— | — | @@ -60,7 +60,7 @@ |
61 | 61 | |
62 | 62 | public static function onParserFirstCallInit( $parser ) { |
63 | 63 | $parser->setFunctionHook( |
64 | | - 'citation', |
| 64 | + 'ta_citation', |
65 | 65 | array( __CLASS__, 'citation' ), |
66 | 66 | SFH_OBJECT_ARGS |
67 | 67 | ); |
Index: trunk/extensions/TemplateAdventures/Templates/Citation.php |
— | — | @@ -98,6 +98,8 @@ |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Render the data after the data have been read. |
| 102 | + * |
| 103 | + * TODO: Clean this baby up, probably be assigning some help functions. |
102 | 104 | */ |
103 | 105 | public function render() { |
104 | 106 | # boolean variables to keep track of output |
— | — | @@ -517,6 +519,13 @@ |
518 | 520 | return wfMsg ( 'ta-citeprintonlyspan', $string ); |
519 | 521 | } |
520 | 522 | |
| 523 | + /** |
| 524 | + * Return something if it is not null. |
| 525 | + * |
| 526 | + * @param $check Variable to check against. |
| 527 | + * @param $add String to add. |
| 528 | + * @return $add if check is not null else '' |
| 529 | + */ |
521 | 530 | private function addNotNull ( $check, $add ) { |
522 | 531 | if ( $this->notNull ( $check ) ) |
523 | 532 | return $add; |
— | — | @@ -578,15 +587,28 @@ |
579 | 588 | } |
580 | 589 | return $area; |
581 | 590 | } |
582 | | - |
| 591 | + |
| 592 | + /** |
| 593 | + * Create a wikilink. If no $url, return the $title. |
| 594 | + * |
| 595 | + * @param $url The url |
| 596 | + * @param $title Title for the URL. |
| 597 | + * @return $title if no $url otherwise the link. |
| 598 | + */ |
583 | 599 | private function makeLink ( $url, $title ) { |
584 | 600 | if ( !$url ) |
585 | 601 | return $title; |
586 | 602 | return "[$url $title]"; |
587 | 603 | } |
588 | | - |
| 604 | + |
| 605 | + /** |
| 606 | + * Check if $check is not null, where blank ('') is considered null. |
| 607 | + * |
| 608 | + * @param $check Variable to check |
| 609 | + * @return Boolean |
| 610 | + */ |
589 | 611 | private function notNull ( $check ) { |
590 | | - return !( $check == null && $check == '' ); |
| 612 | + return !( $check == null && $check === '' ); |
591 | 613 | } |
592 | 614 | |
593 | 615 | /** |
— | — | @@ -623,55 +645,118 @@ |
624 | 646 | } |
625 | 647 | $this->dAuthors = $tmpAuthors; |
626 | 648 | } |
627 | | - |
| 649 | + |
| 650 | + /** |
| 651 | + * This is the editor function section. These functions are designed to |
| 652 | + * add editors (which are considered different from authors) to the |
| 653 | + * template, as there can be an inf amount of editors/authors. |
| 654 | + * |
| 655 | + * This adds the link for the editor. |
| 656 | + * |
| 657 | + * @param $name Editor-reference. |
| 658 | + * @param $value Link |
| 659 | + */ |
628 | 660 | private function addEditorLink( $name, $value ) { |
629 | 661 | if ( $name[1] == null ) |
630 | 662 | return; |
631 | 663 | $this->dEditorLinks[$name[1]] = $value; |
632 | 664 | } |
633 | | - |
| 665 | + |
| 666 | + /** |
| 667 | + * Adds a new editor, but does not divide it into first and last names. |
| 668 | + * |
| 669 | + * @param $name Editor-reference. |
| 670 | + * @param $value Name |
| 671 | + */ |
634 | 672 | private function addEditor( $name, $value ) { |
635 | 673 | $this->appendEditorData ( $name[1], $value ); |
636 | 674 | } |
637 | 675 | |
| 676 | + /** |
| 677 | + * Adds surname. |
| 678 | + * |
| 679 | + * @param $name Editor-reference. |
| 680 | + * @param $value Surname |
| 681 | + */ |
638 | 682 | private function addEditorSurname( $name, $value ) { |
639 | 683 | $this->appendEditorData ( $name[1], array ( null, $value ) ); |
640 | 684 | } |
641 | 685 | |
| 686 | + /** |
| 687 | + * Adds first name. |
| 688 | + * |
| 689 | + * @param $name Editor-reference. |
| 690 | + * @param $value Given name |
| 691 | + */ |
642 | 692 | private function addEditorGivenName ( $name, $value ) { |
643 | 693 | $this->appendEditorData ( $name[1], array ( $value, null ) ); |
644 | 694 | } |
645 | | - |
| 695 | + |
| 696 | + /** |
| 697 | + * Appends the editor to the editor array. |
| 698 | + * |
| 699 | + * @param $num Editor-reference. |
| 700 | + * @param $name Details |
| 701 | + */ |
646 | 702 | private function appendEditorData( $num, $name ) { |
647 | 703 | $this->appendWriterData( $this->dEditors, $num, $name ); |
648 | 704 | } |
649 | | - |
| 705 | + |
| 706 | + /** |
| 707 | + * These functions are similar to the editor functions and does the same, |
| 708 | + * but for the author variables. Their functionality could possibly be |
| 709 | + * referenced in grouped help functions, but right now they are all so |
| 710 | + * short that it seems to be an overhead of useless work. |
| 711 | + * |
| 712 | + * @param $name Author-reference |
| 713 | + * @param $value Link |
| 714 | + */ |
650 | 715 | private function addAuthorLink( $name, $value ) { |
651 | 716 | if ( $name[1] == null ) |
652 | 717 | return; |
653 | 718 | $this->dAuthorLinks[$name[1]] = $value; |
654 | 719 | } |
655 | 720 | |
| 721 | + /** |
| 722 | + * @param $name Author-reference |
| 723 | + * @param $value Full name |
| 724 | + */ |
656 | 725 | private function addAuthor( $name, $value ) { |
657 | 726 | $this->appendAuthorData ( $name[1], $value ); |
658 | 727 | } |
659 | | - |
| 728 | + |
| 729 | + /** |
| 730 | + * @param $name Author-reference |
| 731 | + * @param $value Surname |
| 732 | + */ |
660 | 733 | private function addAuthorSurname( $name, $value ) { |
661 | 734 | $this->appendAuthorData ( $name[1], array ( null, $value ) ); |
662 | 735 | } |
663 | | - |
| 736 | + |
| 737 | + /** |
| 738 | + * @param $name Author-reference |
| 739 | + * @param $value Given name |
| 740 | + */ |
664 | 741 | private function addAuthorGivenName ( $name, $value ) { |
665 | 742 | $this->appendAuthorData ( $name[1], array ( $value, null ) ); |
666 | 743 | } |
667 | | - |
668 | | - private function addCoAuthors ( $name, $value ) { |
669 | | - $this->dCoAuthors = $value; |
670 | | - } |
671 | | - |
| 744 | + |
| 745 | + /** |
| 746 | + * @param $num Author-reference |
| 747 | + * @param $name Details |
| 748 | + */ |
672 | 749 | private function appendAuthorData( $num, $name ) { |
673 | 750 | $this->appendWriterData( $this->dAuthors, $num, $name ); |
674 | 751 | } |
675 | | - |
| 752 | + |
| 753 | + /** |
| 754 | + * This function appends the details (link and name) of authors or editors |
| 755 | + * to their respective arrays. |
| 756 | + * |
| 757 | + * @param $array The array. |
| 758 | + * @param $num The location in the array (0 is always set, but never used) |
| 759 | + * @param $name The name and link of the author/editor. |
| 760 | + */ |
676 | 761 | private function appendWriterData( &$array, $num, $name ) { |
677 | 762 | $split = is_array( $name ); |
678 | 763 | if ( $num == null ) |
— | — | @@ -689,7 +774,14 @@ |
690 | 775 | ); |
691 | 776 | } |
692 | 777 | } |
693 | | - |
| 778 | + |
| 779 | + /** |
| 780 | + * This is a generic function to add more parameters that don't need special |
| 781 | + * treatment to their correct locations. |
| 782 | + * |
| 783 | + * @param $name Name of the parameter. |
| 784 | + * @param $value The value to be inserted. |
| 785 | + */ |
694 | 786 | private function addOtherStringValue ( $name, $value ) { |
695 | 787 | switch ( $name[0] ) { |
696 | 788 | case 'url': |
— | — | @@ -722,6 +814,9 @@ |
723 | 815 | case 'publisher': |
724 | 816 | $this->dPublisher = $value; |
725 | 817 | break; |
| 818 | + case 'coauthors': |
| 819 | + $this->dCoAuthors = $value; |
| 820 | + break; |
726 | 821 | } |
727 | 822 | } |
728 | 823 | |
— | — | @@ -747,9 +842,6 @@ |
748 | 843 | case 'authorlink': |
749 | 844 | $this->addAuthorLink( $name, $value ); |
750 | 845 | break; |
751 | | - case 'coauthors': |
752 | | - $this->addCoAuthors( $name, $value ); |
753 | | - break; |
754 | 846 | case 'editor': |
755 | 847 | $this->addEditor( $name, $value ); |
756 | 848 | break; |
— | — | @@ -762,6 +854,7 @@ |
763 | 855 | case 'editorlink': |
764 | 856 | $this->addEditorLink( $name, $value ); |
765 | 857 | break; |
| 858 | + case 'coauthors': |
766 | 859 | case 'url': |
767 | 860 | case 'title': |
768 | 861 | case 'pmc': |
— | — | @@ -783,6 +876,15 @@ |
784 | 877 | return true; |
785 | 878 | } |
786 | 879 | |
| 880 | + /** |
| 881 | + * This function handles the first item of the variable. For {{#citation:}} |
| 882 | + * the first item defines the type of the citation; which is important the |
| 883 | + * rendering of the function. |
| 884 | + * |
| 885 | + * Right now only 'news' is an acceptable citation type. |
| 886 | + * |
| 887 | + * @param $item The raw item. |
| 888 | + */ |
787 | 889 | protected function handlePrimaryItem( $item ) { |
788 | 890 | if ( in_array ( $item, array ( 'news' ) ) ) |
789 | 891 | $this->citeType = $item; |