You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.1 KiB

  1. <?php
  2. /**
  3. * Refbase entry renderer using citation templates (cite_journal only for now)
  4. */
  5. class RefbaseRendererCitationTemplate extends RefbaseRenderer {
  6. /**
  7. * Constructor (simply inherit from parent)
  8. */
  9. public function __construct() {
  10. parent::__construct();
  11. }
  12. /**
  13. * List fields required to build template
  14. */
  15. public function getFieldList() {
  16. return array( 'type',
  17. 'serial',
  18. 'author',
  19. 'year',
  20. 'title',
  21. 'language',
  22. 'publication',
  23. 'volume',
  24. 'issue',
  25. 'pages',
  26. 'place',
  27. 'publisher',
  28. 'issn',
  29. 'doi' );
  30. }
  31. /**
  32. * Prepare text for template (supports journal articles only)
  33. */
  34. public function render( $entry, & $cite, $options ) {
  35. $cite = "";
  36. $ret = true;
  37. if ( $entry["type"] == "Journal Article" ) {
  38. $cite .= "{{cite_journal|url=" . $this->refbaseURL . "show.php?";
  39. $cite .= "record=" . $entry['serial'];
  40. if( !empty( $entry["author"] ) ) {
  41. $author = $entry["author"];
  42. $aulast = RefbaseTools::extractAuthorsLastName
  43. ( " *; *", " *, *", 1, $author );
  44. $aufirst = RefbaseTools::extractAuthorsGivenName
  45. ( " *; *", " *, *", 1, $author );
  46. if( !empty( $aulast ) ) {
  47. $cite .= "|last=" . $aulast;
  48. }
  49. if( !empty( $aufirst ) ) {
  50. $cite .= "|first=" . $aufirst;
  51. if( !empty( $aulast ) ) {
  52. $cite .= "|authorlink=$aufirst $aulast";
  53. }
  54. }
  55. $authorcount = count( preg_split( "/ *; */", $author ) );
  56. $au = "";
  57. for ( $i=0; $i < $authorcount - 1; $i++ ) {
  58. $aul = RefbaseTools::extractAuthorsLastName
  59. ( " *; *", " *, *", $i + 2, $author );
  60. $auf = RefbaseTools::extractAuthorsGivenName
  61. ( " *; *", " *, *", $i + 2, $author );
  62. if ( !empty( $aul ) ) {
  63. if ( !empty( $auf ) ) {
  64. $au .= "[[$auf $aul|$aul, $auf]]; ";
  65. }
  66. }
  67. }
  68. if ( !empty( $au ) ) {
  69. $cite .= "|coauthors=" . trim( $au, '; ' );
  70. }
  71. }
  72. if( !empty( $entry["year"] ) ) {
  73. $cite .= "|year=" . $entry['year'];
  74. }
  75. if( !empty( $entry["title"] ) ) {
  76. $title = RefbaseTools::searchReplaceText( $entry['title'],
  77. true );
  78. $cite .= "|title=" . $title;
  79. }
  80. if( !empty( $entry["language"] ) )
  81. $cite .= "|language=" . $entry['language'];
  82. if( !empty( $entry["publication"] ) )
  83. $cite .= "|journal=" . $entry['publication'];
  84. if( !empty( $entry["volume"] ) )
  85. $cite .= "|volume=" . $entry['volume'];
  86. if( !empty( $entry["issue"] ) )
  87. $cite .= "|issue=" . $entry['issue'];
  88. if( !empty( $entry["pages"] ) )
  89. $cite .= "|pages=" . $entry['pages'];
  90. if( !empty( $entry["place"] ) )
  91. $cite .= "|location=" . $entry['place'];
  92. if( !empty( $entry["publiser"] ) )
  93. $cite .= "|publisher=" . $entry['publisher'];
  94. if( !empty( $entry["issn"] ) )
  95. $cite .= "|issn=" . $entry['issn'];
  96. if( !empty( $entry["doi"] ) )
  97. $cite .= "|doi=" . $entry['doi'];
  98. $cite .= "}}";
  99. $ret &= true;
  100. } else {
  101. $cite .= wfMessage( 'refbase-error-cite_journal-type' )->text();
  102. $ret &= false;
  103. }
  104. return $ret;
  105. }
  106. }