| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
m |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
use MediaWiki\Logger\LoggerFactory; |
| 27 |
use MediaWiki\Logging\LoggingSelectQueryBuilder; |
| 28 |
use MediaWiki\MediaWikiServices; |
| 29 |
use MediaWiki\User\UserIdentity; |
| 30 |
use Wikimedia\AtEase\AtEase; |
| 31 |
use Wikimedia\Rdbms\IReadableDatabase; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
class DatabaseLogEntry extends LogEntryBase { |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public static function getSelectQueryData() { |
| 57 |
$commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin( 'log_comment' ); |
| 58 |
|
| 59 |
$tables = array_merge( |
| 60 |
[ |
| 61 |
'logging', |
| 62 |
'logging_actor' => 'actor', |
| 63 |
'user' |
| 64 |
], |
| 65 |
$commentQuery['tables'] |
| 66 |
); |
| 67 |
$fields = [ |
| 68 |
'log_id', 'log_type', 'log_action', 'log_timestamp', |
| 69 |
'log_namespace', 'log_title', |
| 70 |
'log_params', 'log_deleted', |
| 71 |
'user_id', |
| 72 |
'user_name', |
| 73 |
'log_actor', |
| 74 |
'log_user' => 'logging_actor.actor_user', |
| 75 |
'log_user_text' => 'logging_actor.actor_name' |
| 76 |
] + $commentQuery['fields']; |
| 77 |
|
| 78 |
$joins = [ |
| 79 |
'logging_actor' => [ 'JOIN', 'actor_id=log_actor' ], |
| 80 |
|
| 81 |
'user' => [ 'LEFT JOIN', 'user_id=logging_actor.actor_user' ], |
| 82 |
] + $commentQuery['joins']; |
| 83 |
|
| 84 |
return [ |
| 85 |
'tables' => $tables, |
| 86 |
'fields' => $fields, |
| 87 |
'conds' => [], |
| 88 |
'options' => [], |
| 89 |
'join_conds' => $joins, |
| 90 |
]; |
| 91 |
} |
| 92 |
|
| 93 |
public static function newSelectQueryBuilder( IReadableDatabase $db ) { |
| 94 |
return new LoggingSelectQueryBuilder( $db ); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public static function newFromRow( $row ) { |
| 105 |
$row = (object)$row; |
| 106 |
if ( isset( $row->rc_logid ) ) { |
| 107 |
return new RCDatabaseLogEntry( $row ); |
| 108 |
} else { |
| 109 |
return new self( $row ); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public static function newFromId( $id, IReadableDatabase $db ) { |
| 121 |
$row = self::newSelectQueryBuilder( $db ) |
| 122 |
->where( [ 'log_id' => $id ] ) |
| 123 |
->caller( __METHOD__ )->fetchRow(); |
| 124 |
if ( !$row ) { |
| 125 |
return null; |
| 126 |
} |
| 127 |
return self::newFromRow( $row ); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
protected $row; |
| 132 |
|
| 133 |
|
| 134 |
protected $performer; |
| 135 |
|
| 136 |
|
| 137 |
protected $params; |
| 138 |
|
| 139 |
|
| 140 |
protected $revId = null; |
| 141 |
|
| 142 |
|
| 143 |
protected $legacy; |
| 144 |
|
| 145 |
protected function __construct( $row ) { |
| 146 |
$this->row = $row; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
public function getId() { |
| 155 |
return (int)( $this->row->log_id ?? 0 ); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
protected function getRawParameters() { |
| 165 |
return $this->row->log_params; |
| 166 |
} |
| 167 |
|
| 168 |
public function isLegacy() { |
| 169 |
|
| 170 |
$this->getParameters(); |
| 171 |
return $this->legacy; |
| 172 |
} |
| 173 |
|
| 174 |
public function getType() { |
| 175 |
return $this->row->log_type; |
| 176 |
} |
| 177 |
|
| 178 |
public function getSubtype() { |
| 179 |
return $this->row->log_action; |
| 180 |
} |
| 181 |
|
| 182 |
public function getParameters() { |
| 183 |
if ( !isset( $this->params ) ) { |
| 184 |
$blob = $this->getRawParameters(); |
| 185 |
AtEase::suppressWarnings(); |
| 186 |
$params = LogEntryBase::extractParams( $blob, $this->getFullType() ); |
| 187 |
AtEase::restoreWarnings(); |
| 188 |
if ( $params !== false ) { |
| 189 |
$this->params = $params; |
| 190 |
$this->legacy = false; |
| 191 |
} else { |
| 192 |
$this->params = LogPage::extractParams( $blob ); |
| 193 |
$this->legacy = true; |
| 194 |
} |
| 195 |
|
| 196 |
if ( isset( $this->params['associated_rev_id'] ) ) { |
| 197 |
$this->revId = $this->params['associated_rev_id']; |
| 198 |
unset( $this->params['associated_rev_id'] ); |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
return $this->params; |
| 203 |
} |
| 204 |
|
| 205 |
public function getAssociatedRevId() { |
| 206 |
|
| 207 |
$this->getParameters(); |
| 208 |
return $this->revId; |
| 209 |
} |
| 210 |
|
| 211 |
public function getPerformerIdentity(): UserIdentity { |
| 212 |
if ( !$this->performer ) { |
| 213 |
$actorStore = MediaWikiServices::getInstance()->getActorStore(); |
| 214 |
try { |
| 215 |
$this->performer = $actorStore->newActorFromRowFields( |
| 216 |
$this->row->user_id ?? 0, |
| 217 |
$this->row->log_user_text ?? null, |
| 218 |
$this->row->log_actor ?? null |
| 219 |
); |
| 220 |
} catch ( InvalidArgumentException $e ) { |
| 221 |
LoggerFactory::getInstance( 'logentry' )->warning( |
| 222 |
'Failed to instantiate log entry performer', [ |
| 223 |
'exception' => $e, |
| 224 |
'log_id' => $this->getId() |
| 225 |
] |
| 226 |
); |
| 227 |
$this->performer = $actorStore->getUnknownActor(); |
| 228 |
} |
| 229 |
} |
| 230 |
return $this->performer; |
| 231 |
} |
| 232 |
|
| 233 |
public function getTarget() { |
| 234 |
$namespace = $this->row->log_namespace; |
| 235 |
$page = $this->row->log_title; |
| 236 |
return MediaWikiServices::getInstance()->getTitleFactory()->makeTitle( $namespace, $page ); |
| 237 |
} |
| 238 |
|
| 239 |
public function getTimestamp() { |
| 240 |
return wfTimestamp( TS_MW, $this->row->log_timestamp ); |
| 241 |
} |
| 242 |
|
| 243 |
public function getComment() { |
| 244 |
return MediaWikiServices::getInstance()->getCommentStore() |
| 245 |
->getComment( 'log_comment', $this->row )->text; |
| 246 |
} |
| 247 |
|
| 248 |
public function getDeleted() { |
| 249 |
return $this->row->log_deleted; |
| 250 |
} |
| 251 |
} |