Add 'logid' parameter to Special:Log
authorSam Wilson <sam@samwilson.id.au>
Mon, 23 Apr 2018 03:55:24 +0000 (11:55 +0800)
committerSam Wilson <sam@samwilson.id.au>
Fri, 4 May 2018 01:52:55 +0000 (09:52 +0800)
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

includes/logging/LogPager.php
includes/specials/SpecialLog.php
includes/specials/SpecialRedirect.php

index 24fdfb0..c047e96 100644 (file)
@@ -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.
index 6a11bf4..bad1746 100644 (file)
@@ -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' ) );
index 36e7779..e827911 100644 (file)
@@ -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 );
        }
 
        /**