| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\AbuseFilter; |
| 4 |
|
| 5 |
use HtmlArmor; |
| 6 |
use LogFormatter; |
| 7 |
use MediaWiki\Context\IContextSource; |
| 8 |
use MediaWiki\Linker\Linker; |
| 9 |
use MediaWiki\MediaWikiServices; |
| 10 |
use MediaWiki\Revision\RevisionRecord; |
| 11 |
use MediaWiki\SpecialPage\SpecialPage; |
| 12 |
use MediaWiki\Title\TitleValue; |
| 13 |
use OldChangesList; |
| 14 |
use RecentChange; |
| 15 |
|
| 16 |
class AbuseFilterChangesList extends OldChangesList { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
private $testFilter; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
private array $rcResults = []; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function __construct( IContextSource $context, $testFilter ) { |
| 33 |
parent::__construct( $context ); |
| 34 |
$this->testFilter = $testFilter; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function insertExtra( &$s, &$rc, &$classes ) { |
| 43 |
if ( (int)$rc->getAttribute( 'rc_deleted' ) !== 0 ) { |
| 44 |
$s .= ' ' . $this->msg( 'abusefilter-log-hidden-implicit' )->parse(); |
| 45 |
if ( !AbuseFilterPermissionManager::hasRCEntryAccess( $rc, $this->getAuthority() ) ) { |
| 46 |
|
| 47 |
return; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
$examineParams = []; |
| 52 |
if ( $this->testFilter && strlen( $this->testFilter ) < 2000 ) { |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
$examineParams['testfilter'] = $this->testFilter; |
| 57 |
} |
| 58 |
|
| 59 |
$rcid = $rc->getAttribute( 'rc_id' ); |
| 60 |
$title = SpecialPage::getTitleFor( 'AbuseFilter', 'examine/' . $rcid ); |
| 61 |
$examineLink = $this->linkRenderer->makeLink( |
| 62 |
$title, |
| 63 |
new HtmlArmor( $this->msg( 'abusefilter-changeslist-examine' )->parse() ), |
| 64 |
[], |
| 65 |
$examineParams |
| 66 |
); |
| 67 |
|
| 68 |
$s .= ' ' . $this->msg( 'parentheses' )->rawParams( $examineLink )->escaped(); |
| 69 |
|
| 70 |
|
| 71 |
if ( isset( $this->rcResults[$rcid] ) ) { |
| 72 |
$class = $this->rcResults[$rcid] ? |
| 73 |
'mw-abusefilter-changeslist-match' : |
| 74 |
'mw-abusefilter-changeslist-nomatch'; |
| 75 |
|
| 76 |
$classes[] = $class; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) { |
| 85 |
$par = parent::recentChangesLine( $rc, $watched, $linenumber ); |
| 86 |
if ( $par === false || $par === '' ) { |
| 87 |
return $par; |
| 88 |
} |
| 89 |
$ret = preg_replace( '/<\/li>$/', '', $par ); |
| 90 |
if ( $rc->getAttribute( 'rc_source' ) === 'flow' ) { |
| 91 |
$classes = []; |
| 92 |
$this->insertExtra( $ret, $rc, $classes ); |
| 93 |
} |
| 94 |
return $ret . '</li>'; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public function insertUserRelatedLinks( &$s, &$rc ) { |
| 105 |
$links = $this->getLanguage()->getDirMark() . Linker::userLink( $rc->getAttribute( 'rc_user' ), |
| 106 |
$rc->getAttribute( 'rc_user_text' ) ) . |
| 107 |
Linker::userToolLinks( $rc->getAttribute( 'rc_user' ), $rc->getAttribute( 'rc_user_text' ) ); |
| 108 |
|
| 109 |
if ( $this->isDeleted( $rc, RevisionRecord::DELETED_USER ) ) { |
| 110 |
if ( $this->userCan( $rc, RevisionRecord::DELETED_USER ) ) { |
| 111 |
$s .= ' <span class="history-deleted">' . $links . '</span>'; |
| 112 |
} else { |
| 113 |
$s .= ' <span class="history-deleted">' . |
| 114 |
$this->msg( 'rev-deleted-user' )->escaped() . '</span>'; |
| 115 |
} |
| 116 |
} else { |
| 117 |
$s .= $links; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public function insertComment( $rc ) { |
| 127 |
if ( $this->isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) { |
| 128 |
if ( $this->userCan( $rc, RevisionRecord::DELETED_COMMENT ) ) { |
| 129 |
return ' <span class="history-deleted">' . |
| 130 |
MediaWikiServices::getInstance()->getCommentFormatter() |
| 131 |
->formatBlock( |
| 132 |
$rc->getAttribute( 'rc_comment' ), |
| 133 |
TitleValue::castPageToLinkTarget( $rc->getPage() ) |
| 134 |
) . '</span>'; |
| 135 |
} else { |
| 136 |
return ' <span class="history-deleted">' . |
| 137 |
$this->msg( 'rev-deleted-comment' )->escaped() . '</span>'; |
| 138 |
} |
| 139 |
} else { |
| 140 |
return MediaWikiServices::getInstance()->getCommentFormatter() |
| 141 |
->formatBlock( $rc->getAttribute( 'rc_comment' ), TitleValue::castPageToLinkTarget( $rc->getPage() ) ); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
public function insertLogEntry( $rc ) { |
| 152 |
$formatter = MediaWikiServices::getInstance()->getLogFormatterFactory()->newFromRow( $rc->getAttributes() ); |
| 153 |
$formatter->setContext( $this->getContext() ); |
| 154 |
$formatter->setAudience( LogFormatter::FOR_THIS_USER ); |
| 155 |
$formatter->setShowUserToolLinks( true ); |
| 156 |
$mark = $this->getLanguage()->getDirMark(); |
| 157 |
return $formatter->getActionText() . " $mark" . $formatter->getComment(); |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
public function insertRollback( &$s, &$rc ) { |
| 165 |
|
| 166 |
} |
| 167 |
|
| 168 |
public function setRCResult( RecentChange $rc, bool $matches ): void { |
| 169 |
$id = $rc->getAttribute( 'rc_id' ); |
| 170 |
$this->rcResults[$id] = $matches; |
| 171 |
} |
| 172 |
} |