2007-04-21 21:11:14 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
2007-04-21 23:19:18 +00:00
|
|
|
* Makes the required database updates for Special:ProtectedPages
|
2007-04-21 21:44:19 +00:00
|
|
|
* to show all protected pages, even ones before the page restrictions
|
|
|
|
|
* schema change. All remaining page_restriction column values are moved
|
|
|
|
|
* to the new table.
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* 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
|
|
|
|
|
*
|
2010-09-01 19:36:18 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
2007-04-21 21:11:14 +00:00
|
|
|
*/
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2007-04-21 21:11:14 +00:00
|
|
|
|
2012-09-03 18:10:09 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script that updates page_restrictions table from
|
|
|
|
|
* old page_restriction column.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class UpdateRestrictions extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Updates page_restrictions table from old page_restriction column' );
|
2017-07-19 17:35:02 +00:00
|
|
|
$this->setBatchSize( 1000 );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2007-04-21 21:11:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
2021-04-29 02:37:11 +00:00
|
|
|
$dbw = $this->getDB( DB_PRIMARY );
|
2017-11-08 03:35:11 +00:00
|
|
|
$batchSize = $this->getBatchSize();
|
2019-09-17 09:47:29 +00:00
|
|
|
|
2020-06-07 16:23:08 +00:00
|
|
|
if ( !$dbw->tableExists( 'page_restrictions', __METHOD__ ) ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "page_restrictions table does not exist" );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2007-04-21 21:11:14 +00:00
|
|
|
|
2024-09-19 19:02:52 +00:00
|
|
|
if ( !$dbw->fieldExists( 'page', 'page_restrictions', __METHOD__ ) ) {
|
2022-06-29 20:06:45 +00:00
|
|
|
$this->output( "Migration is not needed.\n" );
|
2022-05-24 08:51:57 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 09:47:29 +00:00
|
|
|
$encodedExpiry = $dbw->getInfinity();
|
|
|
|
|
|
2023-09-21 11:54:38 +00:00
|
|
|
$maxPageId = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( 'MAX(page_id)' )
|
|
|
|
|
->from( 'page' )
|
|
|
|
|
->caller( __METHOD__ )->fetchField();
|
2019-09-17 09:47:29 +00:00
|
|
|
|
|
|
|
|
$batchMinPageId = 0;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
$batchMaxPageId = $batchMinPageId + $batchSize;
|
|
|
|
|
|
|
|
|
|
$this->output( "...processing page IDs from $batchMinPageId to $batchMaxPageId.\n" );
|
|
|
|
|
|
2023-09-21 11:54:38 +00:00
|
|
|
$res = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( [ 'page_id', 'page_restrictions' ] )
|
|
|
|
|
->from( 'page' )
|
|
|
|
|
->where( [
|
2024-07-18 18:12:05 +00:00
|
|
|
$dbw->expr( 'page_restrictions', '!=', '' ),
|
2024-01-17 17:48:40 +00:00
|
|
|
$dbw->expr( 'page_id', '>', $batchMinPageId ),
|
|
|
|
|
$dbw->expr( 'page_id', '<=', $batchMaxPageId ),
|
2023-09-21 11:54:38 +00:00
|
|
|
] )
|
|
|
|
|
->caller( __METHOD__ )->fetchResultSet();
|
2019-09-17 09:47:29 +00:00
|
|
|
|
|
|
|
|
// No pages have legacy protection settings in the current batch
|
|
|
|
|
if ( !$res->numRows() ) {
|
|
|
|
|
$batchMinPageId = $batchMaxPageId;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$batch = [];
|
2019-09-17 09:47:29 +00:00
|
|
|
$pageIds = [];
|
|
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $res as $row ) {
|
2019-09-17 09:47:29 +00:00
|
|
|
$pageIds[] = $row->page_id;
|
|
|
|
|
|
|
|
|
|
$restrictionsByAction = $this->mapLegacyRestrictionBlob( $row->page_restrictions );
|
|
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Update restrictions table
|
2019-09-17 09:47:29 +00:00
|
|
|
foreach ( $restrictionsByAction as $action => $restrictions ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$batch[] = [
|
2009-08-02 19:35:17 +00:00
|
|
|
'pr_page' => $row->page_id,
|
|
|
|
|
'pr_type' => $action,
|
|
|
|
|
'pr_level' => $restrictions,
|
|
|
|
|
'pr_cascade' => 0,
|
|
|
|
|
'pr_expiry' => $encodedExpiry
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2007-04-21 21:11:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-09-17 09:47:29 +00:00
|
|
|
|
|
|
|
|
$this->beginTransaction( $dbw, __METHOD__ );
|
|
|
|
|
|
|
|
|
|
// Insert new format protection settings for the pages in the current batch.
|
|
|
|
|
// Use INSERT IGNORE to ignore conflicts with new format settings that might exist for the page
|
2023-12-21 15:10:59 +00:00
|
|
|
$dbw->newInsertQueryBuilder()
|
|
|
|
|
->insertInto( 'page_restrictions' )
|
|
|
|
|
->ignore()
|
|
|
|
|
->rows( $batch )
|
|
|
|
|
->caller( __METHOD__ )->execute();
|
2019-09-17 09:47:29 +00:00
|
|
|
|
|
|
|
|
// Clear out the legacy page.page_restrictions blob for this batch
|
2024-04-14 18:36:13 +00:00
|
|
|
$dbw->newUpdateQueryBuilder()
|
|
|
|
|
->update( 'page' )
|
|
|
|
|
->set( [ 'page_restrictions' => '' ] )
|
|
|
|
|
->where( [ 'page_id' => $pageIds ] )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->execute();
|
2019-09-17 09:47:29 +00:00
|
|
|
|
|
|
|
|
$this->commitTransaction( $dbw, __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$batchMinPageId = $batchMaxPageId;
|
|
|
|
|
} while ( $batchMaxPageId < $maxPageId );
|
|
|
|
|
|
|
|
|
|
$this->output( "...Done!\n" );
|
2022-05-26 16:16:35 +00:00
|
|
|
return true;
|
2019-09-17 09:47:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert a legacy restriction specification from the page.page_restrictions blob to
|
|
|
|
|
* a map of action names to restriction levels.
|
|
|
|
|
*
|
|
|
|
|
* @param string $legacyBlob Legacy page.page_restrictions blob,
|
|
|
|
|
* e.g. "sysop" or "edit=sysop:move=autoconfirmed"
|
|
|
|
|
* @return string[] array of restriction levels keyed by action names
|
|
|
|
|
*/
|
|
|
|
|
private function mapLegacyRestrictionBlob( $legacyBlob ) {
|
|
|
|
|
$oldRestrictions = [];
|
|
|
|
|
|
|
|
|
|
foreach ( explode( ':', trim( $legacyBlob ) ) as $restrict ) {
|
|
|
|
|
$temp = explode( '=', trim( $restrict ) );
|
|
|
|
|
|
|
|
|
|
// Treat old old format without action name as edit/move restriction
|
|
|
|
|
if ( count( $temp ) == 1 ) {
|
|
|
|
|
$level = trim( $temp[0] );
|
|
|
|
|
|
|
|
|
|
$oldRestrictions['edit'] = $level;
|
|
|
|
|
$oldRestrictions['move'] = $level;
|
|
|
|
|
} else {
|
|
|
|
|
$restriction = trim( $temp[1] );
|
|
|
|
|
// Some old entries are empty
|
|
|
|
|
if ( $restriction != '' ) {
|
|
|
|
|
$oldRestrictions[$temp[0]] = $restriction;
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2008-10-03 22:23:03 +00:00
|
|
|
}
|
2007-04-21 21:11:14 +00:00
|
|
|
}
|
2019-09-17 09:47:29 +00:00
|
|
|
|
|
|
|
|
return $oldRestrictions;
|
2007-04-21 21:11:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = UpdateRestrictions::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|