r86413 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86412‎ | r86413 | r86414 >
Date:16:40, 19 April 2011
Author:svip
Status:deferred
Tags:
Comment:
Follow up to r86340 and 86344: Cleaned up variables, etc. and added comments to all functions in Citation.php
Modified paths:
  • /trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.magic.php (modified) (history)
  • /trunk/extensions/TemplateAdventures/TemplateAdventures.php (modified) (history)
  • /trunk/extensions/TemplateAdventures/Templates/Citation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.magic.php
@@ -4,7 +4,7 @@
55
66 $magicWords['en'] = array(
77 # citation magic words
8 - 'citation' => array( 1, 'citation' ),
 8+ 'ta_citation' => array( 1, 'citation' ),
99 'ta_cc_author' => array( 0, 'author' ),
1010 'ta_cc_authorsurname' => array( 0, 'surname', 'last' ),
1111 'ta_cc_authorgiven' => array( 0, 'given', 'first' ),
Index: trunk/extensions/TemplateAdventures/TemplateAdventures.php
@@ -60,7 +60,7 @@
6161
6262 public static function onParserFirstCallInit( $parser ) {
6363 $parser->setFunctionHook(
64 - 'citation',
 64+ 'ta_citation',
6565 array( __CLASS__, 'citation' ),
6666 SFH_OBJECT_ARGS
6767 );
Index: trunk/extensions/TemplateAdventures/Templates/Citation.php
@@ -98,6 +98,8 @@
9999
100100 /**
101101 * Render the data after the data have been read.
 102+ *
 103+ * TODO: Clean this baby up, probably be assigning some help functions.
102104 */
103105 public function render() {
104106 # boolean variables to keep track of output
@@ -517,6 +519,13 @@
518520 return wfMsg ( 'ta-citeprintonlyspan', $string );
519521 }
520522
 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+ */
521530 private function addNotNull ( $check, $add ) {
522531 if ( $this->notNull ( $check ) )
523532 return $add;
@@ -578,15 +587,28 @@
579588 }
580589 return $area;
581590 }
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+ */
583599 private function makeLink ( $url, $title ) {
584600 if ( !$url )
585601 return $title;
586602 return "[$url $title]";
587603 }
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+ */
589611 private function notNull ( $check ) {
590 - return !( $check == null && $check == '' );
 612+ return !( $check == null && $check === '' );
591613 }
592614
593615 /**
@@ -623,55 +645,118 @@
624646 }
625647 $this->dAuthors = $tmpAuthors;
626648 }
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+ */
628660 private function addEditorLink( $name, $value ) {
629661 if ( $name[1] == null )
630662 return;
631663 $this->dEditorLinks[$name[1]] = $value;
632664 }
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+ */
634672 private function addEditor( $name, $value ) {
635673 $this->appendEditorData ( $name[1], $value );
636674 }
637675
 676+ /**
 677+ * Adds surname.
 678+ *
 679+ * @param $name Editor-reference.
 680+ * @param $value Surname
 681+ */
638682 private function addEditorSurname( $name, $value ) {
639683 $this->appendEditorData ( $name[1], array ( null, $value ) );
640684 }
641685
 686+ /**
 687+ * Adds first name.
 688+ *
 689+ * @param $name Editor-reference.
 690+ * @param $value Given name
 691+ */
642692 private function addEditorGivenName ( $name, $value ) {
643693 $this->appendEditorData ( $name[1], array ( $value, null ) );
644694 }
645 -
 695+
 696+ /**
 697+ * Appends the editor to the editor array.
 698+ *
 699+ * @param $num Editor-reference.
 700+ * @param $name Details
 701+ */
646702 private function appendEditorData( $num, $name ) {
647703 $this->appendWriterData( $this->dEditors, $num, $name );
648704 }
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+ */
650715 private function addAuthorLink( $name, $value ) {
651716 if ( $name[1] == null )
652717 return;
653718 $this->dAuthorLinks[$name[1]] = $value;
654719 }
655720
 721+ /**
 722+ * @param $name Author-reference
 723+ * @param $value Full name
 724+ */
656725 private function addAuthor( $name, $value ) {
657726 $this->appendAuthorData ( $name[1], $value );
658727 }
659 -
 728+
 729+ /**
 730+ * @param $name Author-reference
 731+ * @param $value Surname
 732+ */
660733 private function addAuthorSurname( $name, $value ) {
661734 $this->appendAuthorData ( $name[1], array ( null, $value ) );
662735 }
663 -
 736+
 737+ /**
 738+ * @param $name Author-reference
 739+ * @param $value Given name
 740+ */
664741 private function addAuthorGivenName ( $name, $value ) {
665742 $this->appendAuthorData ( $name[1], array ( $value, null ) );
666743 }
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+ */
672749 private function appendAuthorData( $num, $name ) {
673750 $this->appendWriterData( $this->dAuthors, $num, $name );
674751 }
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+ */
676761 private function appendWriterData( &$array, $num, $name ) {
677762 $split = is_array( $name );
678763 if ( $num == null )
@@ -689,7 +774,14 @@
690775 );
691776 }
692777 }
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+ */
694786 private function addOtherStringValue ( $name, $value ) {
695787 switch ( $name[0] ) {
696788 case 'url':
@@ -722,6 +814,9 @@
723815 case 'publisher':
724816 $this->dPublisher = $value;
725817 break;
 818+ case 'coauthors':
 819+ $this->dCoAuthors = $value;
 820+ break;
726821 }
727822 }
728823
@@ -747,9 +842,6 @@
748843 case 'authorlink':
749844 $this->addAuthorLink( $name, $value );
750845 break;
751 - case 'coauthors':
752 - $this->addCoAuthors( $name, $value );
753 - break;
754846 case 'editor':
755847 $this->addEditor( $name, $value );
756848 break;
@@ -762,6 +854,7 @@
763855 case 'editorlink':
764856 $this->addEditorLink( $name, $value );
765857 break;
 858+ case 'coauthors':
766859 case 'url':
767860 case 'title':
768861 case 'pmc':
@@ -783,6 +876,15 @@
784877 return true;
785878 }
786879
 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+ */
787889 protected function handlePrimaryItem( $item ) {
788890 if ( in_array ( $item, array ( 'news' ) ) )
789891 $this->citeType = $item;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86340Added support for 'citation types' among other things.svip20:21, 18 April 2011

Status & tagging log