From: Sam Wilson Date: Mon, 23 Apr 2018 03:55:24 +0000 (+0800) Subject: Add 'logid' parameter to Special:Log X-Git-Tag: 1.31.1~19 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=def02ea00c02fcd6e7548683e9cbe9141f1a26e6 Add 'logid' parameter to Special:Log Make it possible to get a URL for a single log entry, as an alternative to using Special:Redirect/logid/123. The existing single-log-entry link of Special:Redirect/logid/123 is also simplified to be a redirect to this new parameter. Bug: T191608 Bug: T187638 Change-Id: I5f2e52531cd2ba617a25570e40aa8c5168e284d9 (cherry picked from commit 8e04e60113272d498070e51ff2b50412ae7a9234) --- diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31 index 60b6c277ef..4331e4f457 100644 --- a/RELEASE-NOTES-1.31 +++ b/RELEASE-NOTES-1.31 @@ -9,6 +9,7 @@ This is a security and maintenance release of the MediaWiki 1.31 branch. * (T193995) Fix undefined patchPath() method call in parser tests. * (T198687) Fix various selectFields methods to use the string 'NULL', not null. * Special:BotPasswords now requires reauthentication. +* (T191608, T187638) Add 'logid' parameter to Special:Log. == MediaWiki 1.31 == diff --git a/includes/logging/LogPager.php b/includes/logging/LogPager.php index 24fdfb0195..c047e96ea3 100644 --- a/includes/logging/LogPager.php +++ b/includes/logging/LogPager.php @@ -65,10 +65,11 @@ class LogPager extends ReverseChronologicalPager { * @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; @@ -81,6 +82,7 @@ class LogPager extends ReverseChronologicalPager { $this->limitAction( $action ); $this->getDateCond( $year, $month ); $this->mTagFilter = $tagFilter; + $this->limitLogId( $logId ); $this->mDb = wfGetDB( DB_REPLICA, 'logpager' ); } @@ -278,6 +280,17 @@ class LogPager extends ReverseChronologicalPager { } } + /** + * 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. diff --git a/includes/specials/SpecialLog.php b/includes/specials/SpecialLog.php index 6a11bf4d94..bad17466b5 100644 --- a/includes/specials/SpecialLog.php +++ b/includes/specials/SpecialLog.php @@ -51,6 +51,7 @@ class SpecialLog extends SpecialPage { $opts->add( 'dir', '' ); $opts->add( 'offender', '' ); $opts->add( 'subtype', '' ); + $opts->add( 'logid', '' ); // Set values $opts->fetchValuesFromRequest( $this->getRequest() ); @@ -169,6 +170,16 @@ class SpecialLog extends SpecialPage { 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 : ''; @@ -204,7 +215,8 @@ class SpecialLog extends SpecialPage { $opts->getValue( 'year' ), $opts->getValue( 'month' ), $opts->getValue( 'tagfilter' ), - $opts->getValue( 'subtype' ) + $opts->getValue( 'subtype' ), + $opts->getValue( 'logid' ) ); $this->addHeader( $opts->getValue( 'type' ) ); diff --git a/includes/specials/SpecialRedirect.php b/includes/specials/SpecialRedirect.php index 36e777940e..e827911382 100644 --- a/includes/specials/SpecialRedirect.php +++ b/includes/specials/SpecialRedirect.php @@ -162,7 +162,7 @@ class SpecialRedirect extends FormSpecialPage { /** * 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. @@ -176,80 +176,8 @@ class SpecialRedirect extends FormSpecialPage { 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 ); } /**