From: PranavK Date: Wed, 13 Jan 2016 16:05:47 +0000 (+0530) Subject: Make Special:Redirect page redirect to log events by ID X-Git-Tag: 1.31.0-rc.0~8307 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=1b294bd3c538c874156d9f924200cbf659789dfb;p=lhc%2Fweb%2Fwiklou.git Make Special:Redirect page redirect to log events by ID Bug: T71107 Change-Id: I48bc6ae31e9f841f1cfeed6167c0c13c58e53f4a --- diff --git a/includes/specials/SpecialRedirect.php b/includes/specials/SpecialRedirect.php index 553e2b1235..328aa11b81 100644 --- a/includes/specials/SpecialRedirect.php +++ b/includes/specials/SpecialRedirect.php @@ -158,6 +158,93 @@ class SpecialRedirect extends FormSpecialPage { ) ); } + /** + * Handle Special:Redirect/logid/xxx + * (by redirecting to index.php?title=Special:Log) + * + * @since 1.27 + * @return string|null Url to redirect to, or null if $mValue is invalid. + */ + function dispatchLog() { + $logid = $this->mValue; + if ( !ctype_digit( $logid ) ) { + return null; + } + $logid = (int)$logid; + if ( $logid === 0 ) { + return null; + } + + $logparams = array( + 'log_id', + 'log_timestamp', + 'log_type', + 'log_user_text', + ); + + $dbr = wfGetDB( DB_SLAVE ); + + // Gets the nested SQL statement which + // returns timestamp of the log with the given log ID + $inner = $dbr->selectSQLText( + 'logging', + array( 'log_timestamp' ), + array( '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', + $logparams, + array( "log_timestamp = ($inner)" ) + ); + if ( $logsSameTimestamps->numRows() === 0 ) { + return null; + } + + // Stores the row with the same log ID as the one given + $rowMain = array(); + 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 $cond ) { + $matchedRows = array(); + foreach ( $logsSameTimestamps as $row ) { + if ( $row->$cond === $rowMain->$cond ) { + $matchedRows[] = $row; + } + } + if ( count( $matchedRows ) === 1 ) { + break; + } + $logsSameTimestamps = $matchedRows; + } + $query = array( 'title' => 'Special:Log', 'limit' => count( $matchedRows ) ); + + // A map of database field names from table 'logging' to the values of $logparams + $keys = array( + 'log_timestamp' => 'offset', + 'log_type' => 'type', + 'log_user_text' => 'user' + ); + + foreach ( $logparams as $logKey ) { + $query[$keys[$logKey]] = $matchedRows[0]->$logKey; + } + $query['offset'] = $query['offset'] + 1; + $url = $query; + + return wfAppendQuery( wfScript( 'index' ), $url ); + } + /** * Use appropriate dispatch* method to obtain a redirection URL, * and either: redirect, set a 404 error code and error message, @@ -181,6 +268,9 @@ class SpecialRedirect extends FormSpecialPage { case 'page': $url = $this->dispatchPage(); break; + case 'logid': + $url = $this->dispatchLog(); + break; default: $this->getOutput()->setStatusCode( 404 ); $url = null; @@ -207,11 +297,12 @@ class SpecialRedirect extends FormSpecialPage { $ns = array( // subpage => message // Messages: redirect-user, redirect-page, redirect-revision, - // redirect-file + // redirect-file, redirect-logid 'user' => $mp . '-user', 'page' => $mp . '-page', 'revision' => $mp . '-revision', 'file' => $mp . '-file', + 'logid' => $mp . '-logid', ); $a = array(); $a['type'] = array( @@ -273,6 +364,7 @@ class SpecialRedirect extends FormSpecialPage { 'page', 'revision', 'user', + 'logid', ); } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index f1932d8a0e..f1c354a304 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3542,10 +3542,10 @@ "version-libraries-license": "License", "version-libraries-description": "Description", "version-libraries-authors": "Authors", - "redirect": "Redirect by file, user, page or revision ID", + "redirect": "Redirect by file, user, page, revision, or log ID", "redirect-legend": "Redirect to a file or page", "redirect-text": "", - "redirect-summary": "This special page redirects to a file (given the filename), a page (given a revision ID or page ID), or a user page (given a numeric user ID). Usage: [[{{#Special:Redirect}}/file/Example.jpg]], [[{{#Special:Redirect}}/page/64308]], [[{{#Special:Redirect}}/revision/328429]], or [[{{#Special:Redirect}}/user/101]].", + "redirect-summary": "This special page redirects to a file (given the filename), a page (given a revision ID or page ID), a user page (given a numeric user ID), or a log entry (given the log ID). Usage: [[{{#Special:Redirect}}/file/Example.jpg]], [[{{#Special:Redirect}}/page/64308]], [[{{#Special:Redirect}}/revision/328429]], [[{{#Special:Redirect}}/user/101]], or [[{{#Special:Redirect}}/logid/186]].", "redirect-submit": "Go", "redirect-lookup": "Lookup:", "redirect-value": "Value:", @@ -3553,6 +3553,7 @@ "redirect-page": "Page ID", "redirect-revision": "Page revision", "redirect-file": "Filename", + "redirect-logid": "Log ID", "redirect-not-exists": "Value not found", "fileduplicatesearch": "Search for duplicate files", "fileduplicatesearch-summary": "Search for duplicate files based on hash values.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 28e52719eb..06f4fe635a 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -3728,6 +3728,7 @@ "redirect-page": "Description of lookup type for [[Special:Redirect]].\n{{Identical|Page ID}}", "redirect-revision": "Description of lookup type for [[Special:Redirect]].\n\nThis means \"Page revision '''ID'''\".", "redirect-file": "Description of lookup type for [[Special:Redirect]].\n{{Identical|Filename}}", + "redirect-logid": "Description of lookup type for [[Special:Redirect]].\n{{Identical|Log ID}}", "redirect-not-exists": "Used as error message in [[Special:Redirect]]", "fileduplicatesearch": "Name of special page [[Special:FileDuplicateSearch]].", "fileduplicatesearch-summary": "Summary of [[Special:FileDuplicateSearch]]",