* @param int|bool $month The month to start from. Default: false
* @param string $tagFilter Tag
* @param string $action Specific action (subtype) requested
+ * @param int $logId Log entry ID, to limit to a single log entry.
*/
public function __construct( $list, $types = [], $performer = '', $title = '',
$pattern = '', $conds = [], $year = false, $month = false, $tagFilter = '',
- $action = ''
+ $action = '', $logId = false
) {
parent::__construct( $list->getContext() );
$this->mConds = $conds;
$this->limitAction( $action );
$this->getDateCond( $year, $month );
$this->mTagFilter = $tagFilter;
+ $this->limitLogId( $logId );
$this->mDb = wfGetDB( DB_REPLICA, 'logpager' );
}
}
}
+ /**
+ * Limit to the (single) specified log ID.
+ * @param int $logId The log entry ID.
+ */
+ protected function limitLogId( $logId ) {
+ if ( !$logId ) {
+ return;
+ }
+ $this->mConds['log_id'] = $logId;
+ }
+
/**
* Constructs the most part of the query. Extra conditions are sprinkled in
* all over this class.
$opts->add( 'dir', '' );
$opts->add( 'offender', '' );
$opts->add( 'subtype', '' );
+ $opts->add( 'logid', '' );
// Set values
$opts->fetchValuesFromRequest( $this->getRequest() );
return $subpages;
}
+ /**
+ * Set options based on the subpage title parts:
+ * - One part that is a valid log type: Special:Log/logtype
+ * - Two parts: Special:Log/logtype/username
+ * - Otherwise, assume the whole subpage is a username.
+ *
+ * @param FormOptions $opts
+ * @param $par
+ * @throws ConfigException
+ */
private function parseParams( FormOptions $opts, $par ) {
# Get parameters
$par = $par !== null ? $par : '';
$opts->getValue( 'year' ),
$opts->getValue( 'month' ),
$opts->getValue( 'tagfilter' ),
- $opts->getValue( 'subtype' )
+ $opts->getValue( 'subtype' ),
+ $opts->getValue( 'logid' )
);
$this->addHeader( $opts->getValue( 'type' ) );
/**
* Handle Special:Redirect/logid/xxx
- * (by redirecting to index.php?title=Special:Log)
+ * (by redirecting to index.php?title=Special:Log&logid=xxx)
*
* @since 1.27
* @return string|null Url to redirect to, or null if $mValue is invalid.
if ( $logid === 0 ) {
return null;
}
-
- $logQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
-
- $logparams = [
- 'log_id' => 'log_id',
- 'log_timestamp' => 'log_timestamp',
- 'log_type' => 'log_type',
- 'log_user_text' => $logQuery['fields']['log_user_text'],
- ];
-
- $dbr = wfGetDB( DB_REPLICA );
-
- // Gets the nested SQL statement which
- // returns timestamp of the log with the given log ID
- $inner = $dbr->selectSQLText(
- 'logging',
- [ 'log_timestamp' ],
- [ 'log_id' => $logid ]
- );
-
- // Returns all fields mentioned in $logparams of the logs
- // with the same timestamp as the one returned by the statement above
- $logsSameTimestamps = $dbr->select(
- [ 'logging' ] + $logQuery['tables'],
- $logparams,
- [ "log_timestamp = ($inner)" ],
- __METHOD__,
- [],
- $logQuery['joins']
- );
- if ( $logsSameTimestamps->numRows() === 0 ) {
- return null;
- }
-
- // Stores the row with the same log ID as the one given
- $rowMain = [];
- foreach ( $logsSameTimestamps as $row ) {
- if ( (int)$row->log_id === $logid ) {
- $rowMain = $row;
- }
- }
-
- array_shift( $logparams );
-
- // Stores all the rows with the same values in each column
- // as $rowMain
- foreach ( $logparams as $key => $dummy ) {
- $matchedRows = [];
- foreach ( $logsSameTimestamps as $row ) {
- if ( $row->$key === $rowMain->$key ) {
- $matchedRows[] = $row;
- }
- }
- if ( count( $matchedRows ) === 1 ) {
- break;
- }
- $logsSameTimestamps = $matchedRows;
- }
- $query = [ 'title' => 'Special:Log', 'limit' => count( $matchedRows ) ];
-
- // A map of database field names from table 'logging' to the values of $logparams
- $keys = [
- 'log_timestamp' => 'offset',
- 'log_type' => 'type',
- 'log_user_text' => 'user'
- ];
-
- foreach ( $logparams as $logKey => $dummy ) {
- $query[$keys[$logKey]] = $matchedRows[0]->$logKey;
- }
- $query['offset'] = $query['offset'] + 1;
- $url = $query;
-
- return wfAppendQuery( wfScript( 'index' ), $url );
+ $query = [ 'title' => 'Special:Log', 'logid' => $logid ];
+ return wfAppendQuery( wfScript( 'index' ), $query );
}
/**