Anonym statt IP anzeigen

master
root 2017-09-27 23:47:28 +02:00
parent cb41f491e8
commit 11d9457338
2 changed files with 181 additions and 177 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

View File

@ -1,177 +1,181 @@
<?php <?php
/** /**
* Comments of the Day parser hook -- shows the five newest comments that have * Comments of the Day parser hook -- shows the five newest comments that have
* been sent within the last 24 hours. * been sent within the last 24 hours.
* *
* @file * @file
* @ingroup Extensions * @ingroup Extensions
* @date 5 August 2011 * @date 5 August 2011
*/ */
if ( !defined( 'MEDIAWIKI' ) ) { if ( !defined( 'MEDIAWIKI' ) ) {
die(); die();
} }
$wgHooks['ParserFirstCallInit'][] = 'wfCommentsListAll'; $wgHooks['ParserFirstCallInit'][] = 'wfCommentsListAll';
/** /**
* Register the new <commentsAll /> parser hook with the Parser. * Register the new <commentsAll /> parser hook with the Parser.
* *
* @param $parser Parser: instance of Parser (not necessarily $wgParser) * @param $parser Parser: instance of Parser (not necessarily $wgParser)
* @return Boolean: true * @return Boolean: true
*/ */
function wfCommentsListAll( &$parser ) { function wfCommentsListAll( &$parser ) {
$parser->setHook( 'commentsAll', 'getcommentsAll' ); $parser->setHook( 'commentsAll', 'getcommentsAll' );
return true; return true;
} }
/** /**
* Get comments all -- * Get comments all --
* *
* @return String: HTML * @return String: HTML
*/ */
function getcommentsAll( $input, $args, $parser ) { function getcommentsAll( $input, $args, $parser ) {
global $wgMemc, $wgUploadPath; global $wgMemc, $wgUploadPath;
$oneDay = 60 * 60 * 24 * 50000; $oneDay = 60 * 60 * 24 * 50000;
// Try memcached first // Try memcached first
$key = wfMemcKey( 'comments-all', 'standalone-hook' ); $key = wfMemcKey( 'comments-all', 'standalone-hook' );
$data = $wgMemc->get( $key ); $data = $wgMemc->get( $key );
if( $data ) { // success, got it from memcached! if( $data ) { // success, got it from memcached!
$commentsAll = $data; $commentsAll = $data;
//$dbr = wfGetDB( DB_SLAVE ); //$dbr = wfGetDB( DB_SLAVE );
} elseif ( !$data || $args['nocache'] ) { // just query the DB } elseif ( !$data || $args['nocache'] ) { // just query the DB
$dbr = wfGetDB( DB_SLAVE ); $dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( $res = $dbr->select(
array( 'Comments', 'page' ), array( 'Comments', 'page' ),
array( array(
'Comment_Username', 'comment_ip', 'comment_text', 'Comment_Username', 'comment_ip', 'comment_text',
'comment_date', 'Comment_user_id', 'CommentID', 'comment_date', 'Comment_user_id', 'CommentID',
'IFNULL(Comment_Plus_Count - Comment_Minus_Count,0) AS Comment_Score', 'IFNULL(Comment_Plus_Count - Comment_Minus_Count,0) AS Comment_Score',
'Comment_Plus_Count AS CommentVotePlus', 'Comment_Plus_Count AS CommentVotePlus',
'Comment_Minus_Count AS CommentVoteMinus', 'Comment_Minus_Count AS CommentVoteMinus',
'Comment_Parent_ID', 'page_title', 'page_namespace' 'Comment_Parent_ID', 'page_title', 'page_namespace'
), ),
array( array(
'comment_page_id = page_id', 'comment_page_id = page_id',
'UNIX_TIMESTAMP(comment_date) > ' . ( time() - ( $oneDay ) ) 'UNIX_TIMESTAMP(comment_date) > ' . ( time() - ( $oneDay ) )
), ),
__METHOD__, __METHOD__,
array( 'ORDER BY' => '(comment_date) DESC') array( 'ORDER BY' => '(comment_date) DESC')
); );
$commentsAll = array(); $commentsAll = array();
foreach ( $res as $row ) { foreach ( $res as $row ) {
$commentsAll[] = array( $commentsAll[] = array(
'username' => $row->Comment_Username, 'username' => $row->Comment_Username,
'userid' => $row->Comment_user_id, 'userid' => $row->Comment_user_id,
'score' => $row->CommentVotePlus, 'score' => $row->CommentVotePlus,
'text' => $row->comment_text, 'text' => $row->comment_text,
'id' => $row->CommentID, 'id' => $row->CommentID,
'pagens' => $row->page_namespace, 'pagens' => $row->page_namespace,
'pagetitle' => $row->page_title, 'pagetitle' => $row->page_title,
'date' => $row->comment_date 'date' => $row->comment_date
); );
} }
$wgMemc->set( $key, $commentsAll, $oneDay ); $wgMemc->set( $key, $commentsAll, $oneDay );
} }
$comments = ''; $comments = '';
foreach ( $commentsAll as $commentsAllTemp ) { foreach ( $commentsAll as $commentsAllTemp ) {
$title2 = Title::makeTitle( $title2 = Title::makeTitle(
$commentsAllTemp['pagens'], $commentsAllTemp['pagens'],
$commentsAllTemp['pagetitle'] $commentsAllTemp['pagetitle']
); );
if( $commentsAllTemp['userid'] != 0 ) { if( $commentsAllTemp['userid'] != 0 ) {
$title = Title::makeTitle( NS_USER, $commentsAllTemp['username'] ); $title = Title::makeTitle( NS_USER, $commentsAllTemp['username'] );
$commentPoster_Display = $commentsAllTemp['username']; $commentPoster_Display = $commentsAllTemp['username'];
$commentPoster = '<a href="' . $title->getFullURL() . $commentPoster = '<a href="' . $title->getFullURL() .
'" title="' . $title->getText() . '" rel="nofollow">' . '" title="' . $title->getText() . '" rel="nofollow">' .
$commentsAllTemp['username'] . '</a>'; $commentsAllTemp['username'] . '</a>';
//avatar = new wAvatar( $commentsAllTemp['userid'], 's' ); //avatar = new wAvatar( $commentsAllTemp['userid'], 's' );
$commentIcon = 'extensions/Comments/images/default_s.gif'; $commentIcon = 'extensions/Comments/images/default_s.gif';
} else { } else {
$title = Title::makeTitle( NS_USER, $commentsAllTemp['username'] ); $title = Title::makeTitle( NS_USER, $commentsAllTemp['username'] );
$commentPoster_Display = $commentsAllTemp['username']; $commentPoster_Display = $commentsAllTemp['username'];
$commentPoster = '<a href="' . $title->getFullURL() . $commentPoster = '<a href="' . $title->getFullURL() .
'" title="' . $title->getText() . '" rel="nofollow">' . '" title="' . $title->getText() . '" rel="nofollow">' .
$commentsAllTemp['username'] . '</a>'; $commentsAllTemp['username'] . '</a>';
//avatar = new wAvatar( $commentsAllTemp['userid'], 's' ); //avatar = new wAvatar( $commentsAllTemp['userid'], 's' );
$commentIcon = 'extensions/Comments/images/default_s.gif'; $commentIcon = 'extensions/Comments/resources/images/default_s.gif';
/* if ( filter_var($commentPoster_Display, FILTER_VALIDATE_IP) !== false ){
$commentPoster_Display = wfMsg( 'comment-anon-name' ); // Wert ist eine IP-Adresse
$commentPoster = wfMsg( 'comment-anon-name' ); $commentPoster = "Anonym";
$commentIcon = '{$IP}/extensions/Comments/images/default_s.gif'; }
*/ /*
} $commentPoster_Display = wfMsg( 'comment-anon-name' );
$commentPoster = wfMsg( 'comment-anon-name' );
// $comment_text = substr( $commentsAllTemp['text'], 0, 550 - strlen( $commentPoster_Display ) ); $commentIcon = '{$IP}/extensions/Comments/images/default_s.gif';
$comment_text = $commentsAllTemp['text']; */
if( $comment_text != $commentsAllTemp['text'] ) { }
$comment_text .= wfMsg( 'ellipsis' );
} // $comment_text = substr( $commentsAllTemp['text'], 0, 550 - strlen( $commentPoster_Display ) );
$comment_text = $commentsAllTemp['text'];
if( $comment_text != $commentsAllTemp['text'] ) {
$comments .= '<div style="width:90%;">'; $comment_text .= wfMsg( 'ellipsis' );
$comments .= '<div style="float:left;width:220px;">'; }
$comments .= '<div style="float:left;width:20px;"><img src='. $commentIcon . ' alt="" align="middle" border="0"/></div>';
$comments .= '<div style="float:left;width:100px;"><span style="font-size: 70%">' . $commentsAllTemp['date'] . '</span> - </div>';
$comments .= '<div style="float:left;width:100px;"><span class="cod-poster">' . $commentPoster . ': </span></div></div>'; $comments .= '<div style="width:90%;">';
$comments .= '<div style="float:left;width:60%;">'; $comments .= '<div style="float:left;width:220px;">';
$comments .= '<div style="float:left;"><span class="cod-comment"><a href="' . $comments .= '<div style="float:left;width:20px;"><img src='. $commentIcon . ' alt="" align="middle" border="0"/></div>';
$title2->getFullURL() . '#comment-' . $commentsAllTemp['id'] . $comments .= '<div style="float:left;width:100px;"><span style="font-size: 70%">' . $commentsAllTemp['date'] . '</span> - </div>';
'" title="' . $title2->getText() . '">' . '<span>' . $comment_text . '</span></a></div>'; $comments .= '<div style="float:left;width:100px;"><span class="cod-poster">' . $commentPoster . ': </span></div></div>';
$comments .= '</div><div style="clear:both;"></div></div><hr>'; $comments .= '<div style="float:left;width:60%;">';
$comments .= '<div style="float:left;"><span class="cod-comment"><a href="' .
// $comments .= '<div class="cod">'; $title2->getFullURL() . '#comment-' . $commentsAllTemp['id'] .
// $sign = ''; '" title="' . $title2->getText() . '">' . '<span>' . $comment_text . '</span></a></div>';
// /*if ( $commentsAllTemp['score'] > 0 ) { $comments .= '</div><div style="clear:both;"></div></div><hr>';
// $sign = '+';
// } elseif ( $commentsAllTemp['score'] < 0 ) { // $comments .= '<div class="cod">';
// $sign = '-'; // this *really* shouldn't be happening... // $sign = '';
// }*/ // /*if ( $commentsAllTemp['score'] > 0 ) {
// $comments .= '<div><span class="cod-score">' . $sign . // $sign = '+';
// '</span> <img src='. $commentIcon . // } elseif ( $commentsAllTemp['score'] < 0 ) {
// '" alt="" align="middle" style="margin-bottom:8px; margin-right: 10px;" border="0"/> // $sign = '-'; // this *really* shouldn't be happening...
// <span class="cod-poster"><span style="font-size: 70%">' . $commentsAllTemp['date'] . '</span> - ' . $commentPoster . ': </span>'; // }*/
// $comments .= '<span class="cod-comment"><a href="' . // $comments .= '<div><span class="cod-score">' . $sign .
// $title2->getFullURL() . '#comment-' . $commentsAllTemp['id'] . // '</span> <img src='. $commentIcon .
// '" title="' . $title2->getText() . '">' . '<span>' . $comment_text . '</span></div>' . // '" alt="" align="middle" style="margin-bottom:8px; margin-right: 10px;" border="0"/>
// '</a></span>'; // <span class="cod-poster"><span style="font-size: 70%">' . $commentsAllTemp['date'] . '</span> - ' . $commentPoster . ': </span>';
// $comments .= '</div>'; // $comments .= '<span class="cod-comment"><a href="' .
} // $title2->getFullURL() . '#comment-' . $commentsAllTemp['id'] .
// '" title="' . $title2->getText() . '">' . '<span>' . $comment_text . '</span></div>' .
$output = ''; // '</a></span>';
if ( !empty( $comments ) ) { // $comments .= '</div>';
$output .= $comments; }
} else {
$output .= wfMsg( 'comments-no-comments-of-day' ); $output = '';
} if ( !empty( $comments ) ) {
$output .= $comments;
return $output; } else {
} $output .= wfMsg( 'comments-no-comments-of-day' );
}
return $output;
}