neue Version für Mediawiki ab Version 1.32
This commit is contained in:
		@@ -1,5 +0,0 @@
 | 
			
		||||
## Default .htaccess file
 | 
			
		||||
# Displaying PHP errors
 | 
			
		||||
php_flag display_errors on
 | 
			
		||||
php_value error_reporting 6143
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
use MediaWiki\MediaWikiServices;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Comment class
 | 
			
		||||
 * Functions for managing comments and everything related to them, including:
 | 
			
		||||
@@ -27,11 +30,6 @@ class Comment extends ContextSource {
 | 
			
		||||
	 */
 | 
			
		||||
	public $text = null;
 | 
			
		||||
 | 
			
		||||
	/* START Anpassung znilwiki */
 | 
			
		||||
	public $CommentUsernameKOK = null; /* 25.10.2013 von Kai-Ole Kirsten */
 | 
			
		||||
    public $UsernameKOK = null; /* 25.10.2013 von Kai-Ole Kirsten */
 | 
			
		||||
	/* ENDE Anpassung znilwiki */
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Date when the comment was posted
 | 
			
		||||
	 *
 | 
			
		||||
@@ -84,7 +82,8 @@ class Comment extends ContextSource {
 | 
			
		||||
	public $userID = 0;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @TODO document
 | 
			
		||||
	 * The amount of points the user has; fetched from the user_stats table if
 | 
			
		||||
	 * SocialProfile is installed, otherwise this remains 0
 | 
			
		||||
	 *
 | 
			
		||||
	 * @var int
 | 
			
		||||
	 */
 | 
			
		||||
@@ -112,9 +111,9 @@ class Comment extends ContextSource {
 | 
			
		||||
	/**
 | 
			
		||||
	 * Constructor - set the page ID
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param $page CommentsPage: ID number of the current page
 | 
			
		||||
	 * @param IContextSource $context
 | 
			
		||||
	 * @param $data: straight from the DB about the comment
 | 
			
		||||
	 * @param CommentsPage $page ID number of the current page
 | 
			
		||||
	 * @param IContextSource|null $context
 | 
			
		||||
	 * @param array $data Straight from the DB about the comment
 | 
			
		||||
	 */
 | 
			
		||||
	public function __construct( CommentsPage $page, $context = null, $data ) {
 | 
			
		||||
		$this->page = $page;
 | 
			
		||||
@@ -125,24 +124,24 @@ class Comment extends ContextSource {
 | 
			
		||||
		$this->ip = $data['Comment_IP'];
 | 
			
		||||
		$this->text = $data['Comment_Text'];
 | 
			
		||||
		$this->date = $data['Comment_Date'];
 | 
			
		||||
		$this->userID = $data['Comment_user_id'];
 | 
			
		||||
		$this->userID = (int)$data['Comment_user_id'];
 | 
			
		||||
		$this->userPoints = $data['Comment_user_points'];
 | 
			
		||||
		$this->id = $data['CommentID'];
 | 
			
		||||
		$this->parentID = $data['Comment_Parent_ID'];
 | 
			
		||||
		$this->id = (int)$data['CommentID'];
 | 
			
		||||
		$this->parentID = (int)$data['Comment_Parent_ID'];
 | 
			
		||||
		$this->thread = $data['thread'];
 | 
			
		||||
		$this->timestamp = $data['timestamp'];
 | 
			
		||||
 | 
			
		||||
		if ( isset( $data['current_vote'] ) ) {
 | 
			
		||||
			$vote = $data['current_vote'];
 | 
			
		||||
		} else {
 | 
			
		||||
			$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
			$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
			$row = $dbr->selectRow(
 | 
			
		||||
				'Comments_Vote',
 | 
			
		||||
				array( 'Comment_Vote_Score' ),
 | 
			
		||||
				array(
 | 
			
		||||
				[ 'Comment_Vote_Score' ],
 | 
			
		||||
				[
 | 
			
		||||
					'Comment_Vote_ID' => $this->id,
 | 
			
		||||
					'Comment_Vote_Username' => $this->getUser()->getName()
 | 
			
		||||
				),
 | 
			
		||||
				],
 | 
			
		||||
				__METHOD__
 | 
			
		||||
			);
 | 
			
		||||
			if ( $row !== false ) {
 | 
			
		||||
@@ -160,24 +159,24 @@ class Comment extends ContextSource {
 | 
			
		||||
 | 
			
		||||
	public static function newFromID( $id ) {
 | 
			
		||||
		$context = RequestContext::getMain();
 | 
			
		||||
		$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
		$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
 | 
			
		||||
		if ( !is_numeric( $id ) || $id == 0 ) {
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$tables = array();
 | 
			
		||||
		$params = array();
 | 
			
		||||
		$joinConds = array();
 | 
			
		||||
		$tables = [];
 | 
			
		||||
		$params = [];
 | 
			
		||||
		$joinConds = [];
 | 
			
		||||
 | 
			
		||||
		// Defaults (for non-social wikis)
 | 
			
		||||
		$tables[] = 'Comments';
 | 
			
		||||
		$fields = array(
 | 
			
		||||
		$fields = [
 | 
			
		||||
			'Comment_Username', 'Comment_IP', 'Comment_Text',
 | 
			
		||||
			'Comment_Date', 'Comment_Date AS timestamp',
 | 
			
		||||
			'Comment_user_id', 'CommentID', 'Comment_Parent_ID',
 | 
			
		||||
			'CommentID', 'Comment_Page_ID'
 | 
			
		||||
		);
 | 
			
		||||
		];
 | 
			
		||||
 | 
			
		||||
		// If SocialProfile is installed, query the user_stats table too.
 | 
			
		||||
		if (
 | 
			
		||||
@@ -186,18 +185,18 @@ class Comment extends ContextSource {
 | 
			
		||||
		) {
 | 
			
		||||
			$tables[] = 'user_stats';
 | 
			
		||||
			$fields[] = 'stats_total_points';
 | 
			
		||||
			$joinConds = array(
 | 
			
		||||
				'Comments' => array(
 | 
			
		||||
			$joinConds = [
 | 
			
		||||
				'Comments' => [
 | 
			
		||||
					'LEFT JOIN', 'Comment_user_id = stats_user_id'
 | 
			
		||||
				)
 | 
			
		||||
			);
 | 
			
		||||
				]
 | 
			
		||||
			];
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Perform the query
 | 
			
		||||
		$res = $dbr->select(
 | 
			
		||||
			$tables,
 | 
			
		||||
			$fields,
 | 
			
		||||
			array( 'CommentID' => $id ),
 | 
			
		||||
			[ 'CommentID' => $id ],
 | 
			
		||||
			__METHOD__,
 | 
			
		||||
			$params,
 | 
			
		||||
			$joinConds
 | 
			
		||||
@@ -210,7 +209,7 @@ class Comment extends ContextSource {
 | 
			
		||||
		} else {
 | 
			
		||||
			$thread = $row->Comment_Parent_ID;
 | 
			
		||||
		}
 | 
			
		||||
		$data = array(
 | 
			
		||||
		$data = [
 | 
			
		||||
			'Comment_Username' => $row->Comment_Username,
 | 
			
		||||
			'Comment_IP' => $row->Comment_IP,
 | 
			
		||||
			'Comment_Text' => $row->Comment_Text,
 | 
			
		||||
@@ -221,13 +220,23 @@ class Comment extends ContextSource {
 | 
			
		||||
			'Comment_Parent_ID' => $row->Comment_Parent_ID,
 | 
			
		||||
			'thread' => $thread,
 | 
			
		||||
			'timestamp' => wfTimestamp( TS_UNIX, $row->timestamp )
 | 
			
		||||
		);
 | 
			
		||||
		];
 | 
			
		||||
 | 
			
		||||
		$page = new CommentsPage( $row->Comment_Page_ID, $context );
 | 
			
		||||
 | 
			
		||||
		return new Comment( $page, $context, $data );
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Is the given User the owner (author) of this comment?
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param User $user
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	public function isOwner( User $user ) {
 | 
			
		||||
		return ( $this->username === $user->getName() && $this->userID === $user->getId() );
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Parse and return the text for this comment
 | 
			
		||||
	 *
 | 
			
		||||
@@ -235,7 +244,7 @@ class Comment extends ContextSource {
 | 
			
		||||
	 * @throws MWException
 | 
			
		||||
	 */
 | 
			
		||||
	function getText() {
 | 
			
		||||
		global $wgParser;
 | 
			
		||||
		$parser = MediaWikiServices::getInstance()->getParser();
 | 
			
		||||
 | 
			
		||||
		$commentText = trim( str_replace( '"', "'", $this->text ) );
 | 
			
		||||
		$comment_text_parts = explode( "\n", $commentText );
 | 
			
		||||
@@ -245,25 +254,25 @@ class Comment extends ContextSource {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if ( $this->getTitle()->getArticleID() > 0 ) {
 | 
			
		||||
			$commentText = $wgParser->recursiveTagParse( $comment_text_fix );
 | 
			
		||||
			$commentText = $parser->recursiveTagParse( $comment_text_fix );
 | 
			
		||||
		} else {
 | 
			
		||||
			$commentText = $this->getOutput()->parse( $comment_text_fix );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// really bad hack because we want to parse=firstline, but don't want wrapping <p> tags
 | 
			
		||||
		if ( substr( $commentText, 0 , 3 ) == '<p>' ) {
 | 
			
		||||
		if ( substr( $commentText, 0, 3 ) == '<p>' ) {
 | 
			
		||||
			$commentText = substr( $commentText, 3 );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if ( substr( $commentText, strlen( $commentText ) -4 , 4 ) == '</p>' ) {
 | 
			
		||||
			$commentText = substr( $commentText, 0, strlen( $commentText ) -4 );
 | 
			
		||||
		if ( substr( $commentText, strlen( $commentText ) - 4, 4 ) == '</p>' ) {
 | 
			
		||||
			$commentText = substr( $commentText, 0, strlen( $commentText ) - 4 );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// make sure link text is not too long (will overflow)
 | 
			
		||||
		// this function changes too long links to <a href=#>http://www.abc....xyz.html</a>
 | 
			
		||||
		$commentText = preg_replace_callback(
 | 
			
		||||
			"/(<a[^>]*>)(.*?)(<\/a>)/i",
 | 
			
		||||
			array( 'CommentFunctions', 'cutCommentLinkText' ),
 | 
			
		||||
			[ 'CommentFunctions', 'cutCommentLinkText' ],
 | 
			
		||||
			$commentText
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
@@ -274,62 +283,48 @@ class Comment extends ContextSource {
 | 
			
		||||
	 * Adds the comment and all necessary info into the Comments table in the
 | 
			
		||||
	 * database.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param string $text: text of the comment
 | 
			
		||||
	 * @param CommentsPage $page: container page
 | 
			
		||||
	 * @param User $user: user commenting
 | 
			
		||||
	 * @param int $parentID: ID of parent comment, if this is a reply
 | 
			
		||||
	 * @param string $text text of the comment
 | 
			
		||||
	 * @param CommentsPage $page container page
 | 
			
		||||
	 * @param User $user user commenting
 | 
			
		||||
	 * @param int $parentID ID of parent comment, if this is a reply
 | 
			
		||||
	 *
 | 
			
		||||
	 * @return Comment: the added comment
 | 
			
		||||
	 * @return Comment the added comment
 | 
			
		||||
	 */
 | 
			
		||||
	static function add( $text, CommentsPage $page, User $user, $parentID ) {
 | 
			
		||||
		global $wgCommentsInRecentChanges;
 | 
			
		||||
		$dbw = wfGetDB( DB_MASTER );
 | 
			
		||||
		$context = RequestContext::getMain();
 | 
			
		||||
 | 
			
		||||
		wfSuppressWarnings();
 | 
			
		||||
		Wikimedia\suppressWarnings();
 | 
			
		||||
		$commentDate = date( 'Y-m-d H:i:s' );
 | 
			
		||||
		wfRestoreWarnings();
 | 
			
		||||
        // ##START## 2017-09-27 von Bernhard Linz
 | 
			
		||||
//		if ( $this->getUser()->isLoggedIn() ) {
 | 
			
		||||
//            $kok_username = $user->getName();
 | 
			
		||||
//            $kok_username = $this->UsernameKOK;
 | 
			
		||||
//		} else {
 | 
			
		||||
            $kok_username = preg_match('/(?<=#START#).*?(?=#ENDE#)/s', $text, $result);
 | 
			
		||||
            $kok_username = $result[0];
 | 
			
		||||
            $text = str_replace('#START#' . $result[0] . '#ENDE#', '', $text);
 | 
			
		||||
//			$kok_username = str_replace('#START#', '', $kok_username);
 | 
			
		||||
//			$kok_username = str_replace('#ENDE#', '', $kok_username);
 | 
			
		||||
            if ( $kok_username == "" ) {
 | 
			
		||||
                 $kok_username = $user->getName();
 | 
			
		||||
            }
 | 
			
		||||
            if ( $kok_username == "none" ) {
 | 
			
		||||
                 $kok_username = $user->getName();
 | 
			
		||||
            }
 | 
			
		||||
//			$kok_username = preg_replace('/<.*>/i', '', $kok_username);
 | 
			
		||||
//			$kok_username = preg_replace('/[^A-Za-z0-9. \-\@]/i', '', $kok_username);
 | 
			
		||||
//			$kok_username = str_replace("1'1", '', $kok_username);
 | 
			
		||||
//			$kok_username = str_replace('USER_NAME', '', $kok_username);
 | 
			
		||||
//			$kok_username = str_replace('DESC', '', $kok_username);
 | 
			
		||||
//			$kok_username = str_replace('(*)', '', $kok_username);
 | 
			
		||||
//			$kok_username = str_replace('EXEC', '', $kok_username); */
 | 
			
		||||
  //		}
 | 
			
		||||
        // ##ENDE## 2017-09-27 von Bernhard Linz
 | 
			
		||||
		Wikimedia\restoreWarnings();
 | 
			
		||||
// ## START ## 25.05.2019 von Bernhard Linz ###################################################################################################
 | 
			
		||||
        $kok_username = preg_match('/(?<=#START#).*?(?=#ENDE#)/s', $text, $result);
 | 
			
		||||
        $kok_username = $result[0];
 | 
			
		||||
        $text = str_replace('#START#' . $result[0] . '#ENDE#', '', $text);
 | 
			
		||||
        if ( $kok_username == "" ) {
 | 
			
		||||
            $kok_username = $user->getName();
 | 
			
		||||
        }
 | 
			
		||||
        if ( $kok_username == "none" ) {
 | 
			
		||||
            $kok_username = $user->getName();
 | 
			
		||||
        }
 | 
			
		||||
// ## ENDE ## 25.05.2019 von Bernhard Linz ###################################################################################################
 | 
			
		||||
		$dbw->insert(
 | 
			
		||||
			'Comments',
 | 
			
		||||
			array(
 | 
			
		||||
			[
 | 
			
		||||
				'Comment_Page_ID' => $page->id,
 | 
			
		||||
// ## START ## 25.05.2019 von Bernhard Linz ###################################################################################################
 | 
			
		||||
				//'Comment_Username' => $user->getName(),
 | 
			
		||||
                'Comment_Username' => $kok_username,
 | 
			
		||||
// ## ENDE ## 25.05.2019 von Bernhard Linz ###################################################################################################
 | 
			
		||||
				'Comment_user_id' => $user->getId(),
 | 
			
		||||
				'Comment_Text' => $text,
 | 
			
		||||
				'Comment_Date' => $commentDate,
 | 
			
		||||
				'Comment_Parent_ID' => $parentID,
 | 
			
		||||
				'Comment_IP' => $_SERVER['REMOTE_ADDR']
 | 
			
		||||
			),
 | 
			
		||||
			],
 | 
			
		||||
			__METHOD__
 | 
			
		||||
		);
 | 
			
		||||
		$commentId = $dbw->insertId();
 | 
			
		||||
		$dbw->commit( __METHOD__ ); // misza: added this
 | 
			
		||||
		$id = $commentId;
 | 
			
		||||
 | 
			
		||||
		$page->clearCommentListCache();
 | 
			
		||||
@@ -337,7 +332,7 @@ class Comment extends ContextSource {
 | 
			
		||||
		// Add a log entry.
 | 
			
		||||
		self::log( 'add', $user, $page->id, $commentId, $text );
 | 
			
		||||
 | 
			
		||||
		$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
		$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
		if (
 | 
			
		||||
			class_exists( 'UserProfile' ) &&
 | 
			
		||||
			$dbr->tableExists( 'user_stats' )
 | 
			
		||||
@@ -345,7 +340,7 @@ class Comment extends ContextSource {
 | 
			
		||||
			$res = $dbr->select( // need this data for seeding a Comment object
 | 
			
		||||
				'user_stats',
 | 
			
		||||
				'stats_total_points',
 | 
			
		||||
				array( 'stats_user_id' => $user->getId() ),
 | 
			
		||||
				[ 'stats_user_id' => $user->getId() ],
 | 
			
		||||
				__METHOD__
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
@@ -360,38 +355,38 @@ class Comment extends ContextSource {
 | 
			
		||||
		} else {
 | 
			
		||||
			$thread = $parentID;
 | 
			
		||||
		}
 | 
			
		||||
		$data = array(
 | 
			
		||||
		$data = [
 | 
			
		||||
			'Comment_Username' => $user->getName(),
 | 
			
		||||
			'Comment_IP' => $context->getRequest()->getIP(),
 | 
			
		||||
			'Comment_Text' => $text,
 | 
			
		||||
			'Comment_Date' => $commentDate,
 | 
			
		||||
			'Comment_user_id' => $user->getID(),
 | 
			
		||||
			'Comment_user_id' => $user->getId(),
 | 
			
		||||
			'Comment_user_points' => $userPoints,
 | 
			
		||||
			'CommentID' => $id,
 | 
			
		||||
			'Comment_Parent_ID' => $parentID,
 | 
			
		||||
			'thread' => $thread,
 | 
			
		||||
			'timestamp' => strtotime( $commentDate )
 | 
			
		||||
		);
 | 
			
		||||
		];
 | 
			
		||||
 | 
			
		||||
		$page = new CommentsPage( $page->id, $context );
 | 
			
		||||
		$comment = new Comment( $page, $context, $data );
 | 
			
		||||
 | 
			
		||||
		Hooks::run( 'Comment::add', array( $comment, $commentId, $comment->page->id ) );
 | 
			
		||||
		/* ## START Kommentar auch per Email versenden ## 11/2014 Bernhard Linz */
 | 
			
		||||
            //$title = Title::makeTitle( NS_USER, $this->username );
 | 
			
		||||
			$znilpageTitle = Title::newFromID( $comment->page->id );
 | 
			
		||||
			$comment_mailto = "root@linz.email";
 | 
			
		||||
			$comment_mailsubject = "Neuer Kommentar von: " . $kok_username . " - IP: " . $_SERVER['REMOTE_ADDR'] . " - DNS: " . gethostbyaddr($_SERVER['REMOTE_ADDR']) ;
 | 
			
		||||
			$comment_mailfrom = "MIME-Version: 1.0\r\n";
 | 
			
		||||
			$comment_mailfrom .= "Content-type: text/html; charset=utf-8\r\n";
 | 
			
		||||
			$comment_mailfrom .= "From: znil.net Kommentare <root@linz.email>\r\n";
 | 
			
		||||
//			$comment_url = $znilpageTitle;
 | 
			
		||||
			$comment_url = "<a href=\"https://znil.net/index.php?title={$znilpageTitle}#comment-{$commentId}\">https://znil.net/index.php?title={$znilpageTitle}#comment-{$commentId}</a>";
 | 
			
		||||
//			$comment_url = "<a href=\"" . $title->getFullURL() . "\">" . $title->getFullURL() . "</a>";
 | 
			
		||||
			$comment_mailtext = $commentDate . "<br><br>" . $comment_url . "<br><br><hr>" . "IP: " . $_SERVER['REMOTE_ADDR'] . "<br>" . "DNS: " . gethostbyaddr($_SERVER['REMOTE_ADDR']) ."<br><br>" . $kok_username . "<br><br>" . $text;
 | 
			
		||||
			$comment_mailtext = nl2br($comment_mailtext);
 | 
			
		||||
			mail($comment_mailto, $comment_mailsubject, $comment_mailtext, $comment_mailfrom);
 | 
			
		||||
		/* ## ENDE Bernhard Linz */
 | 
			
		||||
		Hooks::run( 'Comment::add', [ $comment, $commentId, $comment->page->id ] );
 | 
			
		||||
// ## START ## 25.05.2019 von Bernhard Linz ###################################################################################################
 | 
			
		||||
// Kommentar auch noch einmal per Email versenden (zur Kontrolle)
 | 
			
		||||
        $znilpageTitle = Title::newFromID( $comment->page->id );
 | 
			
		||||
		$comment_mailto = "root@linz.email";
 | 
			
		||||
		$comment_mailsubject = "Neuer Kommentar von: " . $kok_username . " - IP: " . $_SERVER['REMOTE_ADDR'] . " - DNS: " . gethostbyaddr($_SERVER['REMOTE_ADDR']) ;
 | 
			
		||||
		$comment_mailfrom = "MIME-Version: 1.0\r\n";
 | 
			
		||||
		$comment_mailfrom .= "Content-type: text/html; charset=utf-8\r\n";
 | 
			
		||||
		$comment_mailfrom .= "From: znil.net Kommentare <root@linz.email>\r\n";
 | 
			
		||||
//		$comment_url = $znilpageTitle;
 | 
			
		||||
		$comment_url = "<a href=\"https://znil.net/index.php?title={$znilpageTitle}#comment-{$commentId}\">https://znil.net/index.php?title={$znilpageTitle}#comment-{$commentId}</a>";
 | 
			
		||||
//		$comment_url = "<a href=\"" . $title->getFullURL() . "\">" . $title->getFullURL() . "</a>";
 | 
			
		||||
		$comment_mailtext = $commentDate . "<br><br>" . $comment_url . "<br><br><hr>" . "IP: " . $_SERVER['REMOTE_ADDR'] . "<br>" . "DNS: " . gethostbyaddr($_SERVER['REMOTE_ADDR']) ."<br><br>" . $kok_username . "<br><br>" . $text;
 | 
			
		||||
		$comment_mailtext = nl2br($comment_mailtext);
 | 
			
		||||
		mail($comment_mailto, $comment_mailsubject, $comment_mailtext, $comment_mailfrom);
 | 
			
		||||
// ## ENDE ## 25.05.2019 von Bernhard Linz ###################################################################################################
 | 
			
		||||
		return $comment;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -401,11 +396,11 @@ class Comment extends ContextSource {
 | 
			
		||||
	 * @return string
 | 
			
		||||
	 */
 | 
			
		||||
	function getScore() {
 | 
			
		||||
		$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
		$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
		$row = $dbr->selectRow(
 | 
			
		||||
			'Comments_Vote',
 | 
			
		||||
			array( 'SUM(Comment_Vote_Score) AS CommentScore' ),
 | 
			
		||||
			array( 'Comment_Vote_ID' => $this->id ),
 | 
			
		||||
			[ 'SUM(Comment_Vote_Score) AS CommentScore' ],
 | 
			
		||||
			[ 'Comment_Vote_ID' => $this->id ],
 | 
			
		||||
			__METHOD__
 | 
			
		||||
		);
 | 
			
		||||
		$score = '0';
 | 
			
		||||
@@ -415,21 +410,12 @@ class Comment extends ContextSource {
 | 
			
		||||
		return $score;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* START Anpassungen znilwiki */
 | 
			
		||||
	/* ## START ## 25.10.2013 Hinzugefügt von Kai-Ole */
 | 
			
		||||
	function setCommentUsernameKOK( $UsernameKOK ) {
 | 
			
		||||
		$this->CommentUsernameKOK = $UsernameKOK;
 | 
			
		||||
	}
 | 
			
		||||
	/* ## ENDE ## 25.10.2013 Kai-Ole */
 | 
			
		||||
	/* ENDE Anpassungen znilwiki */
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Adds a vote for a comment if the user hasn't voted for said comment yet.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param $value int: upvote or downvote (1 or -1)
 | 
			
		||||
	 * @param int $value Upvote or downvote (1 or -1)
 | 
			
		||||
	 */
 | 
			
		||||
	function vote( $value ) {
 | 
			
		||||
		global $wgMemc;
 | 
			
		||||
		$dbw = wfGetDB( DB_MASTER );
 | 
			
		||||
 | 
			
		||||
		if ( $value < -1 ) { // limit to range -1 -> 0 -> 1
 | 
			
		||||
@@ -442,53 +428,39 @@ class Comment extends ContextSource {
 | 
			
		||||
			$value = 0;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		wfSuppressWarnings();
 | 
			
		||||
		Wikimedia\suppressWarnings();
 | 
			
		||||
		$commentDate = date( 'Y-m-d H:i:s' );
 | 
			
		||||
		wfRestoreWarnings();
 | 
			
		||||
		Wikimedia\restoreWarnings();
 | 
			
		||||
 | 
			
		||||
		if ( $this->currentVote === false ) { // no vote, insert
 | 
			
		||||
			$dbw->insert(
 | 
			
		||||
				'Comments_Vote',
 | 
			
		||||
				array(
 | 
			
		||||
				[
 | 
			
		||||
					'Comment_Vote_id' => $this->id,
 | 
			
		||||
					'Comment_Vote_Username' => $this->getUser()->getName(),
 | 
			
		||||
					'Comment_Vote_user_id' => $this->getUser()->getId(),
 | 
			
		||||
					'Comment_Vote_Score' => $value,
 | 
			
		||||
					'Comment_Vote_Date' => $commentDate,
 | 
			
		||||
					'Comment_Vote_IP' => $_SERVER['REMOTE_ADDR']
 | 
			
		||||
				),
 | 
			
		||||
				],
 | 
			
		||||
				__METHOD__
 | 
			
		||||
			);
 | 
			
		||||
		} else { // already a vote, update
 | 
			
		||||
			$dbw->update(
 | 
			
		||||
				'Comments_Vote',
 | 
			
		||||
				array(
 | 
			
		||||
				[
 | 
			
		||||
					'Comment_Vote_Score' => $value,
 | 
			
		||||
					'Comment_Vote_Date' => $commentDate,
 | 
			
		||||
					'Comment_Vote_IP' => $_SERVER['REMOTE_ADDR']
 | 
			
		||||
				),
 | 
			
		||||
				array(
 | 
			
		||||
				],
 | 
			
		||||
				[
 | 
			
		||||
					'Comment_Vote_id' => $this->id,
 | 
			
		||||
					'Comment_Vote_Username' => $this->getUser()->getName(),
 | 
			
		||||
					'Comment_Vote_user_id' => $this->getUser()->getId(),
 | 
			
		||||
				),
 | 
			
		||||
				],
 | 
			
		||||
				__METHOD__
 | 
			
		||||
			);
 | 
			
		||||
		}
 | 
			
		||||
		$dbw->commit( __METHOD__ );
 | 
			
		||||
 | 
			
		||||
		// update cache for comment list
 | 
			
		||||
		// should perform better than deleting cache completely since Votes happen more frequently
 | 
			
		||||
		$key = wfMemcKey( 'comment', 'pagethreadlist', $this->page->id );
 | 
			
		||||
		$comments = $wgMemc->get( $key );
 | 
			
		||||
		if ( $comments ) {
 | 
			
		||||
			foreach ( $comments as &$comment ) {
 | 
			
		||||
				if ( $comment->id == $this->id ) {
 | 
			
		||||
					$comment->currentScore = $this->currentScore;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			$wgMemc->set( $key, $comments );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$score = $this->getScore();
 | 
			
		||||
 | 
			
		||||
@@ -501,17 +473,18 @@ class Comment extends ContextSource {
 | 
			
		||||
	 */
 | 
			
		||||
	function delete() {
 | 
			
		||||
		$dbw = wfGetDB( DB_MASTER );
 | 
			
		||||
		$dbw->startAtomic( __METHOD__ );
 | 
			
		||||
		$dbw->delete(
 | 
			
		||||
			'Comments',
 | 
			
		||||
			array( 'CommentID' => $this->id ),
 | 
			
		||||
			[ 'CommentID' => $this->id ],
 | 
			
		||||
			__METHOD__
 | 
			
		||||
		);
 | 
			
		||||
		$dbw->delete(
 | 
			
		||||
			'Comments_Vote',
 | 
			
		||||
			array( 'Comment_Vote_ID' => $this->id ),
 | 
			
		||||
			[ 'Comment_Vote_ID' => $this->id ],
 | 
			
		||||
			__METHOD__
 | 
			
		||||
		);
 | 
			
		||||
		$dbw->commit( __METHOD__ );
 | 
			
		||||
		$dbw->endAtomic( __METHOD__ );
 | 
			
		||||
 | 
			
		||||
		// Log the deletion to Special:Log/comments.
 | 
			
		||||
		self::log( 'delete', $this->getUser(), $this->page->id, $this->id );
 | 
			
		||||
@@ -520,7 +493,7 @@ class Comment extends ContextSource {
 | 
			
		||||
		$this->page->clearCommentListCache();
 | 
			
		||||
 | 
			
		||||
		// Ping other extensions that may have hooked into this point (i.e. LinkFilter)
 | 
			
		||||
		Hooks::run( 'Comment::delete', array( $this, $this->id, $this->page->id ) );
 | 
			
		||||
		Hooks::run( 'Comment::delete', [ $this, $this->id, $this->page->id ] );
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -530,7 +503,7 @@ class Comment extends ContextSource {
 | 
			
		||||
	 * @param User $user User who performed the action
 | 
			
		||||
	 * @param int $pageId Page ID of the page that contains the comment thread
 | 
			
		||||
	 * @param int $commentId Comment ID of the affected comment
 | 
			
		||||
	 * @param string $commentText Supplementary log comment, if any
 | 
			
		||||
	 * @param string|null $commentText Supplementary log comment, if any
 | 
			
		||||
	 */
 | 
			
		||||
	static function log( $action, $user, $pageId, $commentId, $commentText = null ) {
 | 
			
		||||
		global $wgCommentsInRecentChanges;
 | 
			
		||||
@@ -540,9 +513,9 @@ class Comment extends ContextSource {
 | 
			
		||||
		if ( $commentText !== null ) {
 | 
			
		||||
			$logEntry->setComment( $commentText );
 | 
			
		||||
		}
 | 
			
		||||
		$logEntry->setParameters( array(
 | 
			
		||||
		$logEntry->setParameters( [
 | 
			
		||||
			'4::commentid' => $commentId
 | 
			
		||||
		) );
 | 
			
		||||
		] );
 | 
			
		||||
		$logId = $logEntry->insert();
 | 
			
		||||
		$logEntry->publish( $logId, ( $wgCommentsInRecentChanges ? 'rcandudp' : 'udp' ) );
 | 
			
		||||
	}
 | 
			
		||||
@@ -571,11 +544,16 @@ class Comment extends ContextSource {
 | 
			
		||||
				'" data-voting="' . $this->page->voting . '" href="javascript:void(0);">';
 | 
			
		||||
		} else {
 | 
			
		||||
			$login = SpecialPage::getTitleFor( 'Userlogin' ); // Anonymous users need to log in before they can vote
 | 
			
		||||
			$returnTo = $this->page->title->getPrefixedDBkey(); // Determine a sane returnto URL parameter
 | 
			
		||||
			$urlParams = [];
 | 
			
		||||
			// @todo FIXME: *when* and *why* is this null?
 | 
			
		||||
			if ( $this->page->title instanceof Title ) {
 | 
			
		||||
				$returnTo = $this->page->title->getPrefixedDBkey(); // Determine a sane returnto URL parameter
 | 
			
		||||
				$urlParams = [ 'returnto' => $returnTo ];
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			$voteLink .=
 | 
			
		||||
				"<a href=\"" .
 | 
			
		||||
				htmlspecialchars( $login->getLocalURL( array( 'returnto' => $returnTo ) ) ) .
 | 
			
		||||
				htmlspecialchars( $login->getLocalURL( $urlParams ) ) .
 | 
			
		||||
				"\" rel=\"nofollow\">";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -600,9 +578,9 @@ class Comment extends ContextSource {
 | 
			
		||||
	/**
 | 
			
		||||
	 * Show the HTML for this comment and ignore section
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param array $blockList list of users the current user has blocked
 | 
			
		||||
	 * @param array $anonList map of ip addresses to names like anon#1, anon#2
 | 
			
		||||
	 * @return string html
 | 
			
		||||
	 * @param array $blockList List of users the current user has blocked
 | 
			
		||||
	 * @param array $anonList Map of IP addresses to names like anon#1, anon#2
 | 
			
		||||
	 * @return string HTML
 | 
			
		||||
	 */
 | 
			
		||||
	function display( $blockList, $anonList ) {
 | 
			
		||||
		if ( $this->parentID == 0 ) {
 | 
			
		||||
@@ -624,62 +602,6 @@ class Comment extends ContextSource {
 | 
			
		||||
		return $output;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function displayForCommentOfTheDay() {
 | 
			
		||||
		$output = '';
 | 
			
		||||
 | 
			
		||||
		$title2 = $this->page->getTitle();
 | 
			
		||||
 | 
			
		||||
		if ( $this->userID != 0 ) {
 | 
			
		||||
			$title = Title::makeTitle( NS_USER, $this->username );
 | 
			
		||||
			$commentPoster_Display = $this->username;
 | 
			
		||||
			$commentPoster = '<a href="' . $title->getFullURL() . '" title="' . $title->getText() . '" rel="nofollow">' . $this->username . '</a>';
 | 
			
		||||
			if ( class_exists( 'wAvatar' ) ) {
 | 
			
		||||
				$avatar = new wAvatar( $this->userID, 's' );
 | 
			
		||||
				$commentIcon = $avatar->getAvatarImage();
 | 
			
		||||
			} else {
 | 
			
		||||
				$commentIcon = '';
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
		    // ##START## 27.09.2017 von Bernhard Linz
 | 
			
		||||
			$commentPoster_Display = $this->username;
 | 
			
		||||
			$commentPoster = $this->username;
 | 
			
		||||
//			$commentPoster_Display = wfMessage( 'comments-anon-name' )->plain();
 | 
			
		||||
//			$commentPoster = wfMessage( 'comments-anon-name' )->plain();
 | 
			
		||||
			$commentIcon = 'default_s.gif';
 | 
			
		||||
            // ##ENDE##
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$avatarHTML = '';
 | 
			
		||||
		if ( class_exists( 'wAvatar' ) ) {
 | 
			
		||||
			global $wgUploadPath;
 | 
			
		||||
			$avatarHTML = '<img src="' . $wgUploadPath . '/avatars/' . $commentIcon .
 | 
			
		||||
				'" alt="" align="middle" border="0"/>';
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$comment_text = substr( $this->text, 0, 50 - strlen( $commentPoster_Display ) );
 | 
			
		||||
		if ( $comment_text != $this->text ) {
 | 
			
		||||
			$comment_text .= wfMessage( 'ellipsis' )->plain();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$output .= '<div class="cod">';
 | 
			
		||||
		$sign = '';
 | 
			
		||||
		if ( $this->currentScore > 0 ) {
 | 
			
		||||
			$sign = '+';
 | 
			
		||||
		} elseif ( $this->currentScore < 0 ) {
 | 
			
		||||
			$sign = '-'; // this *really* shouldn't be happening...
 | 
			
		||||
		}
 | 
			
		||||
		$output .= '<span class="cod-score">' . $sign . $this->currentScore .
 | 
			
		||||
			'</span> ' . $avatarHTML .
 | 
			
		||||
			'<span class="cod-poster">' . $commentPoster . '</span>';
 | 
			
		||||
		$output .= '<span class="cod-comment"><a href="' .
 | 
			
		||||
			$title2->getFullURL() . '#comment-' . $this->id .
 | 
			
		||||
			'" title="' . $title2->getText() . '">' . $comment_text .
 | 
			
		||||
			'</a></span>';
 | 
			
		||||
		$output .= '</div>';
 | 
			
		||||
 | 
			
		||||
		return $output;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Show the box for if this comment has been ignored
 | 
			
		||||
	 *
 | 
			
		||||
@@ -711,10 +633,10 @@ class Comment extends ContextSource {
 | 
			
		||||
	/**
 | 
			
		||||
	 * Show the comment
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param bool $hide: if true, comment is returned but hidden (display:none)
 | 
			
		||||
	 * @param $containerClass
 | 
			
		||||
	 * @param $blockList
 | 
			
		||||
	 * @param $anonList
 | 
			
		||||
	 * @param bool $hide If true, comment is returned but hidden (display:none)
 | 
			
		||||
	 * @param string $containerClass
 | 
			
		||||
	 * @param array $blockList
 | 
			
		||||
	 * @param array $anonList
 | 
			
		||||
	 * @return string
 | 
			
		||||
	 */
 | 
			
		||||
	function showComment( $hide = false, $containerClass, $blockList, $anonList ) {
 | 
			
		||||
@@ -743,24 +665,33 @@ class Comment extends ContextSource {
 | 
			
		||||
			$user = User::newFromId( $this->userID );
 | 
			
		||||
			$CommentReplyToGender = $user->getOption( 'gender', 'unknown' );
 | 
			
		||||
		} else {
 | 
			
		||||
		    // ##START## 27.09.2017 von Bernhard Linz
 | 
			
		||||
			$anonMsg = $this->msg( 'comments-anon-name' )->inContentLanguage()->plain();
 | 
			
		||||
// ## START ## 25.05.2019 von Bernhard Linz ###################################################################################################
 | 
			
		||||
            //Bei Anonymen Benutzern den Namen trotzdem aus der Datenbank benutzen
 | 
			
		||||
			//$commentPoster = $anonMsg . ' #' . $anonList[$this->username];
 | 
			
		||||
            $commentPoster = $this->username;
 | 
			
		||||
            if ( filter_var($commentPoster, FILTER_VALIDATE_IP) !== false ){
 | 
			
		||||
                // Wert ist eine IP-Adresse
 | 
			
		||||
                $commentPoster = $anonMsg . ' #' . $anonList[$this->username];
 | 
			
		||||
            }
 | 
			
		||||
            // Name Fett drucken
 | 
			
		||||
            $commentPoster = '<b>' . $commentPoster . '</b>';
 | 
			
		||||
// ## ENDE ## 25.05.2019 von Bernhard Linz ###################################################################################################
 | 
			
		||||
			$CommentReplyTo = $anonMsg;
 | 
			
		||||
			$CommentReplyToGender = 'unknown'; // Undisclosed gender as anon user
 | 
			
		||||
            $commentPoster = '<b>' . $commentPoster . '</b>';
 | 
			
		||||
            // ##ENDE##
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Comment delete button for privileged users
 | 
			
		||||
		$userObj = $this->getUser();
 | 
			
		||||
		$dlt = '';
 | 
			
		||||
 | 
			
		||||
		if ( $this->getUser()->isAllowed( 'commentadmin' ) ) {
 | 
			
		||||
		if (
 | 
			
		||||
			$userObj->isAllowed( 'commentadmin' ) ||
 | 
			
		||||
			// Allow users to delete their own comments if that feature is enabled in
 | 
			
		||||
			// site configuration
 | 
			
		||||
			// @see https://phabricator.wikimedia.org/T147796
 | 
			
		||||
			$userObj->isAllowed( 'comment-delete-own' ) && $this->isOwner( $userObj )
 | 
			
		||||
		) {
 | 
			
		||||
			$dlt = ' | <span class="c-delete">' .
 | 
			
		||||
				'<a href="javascript:void(0);" rel="nofollow" class="comment-delete-link" data-comment-id="' .
 | 
			
		||||
				$this->id . '">' .
 | 
			
		||||
@@ -769,7 +700,7 @@ class Comment extends ContextSource {
 | 
			
		||||
 | 
			
		||||
		// Reply Link (does not appear on child comments)
 | 
			
		||||
		$replyRow = '';
 | 
			
		||||
		if ( $this->getUser()->isAllowed( 'comment' ) ) {
 | 
			
		||||
		if ( $userObj->isAllowed( 'comment' ) ) {
 | 
			
		||||
			if ( $this->parentID == 0 ) {
 | 
			
		||||
				if ( $replyRow ) {
 | 
			
		||||
					$replyRow .= wfMessage( 'pipe-separator' )->plain();
 | 
			
		||||
@@ -792,7 +723,7 @@ class Comment extends ContextSource {
 | 
			
		||||
		$blockLink = '';
 | 
			
		||||
 | 
			
		||||
		if (
 | 
			
		||||
			$this->getUser()->getID() != 0 && $this->getUser()->getID() != $this->userID &&
 | 
			
		||||
			$userObj->getId() != 0 && $userObj->getId() != $this->userID &&
 | 
			
		||||
			!( in_array( $this->userID, $blockList ) )
 | 
			
		||||
		) {
 | 
			
		||||
			$blockLink = '<a href="javascript:void(0);" rel="nofollow" class="comments-block-user" data-comments-safe-username="' .
 | 
			
		||||
@@ -805,12 +736,13 @@ class Comment extends ContextSource {
 | 
			
		||||
 | 
			
		||||
		// Default avatar image, if SocialProfile extension isn't enabled
 | 
			
		||||
		global $wgCommentsDefaultAvatar;
 | 
			
		||||
// ## START ## 25.05.2019 von Bernhard Linz ###################################################################################################
 | 
			
		||||
        if ( $this->username == "BLinz" ) {
 | 
			
		||||
            $avatarImg = '<img src="' . $wgExtensionAssetsPath . '/Comments/' . 'resources/images/bernhard2.gif' . '" alt="" border="0" />';
 | 
			
		||||
        } else {
 | 
			
		||||
            $avatarImg = '<img src="' . $wgExtensionAssetsPath . '/Comments/' . $wgCommentsDefaultAvatar . '" alt="" border="0" />';
 | 
			
		||||
    		$avatarImg = '<img src="' . $wgCommentsDefaultAvatar . '" alt="" border="0" />';
 | 
			
		||||
        }
 | 
			
		||||
//		$avatarImg = '<img src="' . $wgExtensionAssetsPath . '/Comments/' . $wgCommentsDefaultAvatar . '" alt="" border="0" />';
 | 
			
		||||
// ## ENDE ## 25.05.2019 von Bernhard Linz ###################################################################################################
 | 
			
		||||
		// If SocialProfile *is* enabled, then use its wAvatar class to get the avatars for each commenter
 | 
			
		||||
		if ( class_exists( 'wAvatar' ) ) {
 | 
			
		||||
			$avatar = new wAvatar( $this->userID, 'ml' );
 | 
			
		||||
@@ -824,13 +756,13 @@ class Comment extends ContextSource {
 | 
			
		||||
		$output .= "{$commentPoster}";
 | 
			
		||||
		$output .= "<span class=\"c-user-level\">{$commentPosterLevel}</span> {$blockLink}" . "\n";
 | 
			
		||||
 | 
			
		||||
		wfSuppressWarnings(); // E_STRICT bitches about strtotime()
 | 
			
		||||
		Wikimedia\suppressWarnings(); // E_STRICT bitches about strtotime()
 | 
			
		||||
		$output .= '<div class="c-time">' .
 | 
			
		||||
			wfMessage(
 | 
			
		||||
				'comments-time-ago',
 | 
			
		||||
				CommentFunctions::getTimeAgo( strtotime( $this->date ) )
 | 
			
		||||
			)->parse() . '</div>' . "\n";
 | 
			
		||||
		wfRestoreWarnings();
 | 
			
		||||
		Wikimedia\restoreWarnings();
 | 
			
		||||
 | 
			
		||||
		$output .= '<div class="c-score">' . "\n";
 | 
			
		||||
		$output .= $this->getScoreHTML();
 | 
			
		||||
@@ -21,12 +21,12 @@ class CommentFunctions {
 | 
			
		||||
 | 
			
		||||
	static function getTimeOffset( $time, $timeabrv, $timename ) {
 | 
			
		||||
		$timeStr = ''; // misza: initialize variables, DUMB FUCKS!
 | 
			
		||||
		if( $time[$timeabrv] > 0 ) {
 | 
			
		||||
		if ( $time[$timeabrv] > 0 ) {
 | 
			
		||||
			// Give grep a chance to find the usages:
 | 
			
		||||
			// comments-time-days, comments-time-hours, comments-time-minutes, comments-time-seconds, comments-time-months
 | 
			
		||||
			$timeStr = wfMessage( "comments-time-{$timename}", $time[$timeabrv] )->parse();
 | 
			
		||||
		}
 | 
			
		||||
		if( $timeStr ) {
 | 
			
		||||
		if ( $timeStr ) {
 | 
			
		||||
			$timeStr .= ' ';
 | 
			
		||||
		}
 | 
			
		||||
		return $timeStr;
 | 
			
		||||
@@ -45,15 +45,15 @@ class CommentFunctions {
 | 
			
		||||
			$timeStr = $timeStrMo;
 | 
			
		||||
		} else {
 | 
			
		||||
			$timeStr = $timeStrD;
 | 
			
		||||
			if( $timeStr < 2 ) {
 | 
			
		||||
			if ( $timeStr < 2 ) {
 | 
			
		||||
				$timeStr .= $timeStrH;
 | 
			
		||||
				$timeStr .= $timeStrM;
 | 
			
		||||
				if( !$timeStr ) {
 | 
			
		||||
				if ( !$timeStr ) {
 | 
			
		||||
					$timeStr .= $timeStrS;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if( !$timeStr ) {
 | 
			
		||||
		if ( !$timeStr ) {
 | 
			
		||||
			$timeStr = wfMessage( 'comments-time-seconds', 1 )->parse();
 | 
			
		||||
		}
 | 
			
		||||
		return $timeStr;
 | 
			
		||||
@@ -64,7 +64,7 @@ class CommentFunctions {
 | 
			
		||||
	 * <a href=#>http://www.abc....xyz.html</a>
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param $matches Array
 | 
			
		||||
	 * @return String: shortened URL
 | 
			
		||||
	 * @return String shortened URL
 | 
			
		||||
	 */
 | 
			
		||||
	public static function cutCommentLinkText( $matches ) {
 | 
			
		||||
		$tagOpen = $matches[1];
 | 
			
		||||
@@ -74,7 +74,7 @@ class CommentFunctions {
 | 
			
		||||
		$image = preg_match( "/<img src=/i", $linkText );
 | 
			
		||||
		$isURL = ( preg_match( '%^(?:http|https|ftp)://(?:www\.)?.*$%i', $linkText ) ? true : false );
 | 
			
		||||
 | 
			
		||||
		if( $isURL && !$image && strlen( $linkText ) > 30 ) {
 | 
			
		||||
		if ( $isURL && !$image && strlen( $linkText ) > 30 ) {
 | 
			
		||||
			$start = substr( $linkText, 0, ( 30 / 2 ) - 3 );
 | 
			
		||||
			$end = substr( $linkText, strlen( $linkText ) - ( 30 / 2 ) + 3, ( 30 / 2 ) - 3 );
 | 
			
		||||
			$linkText = trim( $start ) . wfMessage( 'ellipsis' )->escaped() . trim( $end );
 | 
			
		||||
@@ -87,7 +87,7 @@ class CommentFunctions {
 | 
			
		||||
	 * built-in regex-based spam filters
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param $text String: text to check for spam patterns
 | 
			
		||||
	 * @return Boolean: true if it contains spam, otherwise false
 | 
			
		||||
	 * @return Boolean true if it contains spam, otherwise false
 | 
			
		||||
	 */
 | 
			
		||||
	public static function isSpam( $text ) {
 | 
			
		||||
		global $wgSpamRegex, $wgSummarySpamRegex;
 | 
			
		||||
@@ -96,7 +96,7 @@ class CommentFunctions {
 | 
			
		||||
		// Allow to hook other anti-spam extensions so that sites that use,
 | 
			
		||||
		// for example, AbuseFilter, Phalanx or SpamBlacklist can add additional
 | 
			
		||||
		// checks
 | 
			
		||||
		Hooks::run( 'Comments::isSpam', array( &$text, &$retVal ) );
 | 
			
		||||
		Hooks::run( 'Comments::isSpam', [ &$text, &$retVal ] );
 | 
			
		||||
		if ( $retVal ) {
 | 
			
		||||
			// Should only be true here...
 | 
			
		||||
			return $retVal;
 | 
			
		||||
@@ -122,13 +122,13 @@ class CommentFunctions {
 | 
			
		||||
	 * Checks the supplied text for links
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param $text String: text to check
 | 
			
		||||
	 * @return Boolean: true if it contains links, otherwise false
 | 
			
		||||
	 * @return Boolean true if it contains links, otherwise false
 | 
			
		||||
	 */
 | 
			
		||||
	public static function haveLinks( $text ) {
 | 
			
		||||
		$linkPatterns = array(
 | 
			
		||||
		$linkPatterns = [
 | 
			
		||||
			'/(https?)|(ftp):\/\//',
 | 
			
		||||
			'/=\\s*[\'"]?\\s*mailto:/',
 | 
			
		||||
		);
 | 
			
		||||
		];
 | 
			
		||||
		foreach ( $linkPatterns as $linkPattern ) {
 | 
			
		||||
			if ( preg_match( $linkPattern, $text ) ) {
 | 
			
		||||
				return true;
 | 
			
		||||
@@ -148,21 +148,20 @@ class CommentFunctions {
 | 
			
		||||
	public static function blockUser( $blocker, $userId, $userName ) {
 | 
			
		||||
		$dbw = wfGetDB( DB_MASTER );
 | 
			
		||||
 | 
			
		||||
		wfSuppressWarnings(); // E_STRICT bitching
 | 
			
		||||
		Wikimedia\suppressWarnings(); // E_STRICT bitching
 | 
			
		||||
		$date = date( 'Y-m-d H:i:s' );
 | 
			
		||||
		wfRestoreWarnings();
 | 
			
		||||
		Wikimedia\restoreWarnings();
 | 
			
		||||
		$dbw->insert(
 | 
			
		||||
			'Comments_block',
 | 
			
		||||
			array(
 | 
			
		||||
			[
 | 
			
		||||
				'cb_user_id' => $blocker->getId(),
 | 
			
		||||
				'cb_user_name' => $blocker->getName(),
 | 
			
		||||
				'cb_user_id_blocked' => $userId,
 | 
			
		||||
				'cb_user_name_blocked' => $userName,
 | 
			
		||||
				'cb_date' => $date
 | 
			
		||||
			),
 | 
			
		||||
			],
 | 
			
		||||
			__METHOD__
 | 
			
		||||
		);
 | 
			
		||||
		$dbw->commit( __METHOD__ );
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -172,12 +171,12 @@ class CommentFunctions {
 | 
			
		||||
	 * @return array List of comment-blocked users
 | 
			
		||||
	 */
 | 
			
		||||
	static function getBlockList( $userId ) {
 | 
			
		||||
		$blockList = array();
 | 
			
		||||
		$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
		$blockList = [];
 | 
			
		||||
		$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
		$res = $dbr->select(
 | 
			
		||||
			'Comments_block',
 | 
			
		||||
			'cb_user_name_blocked',
 | 
			
		||||
			array( 'cb_user_id' => $userId ),
 | 
			
		||||
			[ 'cb_user_id' => $userId ],
 | 
			
		||||
			__METHOD__
 | 
			
		||||
		);
 | 
			
		||||
		foreach ( $res as $row ) {
 | 
			
		||||
@@ -187,14 +186,14 @@ class CommentFunctions {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	static function isUserCommentBlocked( $userId, $userIdBlocked ) {
 | 
			
		||||
		$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
		$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
		$s = $dbr->selectRow(
 | 
			
		||||
			'Comments_block',
 | 
			
		||||
			array( 'cb_id' ),
 | 
			
		||||
			array(
 | 
			
		||||
			[ 'cb_id' ],
 | 
			
		||||
			[
 | 
			
		||||
				'cb_user_id' => $userId,
 | 
			
		||||
				'cb_user_id_blocked' => $userIdBlocked
 | 
			
		||||
			),
 | 
			
		||||
			],
 | 
			
		||||
			__METHOD__
 | 
			
		||||
		);
 | 
			
		||||
		if ( $s !== false ) {
 | 
			
		||||
@@ -214,13 +213,12 @@ class CommentFunctions {
 | 
			
		||||
		$dbw = wfGetDB( DB_MASTER );
 | 
			
		||||
		$dbw->delete(
 | 
			
		||||
			'Comments_block',
 | 
			
		||||
			array(
 | 
			
		||||
			[
 | 
			
		||||
				'cb_user_id' => $userId,
 | 
			
		||||
				'cb_user_id_blocked' => $userIdBlocked
 | 
			
		||||
			),
 | 
			
		||||
			],
 | 
			
		||||
			__METHOD__
 | 
			
		||||
		);
 | 
			
		||||
		$dbw->commit( __METHOD__ );
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -279,24 +277,6 @@ class CommentFunctions {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Sort COMMENTS (not threads) by score
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param $x
 | 
			
		||||
	 * @param $y
 | 
			
		||||
	 */
 | 
			
		||||
	public static function sortCommentScore( $x, $y ) {
 | 
			
		||||
		// return -1  -  x goes above y
 | 
			
		||||
		// return  1  -  x goes below y
 | 
			
		||||
		// return  0  -  order irrelevant (only when x == y)
 | 
			
		||||
 | 
			
		||||
		if ( $x->currentScore > $y->currentScore ) {
 | 
			
		||||
			return -1;
 | 
			
		||||
		} else {
 | 
			
		||||
			return 1;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Sort the comments purely by the time, from earliest to latest
 | 
			
		||||
	 *
 | 
			
		||||
@@ -1,15 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Aliases for special pages
 | 
			
		||||
 *
 | 
			
		||||
 * @file
 | 
			
		||||
 * @ingroup Extensions
 | 
			
		||||
 */
 | 
			
		||||
// @codingStandardsIgnoreFile
 | 
			
		||||
 | 
			
		||||
$specialPageAliases = array();
 | 
			
		||||
 | 
			
		||||
/** English */
 | 
			
		||||
$specialPageAliases['en'] = array(
 | 
			
		||||
	'CommentIgnoreList' => array( 'CommentIgnoreList' ),
 | 
			
		||||
);
 | 
			
		||||
@@ -1,173 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Hooked functions used by the Comments extension.
 | 
			
		||||
 * All class methods are public and static.
 | 
			
		||||
 *
 | 
			
		||||
 * @file
 | 
			
		||||
 * @ingroup Extensions
 | 
			
		||||
 * @author Jack Phoenix <jack@countervandalism.net>
 | 
			
		||||
 * @author Alexia E. Smith
 | 
			
		||||
 * @copyright (c) 2013 Curse Inc.
 | 
			
		||||
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 | 
			
		||||
 * @link https://www.mediawiki.org/wiki/Extension:Comments Documentation
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class CommentsHooks {
 | 
			
		||||
	/**
 | 
			
		||||
	 * Registers the <comments> tag with the Parser.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param Parser $parser
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	public static function onParserFirstCallInit( Parser &$parser ) {
 | 
			
		||||
		$parser->setHook( 'comments', array( 'CommentsHooks', 'displayComments' ) );
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Callback function for onParserFirstCallInit().
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param $input
 | 
			
		||||
	 * @param array $args
 | 
			
		||||
	 * @param Parser $parser
 | 
			
		||||
	 * @return string HTML
 | 
			
		||||
	 */
 | 
			
		||||
	public static function displayComments( $input, $args, $parser ) {
 | 
			
		||||
		global $wgOut, $wgCommentsSortDescending;
 | 
			
		||||
 | 
			
		||||
		$parser->disableCache();
 | 
			
		||||
		// If an unclosed <comments> tag is added to a page, the extension will
 | 
			
		||||
		// go to an infinite loop...this protects against that condition.
 | 
			
		||||
		$parser->setHook( 'comments', array( 'CommentsHooks', 'nonDisplayComments' ) );
 | 
			
		||||
 | 
			
		||||
		$title = $parser->getTitle();
 | 
			
		||||
		if ( $title->getArticleID() == 0 && $title->getDBkey() == 'CommentListGet' ) {
 | 
			
		||||
			return self::nonDisplayComments( $input, $args, $parser );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Add required CSS & JS via ResourceLoader
 | 
			
		||||
		$wgOut->addModuleStyles( 'ext.comments.css' );
 | 
			
		||||
		$wgOut->addModules( 'ext.comments.js' );
 | 
			
		||||
		$wgOut->addJsConfigVars( array( 'wgCommentsSortDescending' => $wgCommentsSortDescending ) );
 | 
			
		||||
 | 
			
		||||
		// Parse arguments
 | 
			
		||||
		// The preg_match() lines here are to support the old-style way of
 | 
			
		||||
		// adding arguments:
 | 
			
		||||
		// <comments>
 | 
			
		||||
		// Allow=Foo,Bar
 | 
			
		||||
		// Voting=Plus
 | 
			
		||||
		// </comments>
 | 
			
		||||
		// whereas the normal, standard MediaWiki style, which this extension
 | 
			
		||||
		// also supports is: <comments allow="Foo,Bar" voting="Plus" />
 | 
			
		||||
		$allow = '';
 | 
			
		||||
		if ( preg_match( '/^\s*Allow\s*=\s*(.*)/mi', $input, $matches ) ) {
 | 
			
		||||
			$allow = htmlspecialchars( $matches[1] );
 | 
			
		||||
		} elseif ( !empty( $args['allow'] ) ) {
 | 
			
		||||
			$allow = $args['allow'];
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$voting = '';
 | 
			
		||||
		if ( preg_match( '/^\s*Voting\s*=\s*(.*)/mi', $input, $matches ) ) {
 | 
			
		||||
			$voting = htmlspecialchars( $matches[1] );
 | 
			
		||||
		} elseif (
 | 
			
		||||
			!empty( $args['voting'] ) &&
 | 
			
		||||
			in_array( strtoupper( $args['voting'] ), array( 'OFF', 'PLUS', 'MINUS' ) )
 | 
			
		||||
		) {
 | 
			
		||||
			$voting = $args['voting'];
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$commentsPage = new CommentsPage( $title->getArticleID(), $wgOut->getContext() );
 | 
			
		||||
		$commentsPage->allow = $allow;
 | 
			
		||||
		$commentsPage->setVoting( $voting );
 | 
			
		||||
 | 
			
		||||
		$output = '<div class="comments-body">';
 | 
			
		||||
 | 
			
		||||
		if ( $wgCommentsSortDescending ) { // form before comments
 | 
			
		||||
			$output .= '<a id="end" rel="nofollow"></a>';
 | 
			
		||||
			if ( !wfReadOnly() ) {
 | 
			
		||||
				$output .= $commentsPage->displayForm();
 | 
			
		||||
			} else {
 | 
			
		||||
				$output .= wfMessage( 'comments-db-locked' )->parse();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$output .= $commentsPage->displayOrderForm();
 | 
			
		||||
 | 
			
		||||
		$output .= '<div id="allcomments">' . $commentsPage->display() . '</div>';
 | 
			
		||||
 | 
			
		||||
		// If the database is in read-only mode, display a message informing the
 | 
			
		||||
		// user about that, otherwise allow them to comment
 | 
			
		||||
		if ( !$wgCommentsSortDescending ) { // form after comments
 | 
			
		||||
			if ( !wfReadOnly() ) {
 | 
			
		||||
				$output .= $commentsPage->displayForm();
 | 
			
		||||
			} else {
 | 
			
		||||
				$output .= wfMessage( 'comments-db-locked' )->parse();
 | 
			
		||||
			}
 | 
			
		||||
			$output .= '<a id="end" rel="nofollow"></a>';
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$output .= '</div>'; // div.comments-body
 | 
			
		||||
 | 
			
		||||
		return $output;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static function nonDisplayComments( $input, $args, $parser ) {
 | 
			
		||||
		$attr = array();
 | 
			
		||||
 | 
			
		||||
		foreach ( $args as $name => $value ) {
 | 
			
		||||
			$attr[] = htmlspecialchars( $name ) . '="' . htmlspecialchars( $value ) . '"';
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$output = '<comments';
 | 
			
		||||
		if ( count( $attr ) > 0 ) {
 | 
			
		||||
			$output .= ' ' . implode( ' ', $attr );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if ( !is_null( $input ) ) {
 | 
			
		||||
			$output .= '>' . htmlspecialchars( $input ) . '</comments>';
 | 
			
		||||
		} else {
 | 
			
		||||
			$output .= ' />';
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return $output;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Adds the three new required database tables into the database when the
 | 
			
		||||
	 * user runs /maintenance/update.php (the core database updater script).
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param DatabaseUpdater $updater
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	public static function onLoadExtensionSchemaUpdates( $updater ) {
 | 
			
		||||
		$dir = __DIR__ . '/../sql';
 | 
			
		||||
 | 
			
		||||
		$dbType = $updater->getDB()->getType();
 | 
			
		||||
		// For non-MySQL/MariaDB/SQLite DBMSes, use the appropriately named file
 | 
			
		||||
		if ( !in_array( $dbType, array( 'mysql', 'sqlite' ) ) ) {
 | 
			
		||||
			$filename = "comments.{$dbType}.sql";
 | 
			
		||||
		} else {
 | 
			
		||||
			$filename = 'comments.sql';
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$updater->addExtensionUpdate( array( 'addTable', 'Comments', "{$dir}/{$filename}", true ) );
 | 
			
		||||
		$updater->addExtensionUpdate( array( 'addTable', 'Comments_Vote', "{$dir}/{$filename}", true ) );
 | 
			
		||||
		$updater->addExtensionUpdate( array( 'addTable', 'Comments_block', "{$dir}/{$filename}", true ) );
 | 
			
		||||
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * For integration with the Renameuser extension.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param RenameuserSQL $renameUserSQL
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	public static function onRenameUserSQL( $renameUserSQL ) {
 | 
			
		||||
		$renameUserSQL->tables['Comments'] = array( 'Comment_Username', 'Comment_user_id' );
 | 
			
		||||
		$renameUserSQL->tables['Comments_Vote'] = array( 'Comment_Vote_Username', 'Comment_Vote_user_id' );
 | 
			
		||||
		$renameUserSQL->tables['Comments_block'] = array( 'cb_user_name', 'cb_user_id' );
 | 
			
		||||
		$renameUserSQL->tables['Comments_block'] = array( 'cb_user_name_blocked', 'cb_user_id_blocked' );
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 *  Magic words for extension.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
$magicWords = array();
 | 
			
		||||
 | 
			
		||||
/** English (English) */
 | 
			
		||||
$magicWords['en'] = array(
 | 
			
		||||
	'NUMBEROFCOMMENTS' => array( 0, 'NUMBEROFCOMMENTS' ),
 | 
			
		||||
	'NUMBEROFCOMMENTSPAGE' => array( 0, 'NUMBEROFCOMMENTSPAGE' ),
 | 
			
		||||
);
 | 
			
		||||
							
								
								
									
										65
									
								
								includes/CommentsHooks.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								includes/CommentsHooks.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,65 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Hooked functions used by the Comments extension.
 | 
			
		||||
 * All class methods are public and static.
 | 
			
		||||
 *
 | 
			
		||||
 * @file
 | 
			
		||||
 * @ingroup Extensions
 | 
			
		||||
 * @author Jack Phoenix
 | 
			
		||||
 * @author Alexia E. Smith
 | 
			
		||||
 * @copyright (c) 2013 Curse Inc.
 | 
			
		||||
 * @license GPL-2.0-or-later
 | 
			
		||||
 * @link https://www.mediawiki.org/wiki/Extension:Comments Documentation
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class CommentsHooks {
 | 
			
		||||
	/**
 | 
			
		||||
	 * Registers the following tags and magic words:
 | 
			
		||||
	 * - <comments />
 | 
			
		||||
	 * - NUMBEROFCOMMENTSPAGE
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param Parser $parser
 | 
			
		||||
	 */
 | 
			
		||||
	public static function onParserFirstCallInit( Parser &$parser ) {
 | 
			
		||||
		$parser->setHook( 'comments', [ 'DisplayComments', 'getParserHandler' ] );
 | 
			
		||||
		$parser->setFunctionHook( 'NUMBEROFCOMMENTSPAGE', 'NumberOfComments::getParserHandler', Parser::SFH_NO_HASH );
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Adds the three new required database tables into the database when the
 | 
			
		||||
	 * user runs /maintenance/update.php (the core database updater script).
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param DatabaseUpdater $updater
 | 
			
		||||
	 */
 | 
			
		||||
	public static function onLoadExtensionSchemaUpdates( $updater ) {
 | 
			
		||||
		$dir = __DIR__ . '/../sql';
 | 
			
		||||
 | 
			
		||||
		$dbType = $updater->getDB()->getType();
 | 
			
		||||
		// For non-MySQL/MariaDB/SQLite DBMSes, use the appropriately named file
 | 
			
		||||
		if ( !in_array( $dbType, [ 'mysql', 'sqlite' ] ) ) {
 | 
			
		||||
			$comments = "comments.{$dbType}.sql";
 | 
			
		||||
			$comments_vote = "comments_vote.{$dbType}.sql";
 | 
			
		||||
			$comments_block = "comments_block.{$dbType}.sql";
 | 
			
		||||
		} else {
 | 
			
		||||
			$comments = 'comments.sql';
 | 
			
		||||
			$comments_vote = 'comments_vote.sql';
 | 
			
		||||
			$comments_block = 'comments_block.sql';
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$updater->addExtensionTable( 'Comments', "{$dir}/{$comments}" );
 | 
			
		||||
		$updater->addExtensionTable( 'Comments_Vote', "{$dir}/{$comments_vote}" );
 | 
			
		||||
		$updater->addExtensionTable( 'Comments_block', "{$dir}/{$comments_block}" );
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * For integration with the Renameuser extension.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param RenameuserSQL $renameUserSQL
 | 
			
		||||
	 */
 | 
			
		||||
	public static function onRenameUserSQL( $renameUserSQL ) {
 | 
			
		||||
		$renameUserSQL->tables['Comments'] = [ 'Comment_Username', 'Comment_user_id' ];
 | 
			
		||||
		$renameUserSQL->tables['Comments_Vote'] = [ 'Comment_Vote_Username', 'Comment_Vote_user_id' ];
 | 
			
		||||
		$renameUserSQL->tables['Comments_block'] = [ 'cb_user_name', 'cb_user_id' ];
 | 
			
		||||
		$renameUserSQL->tables['Comments_block'] = [ 'cb_user_name_blocked', 'cb_user_id_blocked' ];
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -5,32 +5,7 @@
 | 
			
		||||
 * @file
 | 
			
		||||
 * @date 28 July 2013
 | 
			
		||||
 */
 | 
			
		||||
class CommentsLogFormatter extends LogFormatter {
 | 
			
		||||
	/**
 | 
			
		||||
	 * Gets the log action, including username.
 | 
			
		||||
	 *
 | 
			
		||||
	 * This is a copy of LogFormatter::getActionText() with one "escaped"
 | 
			
		||||
	 * swapped to parse; no other changes here!
 | 
			
		||||
	 *
 | 
			
		||||
	 * @return string HTML
 | 
			
		||||
	 */
 | 
			
		||||
	public function getActionText() {
 | 
			
		||||
		if ( $this->canView( LogPage::DELETED_ACTION ) ) {
 | 
			
		||||
			$element = $this->getActionMessage();
 | 
			
		||||
			if ( $element instanceof Message ) {
 | 
			
		||||
				$element = $this->plaintext ? $element->text() : $element->parse(); // <-- here's the change!
 | 
			
		||||
			}
 | 
			
		||||
			if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
 | 
			
		||||
				$element = $this->styleRestricedElement( $element );
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			$performer = $this->getPerformerElement() . $this->msg( 'word-separator' )->text();
 | 
			
		||||
			$element = $performer . $this->getRestrictedElement( 'rev-deleted-event' );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return $element;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
class CommentsLogFormatter extends WikitextLogFormatter {
 | 
			
		||||
	/**
 | 
			
		||||
	 * Formats parameters intented for action message from
 | 
			
		||||
	 * array of all parameters. There are three hardcoded
 | 
			
		||||
@@ -1,120 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Comments of the Day parser hook -- shows the five newest comments that have
 | 
			
		||||
 * been sent within the last 24 hours.
 | 
			
		||||
 *
 | 
			
		||||
 * @file
 | 
			
		||||
 * @ingroup Extensions
 | 
			
		||||
 * @date 27 November 2015
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class CommentsOfTheDay {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Register the new <commentsoftheday /> parser hook with the Parser.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param Parser $parser Instance of Parser
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	public static function registerTag( &$parser ) {
 | 
			
		||||
		$parser->setHook( 'commentsoftheday', array( __CLASS__, 'getHTML' ) );
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get comments of the day -- five newest comments within the last 24 hours
 | 
			
		||||
	 *
 | 
			
		||||
	 * @return string HTML
 | 
			
		||||
	 */
 | 
			
		||||
	public static function getHTML( $input, $args, $parser ) {
 | 
			
		||||
		$comments = self::get( (bool)$args['nocache'] );
 | 
			
		||||
		$commentOutput = '';
 | 
			
		||||
 | 
			
		||||
		foreach ( $comments as $comment ) {
 | 
			
		||||
			$commentOutput .= $comment->displayForCommentOfTheDay();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$output = '';
 | 
			
		||||
		if ( !empty( $commentOutput ) ) {
 | 
			
		||||
			$output .= $commentOutput;
 | 
			
		||||
		} else {
 | 
			
		||||
			$output .= wfMessage( 'comments-no-comments-of-day' )->plain();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return $output;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get comments of the day, either from cache or the DB.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param bool $skipCache Skip using memcached and fetch data directly from the DB?
 | 
			
		||||
	 * @param int $cacheTime How long to cache the results in memcached? Default is one day (60 * 60 * 24).
 | 
			
		||||
	 * @param array $whereConds WHERE conditions for the SQL clause (if not using the defaults)
 | 
			
		||||
	 * @return array
 | 
			
		||||
	 */
 | 
			
		||||
	public static function get( $skipCache = false, $cacheTime = 86400, $whereConds = array() ) {
 | 
			
		||||
		global $wgMemc;
 | 
			
		||||
 | 
			
		||||
		// Try memcached first
 | 
			
		||||
		$key = wfMemcKey( 'comments-of-the-day', 'standalone-hook-new' );
 | 
			
		||||
		$data = $wgMemc->get( $key );
 | 
			
		||||
 | 
			
		||||
		if ( $data ) { // success, got it from memcached!
 | 
			
		||||
			$comments = $data;
 | 
			
		||||
		} elseif ( !$data || $skipCache ) { // just query the DB
 | 
			
		||||
			$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
 | 
			
		||||
			if ( empty( $whereConds ) ) {
 | 
			
		||||
				$whereConds = array(
 | 
			
		||||
					'Comment_Page_ID = page_id',
 | 
			
		||||
					'UNIX_TIMESTAMP(Comment_Date) > ' . ( time() - ( $cacheTime ) )
 | 
			
		||||
				);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			$res = $dbr->select(
 | 
			
		||||
				array( 'Comments', 'page' ),
 | 
			
		||||
				array(
 | 
			
		||||
					'Comment_Username', 'Comment_IP', 'Comment_Text',
 | 
			
		||||
					'Comment_Date', 'Comment_User_Id', 'CommentID',
 | 
			
		||||
					'Comment_Parent_ID', 'Comment_Page_ID'
 | 
			
		||||
				),
 | 
			
		||||
				$whereConds,
 | 
			
		||||
				__METHOD__
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
			$comments = array();
 | 
			
		||||
 | 
			
		||||
			foreach ( $res as $row ) {
 | 
			
		||||
				if ( $row->Comment_Parent_ID == 0 ) {
 | 
			
		||||
					$thread = $row->CommentID;
 | 
			
		||||
				} else {
 | 
			
		||||
					$thread = $row->Comment_Parent_ID;
 | 
			
		||||
				}
 | 
			
		||||
				$data = array(
 | 
			
		||||
					'Comment_Username' => $row->Comment_Username,
 | 
			
		||||
					'Comment_IP' => $row->Comment_IP,
 | 
			
		||||
					'Comment_Text' => $row->Comment_Text,
 | 
			
		||||
					'Comment_Date' => $row->Comment_Date,
 | 
			
		||||
					'Comment_user_id' => $row->Comment_User_Id,
 | 
			
		||||
					// @todo FIXME: absolutely disgusting -- should use Language's formatNum() for better i18n
 | 
			
		||||
					'Comment_user_points' => ( isset( $row->stats_total_points ) ? number_format( $row->stats_total_points ) : 0 ),
 | 
			
		||||
					'CommentID' => $row->CommentID,
 | 
			
		||||
					'Comment_Parent_ID' => $row->Comment_Parent_ID,
 | 
			
		||||
					'thread' => $thread,
 | 
			
		||||
					'timestamp' => wfTimestamp( TS_UNIX, $row->Comment_Date )
 | 
			
		||||
				);
 | 
			
		||||
 | 
			
		||||
				$page = new CommentsPage( $row->Comment_Page_ID, new RequestContext() );
 | 
			
		||||
				$comments[] = new Comment( $page, new RequestContext(), $data );
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			usort( $comments, array( 'CommentFunctions', 'sortCommentScore' ) );
 | 
			
		||||
			$comments = array_slice( $comments, 0, 5 );
 | 
			
		||||
 | 
			
		||||
			$wgMemc->set( $key, $comments, $cacheTime );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return $comments;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -79,14 +79,14 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
	 *
 | 
			
		||||
	 * @var array
 | 
			
		||||
	 */
 | 
			
		||||
	public $comments = array();
 | 
			
		||||
	public $comments = [];
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Constructor
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param $pageID: current page ID
 | 
			
		||||
	 */
 | 
			
		||||
	function __construct ( $pageID, $context ) {
 | 
			
		||||
	function __construct( $pageID, $context ) {
 | 
			
		||||
		$this->id = $pageID;
 | 
			
		||||
		$this->setContext( $context );
 | 
			
		||||
		$this->title = Title::newFromID( $pageID );
 | 
			
		||||
@@ -98,12 +98,12 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
	 * @return int
 | 
			
		||||
	 */
 | 
			
		||||
	function countTotal() {
 | 
			
		||||
		$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
		$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
		$count = 0;
 | 
			
		||||
		$s = $dbr->selectRow(
 | 
			
		||||
			'Comments',
 | 
			
		||||
			array( 'COUNT(*) AS CommentCount' ),
 | 
			
		||||
			array( 'Comment_Page_ID' => $this->id ),
 | 
			
		||||
			[ 'COUNT(*) AS CommentCount' ],
 | 
			
		||||
			[ 'Comment_Page_ID' => $this->id ],
 | 
			
		||||
			__METHOD__
 | 
			
		||||
		);
 | 
			
		||||
		if ( $s !== false ) {
 | 
			
		||||
@@ -119,13 +119,13 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
	 */
 | 
			
		||||
	function getLatestCommentID() {
 | 
			
		||||
		$latestCommentID = 0;
 | 
			
		||||
		$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
		$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
		$s = $dbr->selectRow(
 | 
			
		||||
			'Comments',
 | 
			
		||||
			array( 'CommentID' ),
 | 
			
		||||
			array( 'Comment_Page_ID' => $this->id ),
 | 
			
		||||
			[ 'CommentID' ],
 | 
			
		||||
			[ 'Comment_Page_ID' => $this->id ],
 | 
			
		||||
			__METHOD__,
 | 
			
		||||
			array( 'ORDER BY' => 'Comment_Date DESC', 'LIMIT' => 1 )
 | 
			
		||||
			[ 'ORDER BY' => 'Comment_Date DESC', 'LIMIT' => 1 ]
 | 
			
		||||
		);
 | 
			
		||||
		if ( $s !== false ) {
 | 
			
		||||
			$latestCommentID = $s->CommentID;
 | 
			
		||||
@@ -159,37 +159,37 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
	 * Fetches all comments, called by display().
 | 
			
		||||
	 *
 | 
			
		||||
	 * @return array Array containing every possible bit of information about
 | 
			
		||||
	 *				a comment, including score, timestamp and more
 | 
			
		||||
	 * 				a comment, including score, timestamp and more
 | 
			
		||||
	 */
 | 
			
		||||
	public function getComments() {
 | 
			
		||||
		$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
		$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
 | 
			
		||||
		// Defaults (for non-social wikis)
 | 
			
		||||
		$tables = array(
 | 
			
		||||
		$tables = [
 | 
			
		||||
			'Comments',
 | 
			
		||||
			'vote1' => 'Comments_Vote',
 | 
			
		||||
			'vote2' => 'Comments_Vote',
 | 
			
		||||
		);
 | 
			
		||||
		$fields = array(
 | 
			
		||||
		];
 | 
			
		||||
		$fields = [
 | 
			
		||||
			'Comment_Username', 'Comment_IP', 'Comment_Text',
 | 
			
		||||
			'Comment_Date', 'Comment_Date AS timestamp',
 | 
			
		||||
			'Comment_user_id', 'CommentID', 'Comment_Parent_ID',
 | 
			
		||||
			'vote1.Comment_Vote_Score AS current_vote',
 | 
			
		||||
			'SUM(vote2.Comment_Vote_Score) AS comment_score'
 | 
			
		||||
		);
 | 
			
		||||
		$joinConds = array(
 | 
			
		||||
		];
 | 
			
		||||
		$joinConds = [
 | 
			
		||||
			// For current user's vote
 | 
			
		||||
			'vote1' => array(
 | 
			
		||||
			'vote1' => [
 | 
			
		||||
				'LEFT JOIN',
 | 
			
		||||
				array(
 | 
			
		||||
				[
 | 
			
		||||
					'vote1.Comment_Vote_ID = CommentID',
 | 
			
		||||
					'vote1.Comment_Vote_Username' => $this->getUser()->getName()
 | 
			
		||||
				)
 | 
			
		||||
			),
 | 
			
		||||
				]
 | 
			
		||||
			],
 | 
			
		||||
			// For total vote count
 | 
			
		||||
			'vote2' => array( 'LEFT JOIN', 'vote2.Comment_Vote_ID = CommentID' )
 | 
			
		||||
		);
 | 
			
		||||
		$params = array( 'GROUP BY' => 'CommentID' );
 | 
			
		||||
			'vote2' => [ 'LEFT JOIN', 'vote2.Comment_Vote_ID = CommentID' ]
 | 
			
		||||
		];
 | 
			
		||||
		$params = [ 'GROUP BY' => 'CommentID' ];
 | 
			
		||||
 | 
			
		||||
		// If SocialProfile is installed, query the user_stats table too.
 | 
			
		||||
		if (
 | 
			
		||||
@@ -198,22 +198,22 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
		) {
 | 
			
		||||
			$tables[] = 'user_stats';
 | 
			
		||||
			$fields[] = 'stats_total_points';
 | 
			
		||||
			$joinConds['Comments'] = array(
 | 
			
		||||
			$joinConds['Comments'] = [
 | 
			
		||||
				'LEFT JOIN', 'Comment_user_id = stats_user_id'
 | 
			
		||||
			);
 | 
			
		||||
			];
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Perform the query
 | 
			
		||||
		$res = $dbr->select(
 | 
			
		||||
			$tables,
 | 
			
		||||
			$fields,
 | 
			
		||||
			array( 'Comment_Page_ID' => $this->id ),
 | 
			
		||||
			[ 'Comment_Page_ID' => $this->id ],
 | 
			
		||||
			__METHOD__,
 | 
			
		||||
			$params,
 | 
			
		||||
			$joinConds
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		$comments = array();
 | 
			
		||||
		$comments = [];
 | 
			
		||||
 | 
			
		||||
		foreach ( $res as $row ) {
 | 
			
		||||
			if ( $row->Comment_Parent_ID == 0 ) {
 | 
			
		||||
@@ -221,7 +221,7 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
			} else {
 | 
			
		||||
				$thread = $row->Comment_Parent_ID;
 | 
			
		||||
			}
 | 
			
		||||
			$data = array(
 | 
			
		||||
			$data = [
 | 
			
		||||
				'Comment_Username' => $row->Comment_Username,
 | 
			
		||||
				'Comment_IP' => $row->Comment_IP,
 | 
			
		||||
				'Comment_Text' => $row->Comment_Text,
 | 
			
		||||
@@ -234,16 +234,16 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
				'timestamp' => wfTimestamp( TS_UNIX, $row->timestamp ),
 | 
			
		||||
				'current_vote' => ( isset( $row->current_vote ) ? $row->current_vote : false ),
 | 
			
		||||
				'total_vote' => ( isset( $row->comment_score ) ? $row->comment_score : 0 ),
 | 
			
		||||
			);
 | 
			
		||||
			];
 | 
			
		||||
 | 
			
		||||
			$comments[] = new Comment( $this, $this->getContext(), $data );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$commentThreads = array();
 | 
			
		||||
		$commentThreads = [];
 | 
			
		||||
 | 
			
		||||
		foreach ( $comments as $comment ) {
 | 
			
		||||
			if ( $comment->parentID == 0 ) {
 | 
			
		||||
				$commentThreads[$comment->id] = array( $comment );
 | 
			
		||||
				$commentThreads[$comment->id] = [ $comment ];
 | 
			
		||||
			} else {
 | 
			
		||||
				$commentThreads[$comment->parentID][] = $comment;
 | 
			
		||||
			}
 | 
			
		||||
@@ -274,7 +274,7 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
	 * @param int $pagerCurrent Page we are currently paged to
 | 
			
		||||
	 * @param int $pagesCount The maximum page number
 | 
			
		||||
	 *
 | 
			
		||||
	 * @return string: the links for paging through pages of comments
 | 
			
		||||
	 * @return string the links for paging through pages of comments
 | 
			
		||||
	 */
 | 
			
		||||
	function displayPager( $pagerCurrent, $pagesCount ) {
 | 
			
		||||
		// Middle is used to "center" pages around the current page.
 | 
			
		||||
@@ -307,12 +307,12 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
				$output .= '<li class="c-pager-item c-pager-previous">' .
 | 
			
		||||
					Html::rawElement(
 | 
			
		||||
						'a',
 | 
			
		||||
						array(
 | 
			
		||||
						[
 | 
			
		||||
							'rel' => 'nofollow',
 | 
			
		||||
							'class' => 'c-pager-link',
 | 
			
		||||
							'href' => '#cfirst',
 | 
			
		||||
							'data-' . $this->pageQuery => ( $pagerCurrent - 1 ),
 | 
			
		||||
						),
 | 
			
		||||
						],
 | 
			
		||||
						'<'
 | 
			
		||||
					) .
 | 
			
		||||
					'</li>';
 | 
			
		||||
@@ -323,12 +323,12 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
				$output .= '<li class="c-pager-item c-pager-first">' .
 | 
			
		||||
					Html::rawElement(
 | 
			
		||||
						'a',
 | 
			
		||||
						array(
 | 
			
		||||
						[
 | 
			
		||||
							'rel' => 'nofollow',
 | 
			
		||||
							'class' => 'c-pager-link',
 | 
			
		||||
							'href' => '#cfirst',
 | 
			
		||||
							'data-' . $this->pageQuery => 1,
 | 
			
		||||
						),
 | 
			
		||||
						],
 | 
			
		||||
						1
 | 
			
		||||
					) .
 | 
			
		||||
					'</li>';
 | 
			
		||||
@@ -349,12 +349,12 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
						$output .= '<li class="c-pager-item">' .
 | 
			
		||||
							Html::rawElement(
 | 
			
		||||
								'a',
 | 
			
		||||
								array(
 | 
			
		||||
								[
 | 
			
		||||
									'rel' => 'nofollow',
 | 
			
		||||
									'class' => 'c-pager-link',
 | 
			
		||||
									'href' => '#cfirst',
 | 
			
		||||
									'data-' . $this->pageQuery => $i,
 | 
			
		||||
								),
 | 
			
		||||
								],
 | 
			
		||||
								$i
 | 
			
		||||
							) .
 | 
			
		||||
							'</li>';
 | 
			
		||||
@@ -371,12 +371,12 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
				$output .= '<li class="c-pager-item c-pager-last">' .
 | 
			
		||||
					Html::rawElement(
 | 
			
		||||
						'a',
 | 
			
		||||
						array(
 | 
			
		||||
						[
 | 
			
		||||
							'rel' => 'nofollow',
 | 
			
		||||
							'class' => 'c-pager-link',
 | 
			
		||||
							'href' => '#cfirst',
 | 
			
		||||
							'data-' . $this->pageQuery => $pagesCount,
 | 
			
		||||
						),
 | 
			
		||||
						],
 | 
			
		||||
						$pagesCount
 | 
			
		||||
					) .
 | 
			
		||||
					'</li>';
 | 
			
		||||
@@ -387,12 +387,12 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
				$output .= '<li class="c-pager-item c-pager-next">' .
 | 
			
		||||
					Html::rawElement(
 | 
			
		||||
						'a',
 | 
			
		||||
						array(
 | 
			
		||||
						[
 | 
			
		||||
							'rel' => 'nofollow',
 | 
			
		||||
							'class' => 'c-pager-link',
 | 
			
		||||
							'href' => '#cfirst',
 | 
			
		||||
							'data-' . $this->pageQuery => ( $pagerCurrent + 1 ),
 | 
			
		||||
						),
 | 
			
		||||
						],
 | 
			
		||||
						'>'
 | 
			
		||||
					) .
 | 
			
		||||
					'</li>';
 | 
			
		||||
@@ -406,22 +406,22 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get this list of anon commenters in the given list of comments,
 | 
			
		||||
	 * and return a mapped array of IP adressess to the the number anon poster
 | 
			
		||||
	 * and return a mapped array of IP adressess to the number anon poster
 | 
			
		||||
	 * (so anon posters can be called Anon#1, Anon#2, etc
 | 
			
		||||
	 *
 | 
			
		||||
	 * @return array
 | 
			
		||||
	 */
 | 
			
		||||
	function getAnonList() {
 | 
			
		||||
		$counter = 1;
 | 
			
		||||
		$bucket = array();
 | 
			
		||||
		$bucket = [];
 | 
			
		||||
 | 
			
		||||
		$commentThreads = $this->comments;
 | 
			
		||||
 | 
			
		||||
		$comments = array(); // convert 2nd threads array to a simple list of comments
 | 
			
		||||
		$comments = []; // convert 2nd threads array to a simple list of comments
 | 
			
		||||
		foreach ( $commentThreads as $thread ) {
 | 
			
		||||
			$comments = array_merge( $comments, $thread );
 | 
			
		||||
		}
 | 
			
		||||
		usort( $comments, array( 'CommentFunctions', 'sortTime' ) );
 | 
			
		||||
		usort( $comments, [ 'CommentFunctions', 'sortTime' ] );
 | 
			
		||||
 | 
			
		||||
		foreach ( $comments as $comment ) {
 | 
			
		||||
			if (
 | 
			
		||||
@@ -445,11 +445,11 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
		global $wgCommentsSortDescending;
 | 
			
		||||
 | 
			
		||||
		if ( $this->orderBy ) {
 | 
			
		||||
			usort( $threads, array( 'CommentFunctions', 'sortScore' ) );
 | 
			
		||||
			usort( $threads, [ 'CommentFunctions', 'sortScore' ] );
 | 
			
		||||
		} elseif ( $wgCommentsSortDescending ) {
 | 
			
		||||
			usort( $threads, array( 'CommentFunctions', 'sortDesc' ) );
 | 
			
		||||
			usort( $threads, [ 'CommentFunctions', 'sortDesc' ] );
 | 
			
		||||
		} else {
 | 
			
		||||
			usort( $threads, array( 'CommentFunctions', 'sortAsc' ) );
 | 
			
		||||
			usort( $threads, [ 'CommentFunctions', 'sortAsc' ] );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return $threads;
 | 
			
		||||
@@ -482,13 +482,13 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
		// Suppress random E_NOTICE about "Undefined offset: 0", which seems to
 | 
			
		||||
		// be breaking ProblemReports (at least on my local devbox, not sure
 | 
			
		||||
		// about prod). --Jack Phoenix, 13 July 2015
 | 
			
		||||
		wfSuppressWarnings();
 | 
			
		||||
		Wikimedia\suppressWarnings();
 | 
			
		||||
		$currentPage = $commentPages[$currentPageNum - 1];
 | 
			
		||||
		wfRestoreWarnings();
 | 
			
		||||
		Wikimedia\restoreWarnings();
 | 
			
		||||
 | 
			
		||||
		// Load complete blocked list for logged in user so they don't see their comments
 | 
			
		||||
		$blockList = array();
 | 
			
		||||
		if ( $this->getUser()->getID() != 0 ) {
 | 
			
		||||
		$blockList = [];
 | 
			
		||||
		if ( $this->getUser()->getId() != 0 ) {
 | 
			
		||||
			$blockList = CommentFunctions::getBlockList( $this->getUser()->getId() );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -515,9 +515,10 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
	 *
 | 
			
		||||
	 * @return string HTML
 | 
			
		||||
	 */
 | 
			
		||||
 | 
			
		||||
// ## START ## 25.05.2019 von Bernhard Linz ########################################################################################
 | 
			
		||||
	function displayOrderForm() {
 | 
			
		||||
	    // ##START## 27.09.2017 von Bernhard Linz
 | 
			
		||||
   		$output = '<div id="spy" class="c-spy">
 | 
			
		||||
	    $output = '<div id="spy" class="c-spy">
 | 
			
		||||
				<a href="javascript:void(0)">' .
 | 
			
		||||
			wfMessage( 'comments-auto-refresher-enable' )->plain() .
 | 
			
		||||
			'</a>
 | 
			
		||||
@@ -547,7 +548,7 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
		</div>
 | 
			
		||||
		<br />' . "\n";
 | 
			
		||||
*/
 | 
			
		||||
        // ##ENDE##
 | 
			
		||||
// ## ENDE ## 25.05.2019 von Bernhard Linz ########################################################################################
 | 
			
		||||
 | 
			
		||||
		return $output;
 | 
			
		||||
	}
 | 
			
		||||
@@ -587,13 +588,13 @@ class CommentsPage extends ContextSource {
 | 
			
		||||
							htmlspecialchars( $login_title->getFullURL() )
 | 
			
		||||
						)->text() . '</div>' . "\n";
 | 
			
		||||
				}
 | 
			
		||||
			    // ##START## 27.09.2017 von Bernhard Linz
 | 
			
		||||
// ## START ## 25.05.2019 von Bernhard Linz ########################################################################################
 | 
			
		||||
                if ( !$this->getUser()->isLoggedIn() ) {
 | 
			
		||||
                    $output .= '<p><label for="txt_username">Name oder Emailadresse:</label><br /><input style="margin: 0px; width: 530px;" type="text" name="txt_username" id="txt_username" />' . "</p>";
 | 
			
		||||
                    $output .= '<p><label for="txt_username">Name oder Emailadresse oder leer lassen:</label><br /><input style="margin: 0px; width: 530px;" type="text" name="txt_username" id="txt_username" />' . "</p>";
 | 
			
		||||
                } else {
 | 
			
		||||
                    $output .= '<p>Benutzer:<b>' . $this->getUser()->getName() . '</b></p>';
 | 
			
		||||
                }
 | 
			
		||||
                // ##ENDE## 27.09.2017 von Bernhard Linz
 | 
			
		||||
// ## ENDE ## 25.05.2019 von Bernhard Linz ########################################################################################
 | 
			
		||||
				$output .= '<textarea name="commentText" id="comment" rows="5" cols="64"></textarea>' . "\n";
 | 
			
		||||
				$output .= '<div class="c-form-button"><input type="button" value="' .
 | 
			
		||||
					wfMessage( 'comments-post' )->plain() . '" class="site-button" /></div>' . "\n";
 | 
			
		||||
@@ -1,56 +1,52 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
class CommentBlockAPI extends ApiBase {
 | 
			
		||||
 | 
			
		||||
	public function execute() {
 | 
			
		||||
		// Do nothing when the database is in read-only mode
 | 
			
		||||
		if ( wfReadOnly() ) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Load user_name and user_id for person we want to block from the comment it originated from
 | 
			
		||||
		$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
		$s = $dbr->selectRow(
 | 
			
		||||
			'Comments',
 | 
			
		||||
			array( 'comment_username', 'comment_user_id' ),
 | 
			
		||||
			array( 'CommentID' => $this->getMain()->getVal( 'commentID' ) ),
 | 
			
		||||
			__METHOD__
 | 
			
		||||
		);
 | 
			
		||||
		if ( $s !== false ) {
 | 
			
		||||
			$userID = $s->comment_user_id;
 | 
			
		||||
			$username = $s->comment_username;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		CommentFunctions::blockUser( $this->getUser(), $userID, $username );
 | 
			
		||||
 | 
			
		||||
		if ( class_exists( 'UserStatsTrack' ) ) {
 | 
			
		||||
			$stats = new UserStatsTrack( $userID, $username );
 | 
			
		||||
			$stats->incStatField( 'comment_ignored' );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$result = $this->getResult();
 | 
			
		||||
		$result->addValue( $this->getModuleName(), 'ok', 'ok' );
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function needsToken() {
 | 
			
		||||
		return 'csrf';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function isWriteMode() {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getAllowedParams() {
 | 
			
		||||
		return array(
 | 
			
		||||
			'commentID' => array(
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			),
 | 
			
		||||
			'UsernameKOK' => array(
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => false,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'string'
 | 
			
		||||
			)
 | 
			
		||||
		);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
class CommentBlockAPI extends ApiBase {
 | 
			
		||||
 | 
			
		||||
	public function execute() {
 | 
			
		||||
		// Do nothing when the database is in read-only mode
 | 
			
		||||
		if ( wfReadOnly() ) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Load user_name and user_id for person we want to block from the comment it originated from
 | 
			
		||||
		$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
		$s = $dbr->selectRow(
 | 
			
		||||
			'Comments',
 | 
			
		||||
			[ 'comment_username', 'comment_user_id' ],
 | 
			
		||||
			[ 'CommentID' => $this->getMain()->getVal( 'commentID' ) ],
 | 
			
		||||
			__METHOD__
 | 
			
		||||
		);
 | 
			
		||||
		if ( $s !== false ) {
 | 
			
		||||
			$userID = $s->comment_user_id;
 | 
			
		||||
			$username = $s->comment_username;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		CommentFunctions::blockUser( $this->getUser(), $userID, $username );
 | 
			
		||||
 | 
			
		||||
		if ( class_exists( 'UserStatsTrack' ) ) {
 | 
			
		||||
			$stats = new UserStatsTrack( $userID, $username );
 | 
			
		||||
			$stats->incStatField( 'comment_ignored' );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$result = $this->getResult();
 | 
			
		||||
		$result->addValue( $this->getModuleName(), 'ok', 'ok' );
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function needsToken() {
 | 
			
		||||
		return 'csrf';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function isWriteMode() {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getAllowedParams() {
 | 
			
		||||
		return [
 | 
			
		||||
			'commentID' => [
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			]
 | 
			
		||||
		];
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -4,17 +4,21 @@ class CommentDeleteAPI extends ApiBase {
 | 
			
		||||
 | 
			
		||||
	public function execute() {
 | 
			
		||||
		$user = $this->getUser();
 | 
			
		||||
 | 
			
		||||
		$comment = Comment::newFromID( $this->getMain()->getVal( 'commentID' ) );
 | 
			
		||||
		// Blocked users cannot delete comments, and neither can unprivileged ones.
 | 
			
		||||
		// Also check for database read-only status
 | 
			
		||||
		if (
 | 
			
		||||
			$user->isBlocked() ||
 | 
			
		||||
			!$user->isAllowed( 'commentadmin' ) ||
 | 
			
		||||
			!(
 | 
			
		||||
				$user->isAllowed( 'commentadmin' ) ||
 | 
			
		||||
				$user->isAllowed( 'comment-delete-own' ) && $comment->isOwner( $user )
 | 
			
		||||
			) ||
 | 
			
		||||
			wfReadOnly()
 | 
			
		||||
		) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$comment = Comment::newFromID( $this->getMain()->getVal( 'commentID' ) );
 | 
			
		||||
		$comment->delete();
 | 
			
		||||
 | 
			
		||||
		$result = $this->getResult();
 | 
			
		||||
@@ -31,11 +35,11 @@ class CommentDeleteAPI extends ApiBase {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getAllowedParams() {
 | 
			
		||||
		return array(
 | 
			
		||||
			'commentID' => array(
 | 
			
		||||
		return [
 | 
			
		||||
			'commentID' => [
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			)
 | 
			
		||||
		);
 | 
			
		||||
			]
 | 
			
		||||
		];
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -3,6 +3,9 @@
 | 
			
		||||
class CommentLatestIdAPI extends ApiBase {
 | 
			
		||||
 | 
			
		||||
	public function execute() {
 | 
			
		||||
		// To avoid API warning, register the parameter used to bust browser cache
 | 
			
		||||
		$this->getMain()->getVal( '_' );
 | 
			
		||||
 | 
			
		||||
		$pageID = $this->getMain()->getVal( 'pageID' );
 | 
			
		||||
 | 
			
		||||
		$commentsPage = new CommentsPage( $pageID, RequestContext::getMain() );
 | 
			
		||||
@@ -12,11 +15,11 @@ class CommentLatestIdAPI extends ApiBase {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getAllowedParams() {
 | 
			
		||||
		return array(
 | 
			
		||||
			'pageID' => array(
 | 
			
		||||
		return [
 | 
			
		||||
			'pageID' => [
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'int'
 | 
			
		||||
			)
 | 
			
		||||
		);
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			]
 | 
			
		||||
		];
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -22,23 +22,23 @@ class CommentListAPI extends ApiBase {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getAllowedParams() {
 | 
			
		||||
		return array(
 | 
			
		||||
			'pageID' => array(
 | 
			
		||||
		return [
 | 
			
		||||
			'pageID' => [
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			),
 | 
			
		||||
			'order' => array(
 | 
			
		||||
			],
 | 
			
		||||
			'order' => [
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'boolean'
 | 
			
		||||
			),
 | 
			
		||||
			'pagerPage' => array(
 | 
			
		||||
			],
 | 
			
		||||
			'pagerPage' => [
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			),
 | 
			
		||||
			'showForm' => array(
 | 
			
		||||
			],
 | 
			
		||||
			'showForm' => [
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => false,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			)
 | 
			
		||||
		);
 | 
			
		||||
			]
 | 
			
		||||
		];
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -1,79 +1,79 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
class CommentSubmitAPI extends ApiBase {
 | 
			
		||||
 | 
			
		||||
	public function execute() {
 | 
			
		||||
		$user = $this->getUser();
 | 
			
		||||
		// Blocked users cannot submit new comments, and neither can those users
 | 
			
		||||
		// without the necessary privileges. Also prevent obvious cross-site request
 | 
			
		||||
		// forgeries (CSRF)
 | 
			
		||||
		if (
 | 
			
		||||
			$user->isBlocked() ||
 | 
			
		||||
			!$user->isAllowed( 'comment' ) ||
 | 
			
		||||
			wfReadOnly()
 | 
			
		||||
		) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$commentText = $this->getMain()->getVal( 'commentText' );
 | 
			
		||||
 | 
			
		||||
		if ( $commentText != '' ) {
 | 
			
		||||
			// To protect against spam, it's necessary to check the supplied text
 | 
			
		||||
			// against spam filters (but comment admins are allowed to bypass the
 | 
			
		||||
			// spam filters)
 | 
			
		||||
			if ( !$user->isAllowed( 'commentadmin' ) && CommentFunctions::isSpam( $commentText ) ) {
 | 
			
		||||
				$this->dieUsage( wfMessage( 'comments-is-spam' )->plain(), 'comments-is-spam' );
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			// If the comment contains links but the user isn't allowed to post
 | 
			
		||||
			// links, reject the submission
 | 
			
		||||
			if ( !$user->isAllowed( 'commentlinks' ) && CommentFunctions::haveLinks( $commentText ) ) {
 | 
			
		||||
				$this->dieUsage( wfMessage( 'comments-links-are-forbidden' )->plain(), 'comments-links-are-forbidden' );
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			$page = new CommentsPage( $this->getMain()->getVal( 'pageID' ), $this->getContext() );
 | 
			
		||||
 | 
			
		||||
			Comment::add( $commentText, $page, $user, $this->getMain()->getVal( 'parentID' ) );
 | 
			
		||||
 | 
			
		||||
			if ( class_exists( 'UserStatsTrack' ) ) {
 | 
			
		||||
				$stats = new UserStatsTrack( $user->getID(), $user->getName() );
 | 
			
		||||
				$stats->incStatField( 'comment' );
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
        $kok_username = $this->getMain()->getVal( 'UsernameKOK' );
 | 
			
		||||
 | 
			
		||||
		$result = $this->getResult();
 | 
			
		||||
		$result->addValue( $this->getModuleName(), 'ok', 'ok' );
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function needsToken() {
 | 
			
		||||
		return 'csrf';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function isWriteMode() {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getAllowedParams() {
 | 
			
		||||
		return array(
 | 
			
		||||
			'pageID' => array(
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			),
 | 
			
		||||
			'parentID' => array(
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => false,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			),
 | 
			
		||||
			'commentText' => array(
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'string'
 | 
			
		||||
			),
 | 
			
		||||
			'UsernameKOK' => array(
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => false,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'string'
 | 
			
		||||
			)
 | 
			
		||||
		);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
class CommentSubmitAPI extends ApiBase {
 | 
			
		||||
 | 
			
		||||
	public function execute() {
 | 
			
		||||
		$user = $this->getUser();
 | 
			
		||||
		// Blocked users cannot submit new comments, and neither can those users
 | 
			
		||||
		// without the necessary privileges. Also prevent obvious cross-site request
 | 
			
		||||
		// forgeries (CSRF)
 | 
			
		||||
		if (
 | 
			
		||||
			$user->isBlocked() ||
 | 
			
		||||
			!$user->isAllowed( 'comment' ) ||
 | 
			
		||||
			wfReadOnly()
 | 
			
		||||
		) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$commentText = $this->getMain()->getVal( 'commentText' );
 | 
			
		||||
 | 
			
		||||
		if ( $commentText != '' ) {
 | 
			
		||||
			// To protect against spam, it's necessary to check the supplied text
 | 
			
		||||
			// against spam filters (but comment admins are allowed to bypass the
 | 
			
		||||
			// spam filters)
 | 
			
		||||
			if ( !$user->isAllowed( 'commentadmin' ) && CommentFunctions::isSpam( $commentText ) ) {
 | 
			
		||||
				$this->dieWithError(
 | 
			
		||||
					$this->msg( 'comments-is-spam' )->plain(),
 | 
			
		||||
					'comments-is-spam'
 | 
			
		||||
				);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			// If the comment contains links but the user isn't allowed to post
 | 
			
		||||
			// links, reject the submission
 | 
			
		||||
			if ( !$user->isAllowed( 'commentlinks' ) && CommentFunctions::haveLinks( $commentText ) ) {
 | 
			
		||||
				$this->dieWithError(
 | 
			
		||||
					$this->msg( 'comments-links-are-forbidden' )->plain(),
 | 
			
		||||
					'comments-links-are-forbidden'
 | 
			
		||||
				);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			$page = new CommentsPage( $this->getMain()->getVal( 'pageID' ), $this->getContext() );
 | 
			
		||||
 | 
			
		||||
			Comment::add( $commentText, $page, $user, $this->getMain()->getVal( 'parentID' ) );
 | 
			
		||||
 | 
			
		||||
			if ( class_exists( 'UserStatsTrack' ) ) {
 | 
			
		||||
				$stats = new UserStatsTrack( $user->getId(), $user->getName() );
 | 
			
		||||
				$stats->incStatField( 'comment' );
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$result = $this->getResult();
 | 
			
		||||
		$result->addValue( $this->getModuleName(), 'ok', 'ok' );
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function needsToken() {
 | 
			
		||||
		return 'csrf';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function isWriteMode() {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getAllowedParams() {
 | 
			
		||||
		return [
 | 
			
		||||
			'pageID' => [
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			],
 | 
			
		||||
			'parentID' => [
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => false,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			],
 | 
			
		||||
			'commentText' => [
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'string'
 | 
			
		||||
			]
 | 
			
		||||
		];
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -3,10 +3,11 @@
 | 
			
		||||
class CommentVoteAPI extends ApiBase {
 | 
			
		||||
 | 
			
		||||
	public function execute() {
 | 
			
		||||
		$user = $this->getUser();
 | 
			
		||||
		// Blocked users cannot vote, obviously, and neither can those users without the necessary privileges
 | 
			
		||||
		if (
 | 
			
		||||
			$this->getUser()->isBlocked() ||
 | 
			
		||||
			!$this->getUser()->isAllowed( 'comment' ) ||
 | 
			
		||||
			$user->isBlocked() ||
 | 
			
		||||
			!$user->isAllowed( 'comment' ) ||
 | 
			
		||||
			wfReadOnly()
 | 
			
		||||
		) {
 | 
			
		||||
			return '';
 | 
			
		||||
@@ -22,7 +23,7 @@ class CommentVoteAPI extends ApiBase {
 | 
			
		||||
			$html = htmlspecialchars( $html );
 | 
			
		||||
 | 
			
		||||
			if ( class_exists( 'UserStatsTrack' ) ) {
 | 
			
		||||
				$stats = new UserStatsTrack( $this->getUser()->getID(), $this->getUser()->getName() );
 | 
			
		||||
				$stats = new UserStatsTrack( $user->getId(), $user->getName() );
 | 
			
		||||
 | 
			
		||||
				// Must update stats for user doing the voting
 | 
			
		||||
				if ( $voteValue == 1 ) {
 | 
			
		||||
@@ -58,15 +59,15 @@ class CommentVoteAPI extends ApiBase {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getAllowedParams() {
 | 
			
		||||
		return array(
 | 
			
		||||
			'commentID' => array(
 | 
			
		||||
		return [
 | 
			
		||||
			'commentID' => [
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			),
 | 
			
		||||
			'voteValue' => array(
 | 
			
		||||
			],
 | 
			
		||||
			'voteValue' => [
 | 
			
		||||
				ApiBase::PARAM_REQUIRED => true,
 | 
			
		||||
				ApiBase::PARAM_TYPE => 'integer'
 | 
			
		||||
			),
 | 
			
		||||
		);
 | 
			
		||||
			],
 | 
			
		||||
		];
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										121
									
								
								includes/parser/DisplayComments.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								includes/parser/DisplayComments.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,121 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
class DisplayComments {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Callback function for onParserFirstCallInit(),
 | 
			
		||||
	 * displays comments.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param $input
 | 
			
		||||
	 * @param array $args
 | 
			
		||||
	 * @param Parser $parser
 | 
			
		||||
	 * @return string HTML
 | 
			
		||||
	 */
 | 
			
		||||
	public static function getParserHandler( $input, $args, $parser ) {
 | 
			
		||||
		global $wgCommentsSortDescending;
 | 
			
		||||
 | 
			
		||||
		$po = $parser->getOutput();
 | 
			
		||||
		$po->updateCacheExpiry( 0 );
 | 
			
		||||
		// If an unclosed <comments> tag is added to a page, the extension will
 | 
			
		||||
		// go to an infinite loop...this protects against that condition.
 | 
			
		||||
		$parser->setHook( 'comments', [ __CLASS__, 'nonDisplayComments' ] );
 | 
			
		||||
 | 
			
		||||
		$title = $parser->getTitle();
 | 
			
		||||
		if ( $title->getArticleID() == 0 && $title->getDBkey() == 'CommentListGet' ) {
 | 
			
		||||
			return self::nonDisplayComments( $input, $args, $parser );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Add required CSS & JS via ResourceLoader
 | 
			
		||||
		$po->addModuleStyles( 'ext.comments.css' );
 | 
			
		||||
		$po->addModules( 'ext.comments.js' );
 | 
			
		||||
		$po->addJsConfigVars( [ 'wgCommentsSortDescending' => $wgCommentsSortDescending ] );
 | 
			
		||||
 | 
			
		||||
		// Parse arguments
 | 
			
		||||
		// The preg_match() lines here are to support the old-style way of
 | 
			
		||||
		// adding arguments:
 | 
			
		||||
		// <comments>
 | 
			
		||||
		// Allow=Foo,Bar
 | 
			
		||||
		// Voting=Plus
 | 
			
		||||
		// </comments>
 | 
			
		||||
		// whereas the normal, standard MediaWiki style, which this extension
 | 
			
		||||
		// also supports is: <comments allow="Foo,Bar" voting="Plus" />
 | 
			
		||||
		$allow = '';
 | 
			
		||||
		if ( preg_match( '/^\s*Allow\s*=\s*(.*)/mi', $input, $matches ) ) {
 | 
			
		||||
			$allow = htmlspecialchars( $matches[1] );
 | 
			
		||||
		} elseif ( !empty( $args['allow'] ) ) {
 | 
			
		||||
			$allow = $args['allow'];
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$voting = '';
 | 
			
		||||
		if ( preg_match( '/^\s*Voting\s*=\s*(.*)/mi', $input, $matches ) ) {
 | 
			
		||||
			$voting = htmlspecialchars( $matches[1] );
 | 
			
		||||
		} elseif (
 | 
			
		||||
			!empty( $args['voting'] ) &&
 | 
			
		||||
			in_array( strtoupper( $args['voting'] ), [ 'OFF', 'PLUS', 'MINUS' ] )
 | 
			
		||||
		) {
 | 
			
		||||
			$voting = $args['voting'];
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Create a new context to execute the CommentsPage
 | 
			
		||||
		$context = new RequestContext;
 | 
			
		||||
		$context->setTitle( $title );
 | 
			
		||||
		$context->setRequest( new FauxRequest() );
 | 
			
		||||
		$context->setUser( $parser->getUser() );
 | 
			
		||||
		$context->setLanguage( $parser->getTargetLanguage() );
 | 
			
		||||
 | 
			
		||||
		$commentsPage = new CommentsPage( $title->getArticleID(), $context );
 | 
			
		||||
		$commentsPage->allow = $allow;
 | 
			
		||||
		$commentsPage->setVoting( $voting );
 | 
			
		||||
 | 
			
		||||
		$output = '<div class="comments-body">';
 | 
			
		||||
 | 
			
		||||
		if ( $wgCommentsSortDescending ) { // form before comments
 | 
			
		||||
			$output .= '<a id="end" rel="nofollow"></a>';
 | 
			
		||||
			if ( !wfReadOnly() ) {
 | 
			
		||||
				$output .= $commentsPage->displayForm();
 | 
			
		||||
			} else {
 | 
			
		||||
				$output .= wfMessage( 'comments-db-locked' )->parse();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$output .= $commentsPage->displayOrderForm();
 | 
			
		||||
 | 
			
		||||
		$output .= '<div id="allcomments">' . $commentsPage->display() . '</div>';
 | 
			
		||||
 | 
			
		||||
		// If the database is in read-only mode, display a message informing the
 | 
			
		||||
		// user about that, otherwise allow them to comment
 | 
			
		||||
		if ( !$wgCommentsSortDescending ) { // form after comments
 | 
			
		||||
			if ( !wfReadOnly() ) {
 | 
			
		||||
				$output .= $commentsPage->displayForm();
 | 
			
		||||
			} else {
 | 
			
		||||
				$output .= wfMessage( 'comments-db-locked' )->parse();
 | 
			
		||||
			}
 | 
			
		||||
			$output .= '<a id="end" rel="nofollow"></a>';
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$output .= '</div>'; // div.comments-body
 | 
			
		||||
 | 
			
		||||
		return $output;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static function nonDisplayComments( $input, $args, $parser ) {
 | 
			
		||||
		$attr = [];
 | 
			
		||||
 | 
			
		||||
		foreach ( $args as $name => $value ) {
 | 
			
		||||
			$attr[] = htmlspecialchars( $name ) . '="' . htmlspecialchars( $value ) . '"';
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$output = '<comments';
 | 
			
		||||
		if ( count( $attr ) > 0 ) {
 | 
			
		||||
			$output .= ' ' . implode( ' ', $attr );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if ( !is_null( $input ) ) {
 | 
			
		||||
			$output .= '>' . htmlspecialchars( $input ) . '</comments>';
 | 
			
		||||
		} else {
 | 
			
		||||
			$output .= ' />';
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return $output;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -5,22 +5,12 @@ class NumberOfComments {
 | 
			
		||||
	 * Registers NUMBEROFCOMMENTS and NUMPBEROFCOMMENTSPAGE as a valid magic word identifier.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param array $variableIds Array of valid magic word identifiers
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 * @return bool true
 | 
			
		||||
	 */
 | 
			
		||||
	public static function registerNumberOfCommentsMagicWord( &$variableIds ) {
 | 
			
		||||
	public static function onMagicWordwgVariableIDs( &$variableIds ) {
 | 
			
		||||
		$variableIds[] = 'NUMBEROFCOMMENTS';
 | 
			
		||||
		$variableIds[] = 'NUMBEROFCOMMENTSPAGE';
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Hook to setup parser function
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param Parser $parser
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	static function setupNumberOfCommentsPageParser( &$parser ) {
 | 
			
		||||
		$parser->setFunctionHook( 'NUMBEROFCOMMENTSPAGE', 'NumberOfComments::getNumberOfCommentsPageParser', Parser::SFH_NO_HASH );
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -40,11 +30,11 @@ class NumberOfComments {
 | 
			
		||||
	 * @param int $ret What to return to the user (in our case, the number of comments)
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	public static function getNumberOfCommentsMagic( &$parser, &$cache, &$magicWordId, &$ret ) {
 | 
			
		||||
	public static function onParserGetVariableValueSwitch( &$parser, &$cache, &$magicWordId, &$ret ) {
 | 
			
		||||
		global $wgMemc;
 | 
			
		||||
 | 
			
		||||
		if ( $magicWordId == 'NUMBEROFCOMMENTS' ) {
 | 
			
		||||
			$key = wfMemcKey( 'comments', 'magic-word' );
 | 
			
		||||
			$key = $wgMemc->makeKey( 'comments', 'magic-word' );
 | 
			
		||||
			$data = $wgMemc->get( $key );
 | 
			
		||||
			if ( $data != '' ) {
 | 
			
		||||
				// We have it in cache? Oh goody, let's just use the cached value!
 | 
			
		||||
@@ -56,11 +46,11 @@ class NumberOfComments {
 | 
			
		||||
				$ret = $data;
 | 
			
		||||
			} else {
 | 
			
		||||
				// Not cached → have to fetch it from the database
 | 
			
		||||
				$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
				$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
				$commentCount = (int)$dbr->selectField(
 | 
			
		||||
					'Comments',
 | 
			
		||||
					'COUNT(*) AS count',
 | 
			
		||||
					array(),
 | 
			
		||||
					[],
 | 
			
		||||
					__METHOD__
 | 
			
		||||
				);
 | 
			
		||||
				wfDebugLog( 'Comments', 'Got the amount of comments from DB' );
 | 
			
		||||
@@ -72,7 +62,7 @@ class NumberOfComments {
 | 
			
		||||
			}
 | 
			
		||||
		} elseif ( $magicWordId == 'NUMBEROFCOMMENTSPAGE' ) {
 | 
			
		||||
			$id = $parser->getTitle()->getArticleID();
 | 
			
		||||
			$ret = NumberOfComments::getNumberOfCommentsPage( $id );
 | 
			
		||||
			$ret = self::getNumberOfCommentsPage( $id );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return true;
 | 
			
		||||
@@ -85,7 +75,7 @@ class NumberOfComments {
 | 
			
		||||
	 * @param string $pagename Page name
 | 
			
		||||
	 * @return int Amount of comments on the given page
 | 
			
		||||
	 */
 | 
			
		||||
	static function getNumberOfCommentsPageParser( $parser, $pagename ) {
 | 
			
		||||
	static function getParserHandler( $parser, $pagename ) {
 | 
			
		||||
		$page = Title::newFromText( $pagename );
 | 
			
		||||
 | 
			
		||||
		if ( $page instanceof Title ) {
 | 
			
		||||
@@ -94,7 +84,7 @@ class NumberOfComments {
 | 
			
		||||
			$id = $parser->getTitle()->getArticleID();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return NumberOfComments::getNumberOfCommentsPage( $id );
 | 
			
		||||
		return self::getNumberOfCommentsPage( $id );
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -106,18 +96,18 @@ class NumberOfComments {
 | 
			
		||||
	static function getNumberOfCommentsPage( $pageId ) {
 | 
			
		||||
		global $wgMemc;
 | 
			
		||||
 | 
			
		||||
		$key = wfMemcKey( 'comments', 'numberofcommentspage', $pageId );
 | 
			
		||||
		$key = $wgMemc->makeKey( 'comments', 'numberofcommentspage', $pageId );
 | 
			
		||||
		$cache = $wgMemc->get( $key );
 | 
			
		||||
 | 
			
		||||
		if ( $cache ) {
 | 
			
		||||
			$val = intval( $cache );
 | 
			
		||||
		} else {
 | 
			
		||||
			$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
			$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
 | 
			
		||||
			$res = $dbr->selectField(
 | 
			
		||||
				'Comments',
 | 
			
		||||
				'COUNT(*)',
 | 
			
		||||
				array( 'Comment_Page_ID' => $pageId ),
 | 
			
		||||
				[ 'Comment_Page_ID' => $pageId ],
 | 
			
		||||
				__METHOD__
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
@@ -43,7 +43,7 @@ class CommentIgnoreList extends SpecialPage {
 | 
			
		||||
		 * Redirect anonymous users to Login Page
 | 
			
		||||
		 * It will automatically return them to the CommentIgnoreList page
 | 
			
		||||
		 */
 | 
			
		||||
		if ( $user->getID() == 0 && $user_name == '' ) {
 | 
			
		||||
		if ( $user->getId() == 0 && $user_name == '' ) {
 | 
			
		||||
			$loginPage = SpecialPage::getTitleFor( 'Userlogin' );
 | 
			
		||||
			$out->redirect( $loginPage->getLocalURL( 'returnto=Special:CommentIgnoreList' ) );
 | 
			
		||||
			return;
 | 
			
		||||
@@ -70,7 +70,7 @@ class CommentIgnoreList extends SpecialPage {
 | 
			
		||||
					$user_id = 0;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				CommentFunctions::deleteBlock( $user->getID(), $user_id );
 | 
			
		||||
				CommentFunctions::deleteBlock( $user->getId(), $user_id );
 | 
			
		||||
				if ( $user_id && class_exists( 'UserStatsTrack' ) ) {
 | 
			
		||||
					$stats = new UserStatsTrack( $user_id, $user_name );
 | 
			
		||||
					$stats->decStatField( 'comment_ignored' );
 | 
			
		||||
@@ -93,13 +93,13 @@ class CommentIgnoreList extends SpecialPage {
 | 
			
		||||
		$lang = $this->getLanguage();
 | 
			
		||||
		$title = $this->getPageTitle();
 | 
			
		||||
 | 
			
		||||
		$dbr = wfGetDB( DB_SLAVE );
 | 
			
		||||
		$dbr = wfGetDB( DB_REPLICA );
 | 
			
		||||
		$res = $dbr->select(
 | 
			
		||||
			'Comments_block',
 | 
			
		||||
			array( 'cb_user_name_blocked', 'cb_date' ),
 | 
			
		||||
			array( 'cb_user_id' => $this->getUser()->getID() ),
 | 
			
		||||
			[ 'cb_user_name_blocked', 'cb_date' ],
 | 
			
		||||
			[ 'cb_user_id' => $this->getUser()->getId() ],
 | 
			
		||||
			__METHOD__,
 | 
			
		||||
			array( 'ORDER BY' => 'cb_user_name' )
 | 
			
		||||
			[ 'ORDER BY' => 'cb_user_name' ]
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		if ( $dbr->numRows( $res ) > 0 ) {
 | 
			
		||||
		Reference in New Issue
	
	Block a user