Alex Monk has uploaded a new change for review. https://gerrit.wikimedia.org/r/224319
Change subject: Add maintenance script to fix log_search of revisions migrated to revdel ...................................................................... Add maintenance script to fix log_search of revisions migrated to revdel Bug: T62373 Change-Id: I792dbcadcbf07df16588148d7a9920d538432a16 --- A fixMigratedLogSearch.php 1 file changed, 134 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Oversight refs/changes/19/224319/1 diff --git a/fixMigratedLogSearch.php b/fixMigratedLogSearch.php new file mode 100644 index 0000000..5df18f7 --- /dev/null +++ b/fixMigratedLogSearch.php @@ -0,0 +1,134 @@ +<?php +/** + * Fix log_search for revisions migrated from the Oversight extension to revdel. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Maintenance + */ + +// Detect $IP +$IP = getenv( 'MW_INSTALL_PATH' ); +if ( $IP === false ) { + $IP = __DIR__ . '/../..'; +} + +// Require base maintenance class +require_once( "$IP/maintenance/Maintenance.php" ); +/** + * Fix log_search for revisions migrated from the Oversight extension to revdel. + * + * @ingroup Maintenance + */ +class FixMigratedOversightRevisions extends Maintenance { + public function __construct() { + parent::__construct(); + $this->setBatchSize( 20 ); + $this->mDescription = "Fix log_search for revisions migrated from the Oversight extension to revdel."; + $this->addOption( 'fix', "Turn off dry-run mode and actually insert OS data into revision/archive table." ); + } + + public function execute() { + $this->output( "Fixing log_search for revisions migrated from the Oversight extension to revdel.\n" ); + if ( !$this->hasOption( 'fix' ) ) { + $this->output( "Dry-run mode on. To actually fix log_search, run again with --fix.\n" ); + } + + $count = 0; + $dbw = wfGetDB( DB_MASTER ); + + $so = new SpecialOversight; // PHP 5.3 back-compat, ugh + $selectFields = array_merge( $so->getSelectFields(), array( "{$dbw->tableName('hidden')}.*" ) ); + $lastRevId = "-1"; + + do { + $hiddenRows = $dbw->select( + array( 'hidden', 'user' ), + $selectFields, + array( 'hidden_rev_id > ' . $dbw->addQuotes( $lastRevId ) ), + __METHOD__, + array( 'LIMIT' => $this->mBatchSize, 'ORDER BY' => 'hidden_rev_id' ), + array( 'user' => array( 'INNER JOIN', 'user_id = hidden_by_user' ) ) + ); + $insertLogSearchData = array(); + foreach ( $hiddenRows as $hiddenRow ) { + $latestRevision = Revision::newFromPageId( $hiddenRow->hidden_page ); + $pageExists = $latestRevision !== null; + if ( $pageExists && $latestRevision->getTimestamp() < wfTimestamp( TS_MW, $hiddenRow->hidden_timestamp ) ) { + $this->output( "Warning: Revision ID {$hiddenRow->hidden_rev_id} will be inserted into the archive (like a deleted page) instead of revision to avoid revealing suppressed information (it is newer than any live revision).\n" ); + $pageExists = false; + } + + // Hide revision text, edit summary, editor's username/IP, even from admins. + $deletedBits = Revision::DELETED_TEXT | Revision::DELETED_COMMENT | Revision::DELETED_USER | Revision::DELETED_RESTRICTED; + + $logData = array( + 'log_type' => 'suppress', + 'log_action' => 'revision', + 'log_timestamp' => $hiddenRow->hidden_on_timestamp, + 'log_user' => $hiddenRow->hidden_by_user, + 'log_namespace' => $hiddenRow->hidden_namespace, + 'log_title' => $hiddenRow->hidden_title, + 'log_page' => $hiddenRow->hidden_page, + 'log_comment' => $hiddenRow->hidden_reason, + 'log_params' => "revision\n" . $hiddenRow->hidden_rev_id . "\nofield=" . $hiddenRow->hidden_deleted . "\nnfield=" . $deletedBits, //'revision', rev_id, old bits, new bits + ); + + // Find suppression log entry ID that was generated at the time of the migration + $logID = $dbw->selectField( 'logging', 'log_id', $logData, __METHOD__ ); + + if ( !$logID ) { + $this->output( "Skipping for hidden_rev_id=" . $hiddenRow->hidden_rev_id . ", no suppression log entry found.\n" ); + continue; + } + + $insertLogSearchData[] = array( + 'ls_field' => 'rev_id', + 'ls_value' => $hiddenRow->hidden_rev_id, + 'ls_log_id' => $logID + ); + + if ( $hiddenRow->hidden_user ) { + $targetField = 'target_author_id'; + $targetValue = $hiddenRow->hidden_user; + } else { + $targetField = 'target_author_ip'; + $targetValue = $hiddenRow->hidden_user_text; + } + $insertLogSearchData[] = array( + 'ls_field' => $targetField, + 'ls_value' => $targetValue, + 'ls_log_id' => $logID + ); + + $lastRevId = $hiddenRow->hidden_rev_id; + $count++; + } + + if ( $this->getOption( 'fix' ) ) { + $dbw->insert( 'log_search', $insertLogSearchData, __METHOD__, array( 'IGNORE' ) ); + } + } while ( $hiddenRows->numRows() === $this->mBatchSize ); + + if ( $this->getOption( 'fix' ) ) { + $this->output( "Done! $count oversighted revision(s) should now be searchable.\n" ); + } + } +} + +$maintClass = "FixMigratedOversightRevisions"; +require_once( RUN_MAINTENANCE_IF_MAIN ); -- To view, visit https://gerrit.wikimedia.org/r/224319 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I792dbcadcbf07df16588148d7a9920d538432a16 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Oversight Gerrit-Branch: master Gerrit-Owner: Alex Monk <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
