Original: https://www.mediawiki.org/wiki/Extension:Comments Das hier ist eine an https://znil.net angepasste Version.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

znilListAllComments.php 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * Comments of the Day parser hook -- shows the five newest comments that have
  4. * been sent within the last 24 hours.
  5. *
  6. * @file
  7. * @ingroup Extensions
  8. * @date 5 August 2011
  9. */
  10. if ( !defined( 'MEDIAWIKI' ) ) {
  11. die();
  12. }
  13. $wgHooks['ParserFirstCallInit'][] = 'wfCommentsListAll';
  14. /**
  15. * Register the new <commentsAll /> parser hook with the Parser.
  16. *
  17. * @param $parser Parser: instance of Parser (not necessarily $wgParser)
  18. * @return Boolean: true
  19. */
  20. function wfCommentsListAll( &$parser ) {
  21. $parser->setHook( 'commentsAll', 'getcommentsAll' );
  22. return true;
  23. }
  24. /**
  25. * Get comments all --
  26. *
  27. * @return String: HTML
  28. */
  29. function getcommentsAll( $input, $args, $parser ) {
  30. global $wgMemc, $wgUploadPath;
  31. $oneDay = 60 * 60 * 24 * 50000;
  32. // Try memcached first
  33. $key = wfMemcKey( 'comments-all', 'standalone-hook' );
  34. $data = $wgMemc->get( $key );
  35. if( $data ) { // success, got it from memcached!
  36. $commentsAll = $data;
  37. //$dbr = wfGetDB( DB_SLAVE );
  38. } elseif ( !$data || $args['nocache'] ) { // just query the DB
  39. $dbr = wfGetDB( DB_SLAVE );
  40. $res = $dbr->select(
  41. array( 'Comments', 'page' ),
  42. array(
  43. 'Comment_Username', 'comment_ip', 'comment_text',
  44. 'comment_date', 'Comment_user_id', 'CommentID',
  45. 'IFNULL(Comment_Plus_Count - Comment_Minus_Count,0) AS Comment_Score',
  46. 'Comment_Plus_Count AS CommentVotePlus',
  47. 'Comment_Minus_Count AS CommentVoteMinus',
  48. 'Comment_Parent_ID', 'page_title', 'page_namespace'
  49. ),
  50. array(
  51. 'comment_page_id = page_id',
  52. 'UNIX_TIMESTAMP(comment_date) > ' . ( time() - ( $oneDay ) )
  53. ),
  54. __METHOD__,
  55. array( 'ORDER BY' => '(comment_date) DESC')
  56. );
  57. $commentsAll = array();
  58. foreach ( $res as $row ) {
  59. $commentsAll[] = array(
  60. 'username' => $row->Comment_Username,
  61. 'userid' => $row->Comment_user_id,
  62. 'score' => $row->CommentVotePlus,
  63. 'text' => $row->comment_text,
  64. 'id' => $row->CommentID,
  65. 'pagens' => $row->page_namespace,
  66. 'pagetitle' => $row->page_title,
  67. 'date' => $row->comment_date
  68. );
  69. }
  70. $wgMemc->set( $key, $commentsAll, $oneDay );
  71. }
  72. $comments = '';
  73. foreach ( $commentsAll as $commentsAllTemp ) {
  74. $title2 = Title::makeTitle(
  75. $commentsAllTemp['pagens'],
  76. $commentsAllTemp['pagetitle']
  77. );
  78. if( $commentsAllTemp['userid'] != 0 ) {
  79. $title = Title::makeTitle( NS_USER, $commentsAllTemp['username'] );
  80. $commentPoster_Display = $commentsAllTemp['username'];
  81. $commentPoster = '<a href="' . $title->getFullURL() .
  82. '" title="' . $title->getText() . '" rel="nofollow">' .
  83. $commentsAllTemp['username'] . '</a>';
  84. //avatar = new wAvatar( $commentsAllTemp['userid'], 's' );
  85. $commentIcon = 'extensions/Comments/images/default_s.gif';
  86. } else {
  87. $title = Title::makeTitle( NS_USER, $commentsAllTemp['username'] );
  88. $commentPoster_Display = $commentsAllTemp['username'];
  89. $commentPoster = '<a href="' . $title->getFullURL() .
  90. '" title="' . $title->getText() . '" rel="nofollow">' .
  91. $commentsAllTemp['username'] . '</a>';
  92. //avatar = new wAvatar( $commentsAllTemp['userid'], 's' );
  93. $commentIcon = 'extensions/Comments/resources/images/default_s.gif';
  94. if ( filter_var($commentPoster_Display, FILTER_VALIDATE_IP) !== false ){
  95. // Wert ist eine IP-Adresse
  96. $commentPoster = "Anonym";
  97. }
  98. /*
  99. $commentPoster_Display = wfMsg( 'comment-anon-name' );
  100. $commentPoster = wfMsg( 'comment-anon-name' );
  101. $commentIcon = '{$IP}/extensions/Comments/images/default_s.gif';
  102. */
  103. }
  104. // $comment_text = substr( $commentsAllTemp['text'], 0, 550 - strlen( $commentPoster_Display ) );
  105. $comment_text = $commentsAllTemp['text'];
  106. if( $comment_text != $commentsAllTemp['text'] ) {
  107. $comment_text .= wfMsg( 'ellipsis' );
  108. }
  109. $comments .= '<div style="width:90%;">';
  110. $comments .= '<div style="float:left;width:220px;">';
  111. $comments .= '<div style="float:left;width:20px;"><img src='. $commentIcon . ' alt="" align="middle" border="0"/></div>';
  112. $comments .= '<div style="float:left;width:100px;"><span style="font-size: 70%">' . $commentsAllTemp['date'] . '</span> - </div>';
  113. $comments .= '<div style="float:left;width:100px;"><span class="cod-poster">' . $commentPoster . ': </span></div></div>';
  114. $comments .= '<div style="float:left;width:60%;">';
  115. $comments .= '<div style="float:left;"><span class="cod-comment"><a href="' .
  116. $title2->getFullURL() . '#comment-' . $commentsAllTemp['id'] .
  117. '" title="' . $title2->getText() . '">' . '<span>' . $comment_text . '</span></a></div>';
  118. $comments .= '</div><div style="clear:both;"></div></div><hr>';
  119. // $comments .= '<div class="cod">';
  120. // $sign = '';
  121. // /*if ( $commentsAllTemp['score'] > 0 ) {
  122. // $sign = '+';
  123. // } elseif ( $commentsAllTemp['score'] < 0 ) {
  124. // $sign = '-'; // this *really* shouldn't be happening...
  125. // }*/
  126. // $comments .= '<div><span class="cod-score">' . $sign .
  127. // '</span> <img src='. $commentIcon .
  128. // '" alt="" align="middle" style="margin-bottom:8px; margin-right: 10px;" border="0"/>
  129. // <span class="cod-poster"><span style="font-size: 70%">' . $commentsAllTemp['date'] . '</span> - ' . $commentPoster . ': </span>';
  130. // $comments .= '<span class="cod-comment"><a href="' .
  131. // $title2->getFullURL() . '#comment-' . $commentsAllTemp['id'] .
  132. // '" title="' . $title2->getText() . '">' . '<span>' . $comment_text . '</span></div>' .
  133. // '</a></span>';
  134. // $comments .= '</div>';
  135. }
  136. $output = '';
  137. if ( !empty( $comments ) ) {
  138. $output .= $comments;
  139. } else {
  140. $output .= wfMsg( 'comments-no-comments-of-day' );
  141. }
  142. return $output;
  143. }