use MediaWiki\Linker\LinkTarget;
use MediaWiki\MediaWikiServices;
-use Wikimedia\Rdbms\ResultWrapper;
+use Wikimedia\Rdbms\IResultWrapper;
use Wikimedia\Rdbms\IMaintainableDatabase;
/**
}
public function execute() {
- $this->db = $this->getDB( DB_MASTER );
-
$options = [
'fix' => $this->hasOption( 'fix' ),
'merge' => $this->hasOption( 'merge' ),
}
// Now pull in all canonical and alias namespaces...
- foreach ( MWNamespace::getCanonicalNamespaces() as $ns => $name ) {
+ foreach (
+ MediaWikiServices::getInstance()->getNamespaceInfo()->getCanonicalNamespaces()
+ as $ns => $name
+ ) {
// This includes $wgExtraNamespaces
if ( $name !== '' ) {
$spaces[$name] = $ns;
foreach ( $targets as $row ) {
// Find the new title and determine the action to take
- $newTitle = $this->getDestinationTitle( $ns, $name,
- $row->page_namespace, $row->page_title, $options );
+ $newTitle = $this->getDestinationTitle(
+ $ns, $name, $row->page_namespace, $row->page_title );
$logStatus = false;
if ( !$newTitle ) {
$logStatus = 'invalid title';
private function checkLinkTable( $table, $fieldPrefix, $ns, $name, $options,
$extraConds = []
) {
+ $dbw = $this->getDB( DB_MASTER );
+
$batchConds = [];
$fromField = "{$fieldPrefix}_from";
$namespaceField = "{$fieldPrefix}_namespace";
$titleField = "{$fieldPrefix}_title";
$batchSize = 500;
while ( true ) {
- $res = $this->db->select(
+ $res = $dbw->select(
$table,
[ $fromField, $namespaceField, $titleField ],
array_merge( $batchConds, $extraConds, [
$namespaceField => 0,
- $titleField . $this->db->buildLike( "$name:", $this->db->anyString() )
+ $titleField . $dbw->buildLike( "$name:", $dbw->anyString() )
] ),
__METHOD__,
[
foreach ( $res as $row ) {
$logTitle = "from={$row->$fromField} ns={$row->$namespaceField} " .
"dbk={$row->$titleField}";
- $destTitle = $this->getDestinationTitle( $ns, $name,
- $row->$namespaceField, $row->$titleField, $options );
+ $destTitle = $this->getDestinationTitle(
+ $ns, $name, $row->$namespaceField, $row->$titleField );
$this->totalLinks++;
if ( !$destTitle ) {
$this->output( "$table $logTitle *** INVALID\n" );
continue;
}
- $this->db->update( $table,
+ $dbw->update( $table,
// SET
[
$namespaceField => $destTitle->getNamespace(),
$this->output( "$table $logTitle -> " .
$destTitle->getPrefixedDBkey() . "\n" );
}
- $encLastTitle = $this->db->addQuotes( $row->$titleField );
- $encLastFrom = $this->db->addQuotes( $row->$fromField );
+ $encLastTitle = $dbw->addQuotes( $row->$titleField );
+ $encLastFrom = $dbw->addQuotes( $row->$fromField );
$batchConds = [
"$titleField > $encLastTitle " .
* @param string $name Prefix that is being made a namespace
* @param array $options Associative array of validated command-line options
*
- * @return ResultWrapper
+ * @return IResultWrapper
*/
private function getTargetList( $ns, $name, $options ) {
- if ( $options['move-talk'] && MWNamespace::isSubject( $ns ) ) {
+ $dbw = $this->getDB( DB_MASTER );
+
+ if (
+ $options['move-talk'] &&
+ MediaWikiServices::getInstance()->getNamespaceInfo()->isSubject( $ns )
+ ) {
$checkNamespaces = [ NS_MAIN, NS_TALK ];
} else {
$checkNamespaces = NS_MAIN;
}
- return $this->db->select( 'page',
+ return $dbw->select( 'page',
[
'page_id',
'page_title',
],
[
'page_namespace' => $checkNamespaces,
- 'page_title' . $this->db->buildLike( "$name:", $this->db->anyString() ),
+ 'page_title' . $dbw->buildLike( "$name:", $dbw->anyString() ),
],
__METHOD__
);
* @param string $name The conflicting prefix
* @param int $sourceNs The source namespace
* @param int $sourceDbk The source DB key (i.e. page_title)
- * @param array $options Associative array of validated command-line options
* @return Title|false
*/
- private function getDestinationTitle( $ns, $name, $sourceNs, $sourceDbk, $options ) {
+ private function getDestinationTitle( $ns, $name, $sourceNs, $sourceDbk ) {
$dbk = substr( $sourceDbk, strlen( "$name:" ) );
if ( $ns == 0 ) {
// An interwiki; try an alternate encoding with '-' for ':'
$dbk = "$name-" . $dbk;
}
$destNS = $ns;
- if ( $sourceNs == NS_TALK && MWNamespace::isSubject( $ns ) ) {
+ $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+ if ( $sourceNs == NS_TALK && $nsInfo->isSubject( $ns ) ) {
// This is an associated talk page moved with the --move-talk feature.
- $destNS = MWNamespace::getTalk( $destNS );
+ $destNS = $nsInfo->getTalk( $destNS );
}
$newTitle = Title::makeTitleSafe( $destNS, $dbk );
if ( !$newTitle || !$newTitle->canExist() ) {
* @return bool
*/
private function movePage( $id, LinkTarget $newLinkTarget ) {
- $this->db->update( 'page',
+ $dbw = $this->getDB( DB_MASTER );
+
+ $dbw->update( 'page',
[
"page_namespace" => $newLinkTarget->getNamespace(),
"page_title" => $newLinkTarget->getDBkey(),
[ 'imagelinks', 'il' ] ];
foreach ( $fromNamespaceTables as $tableInfo ) {
list( $table, $fieldPrefix ) = $tableInfo;
- $this->db->update( $table,
+ $dbw->update( $table,
// SET
[ "{$fieldPrefix}_from_namespace" => $newLinkTarget->getNamespace() ],
// WHERE
* @return bool
*/
private function mergePage( $row, Title $newTitle ) {
+ $dbw = $this->getDB( DB_MASTER );
+
$id = $row->page_id;
// Construct the WikiPage object we will need later, while the
$wikiPage->loadPageData( 'fromdbmaster' );
$destId = $newTitle->getArticleID();
- $this->beginTransaction( $this->db, __METHOD__ );
- $this->db->update( 'revision',
+ $this->beginTransaction( $dbw, __METHOD__ );
+ $dbw->update( 'revision',
// SET
[ 'rev_page' => $destId ],
// WHERE
[ 'rev_page' => $id ],
__METHOD__ );
- $this->db->delete( 'page', [ 'page_id' => $id ], __METHOD__ );
+ $dbw->delete( 'page', [ 'page_id' => $id ], __METHOD__ );
- $this->commitTransaction( $this->db, __METHOD__ );
+ $this->commitTransaction( $dbw, __METHOD__ );
/* Call LinksDeletionUpdate to delete outgoing links from the old title,
* and update category counts.