$pageid = $this->oldTitle->getArticleID( Title::GAID_FOR_UPDATE );
$protected = $this->oldTitle->isProtected();
- // Do the actual move
+ // Do the actual move; if this fails, it will throw an MWException(!)
$nullRevision = $this->moveToInternal( $user, $this->newTitle, $reason, $createRedirect );
// Refresh the sortkey for this row. Be careful to avoid resetting
*
* @fixme This was basically directly moved from Title, it should be split into smaller functions
* @param User $user the User doing the move
- * @param Title $nt The page to move to, which should be a redirect or nonexistent
+ * @param Title $nt The page to move to, which should be a redirect or non-existent
* @param string $reason The reason for the move
* @param bool $createRedirect Whether to leave a redirect at the old title. Does not check
* if the user has the suppressredirect right
$logType = 'move';
}
+ if ( $moveOverRedirect ) {
+ $overwriteMessage = wfMessage(
+ 'delete_and_move_reason',
+ $this->oldTitle->getPrefixedText()
+ )->text();
+ $newpage = WikiPage::factory( $nt );
+ $errs = [];
+ $status = $newpage->doDeleteArticleReal(
+ $overwriteMessage,
+ /* $suppress */ false,
+ $nt->getArticleId(),
+ /* $commit */ false,
+ $errs,
+ $user
+ );
+
+ if ( !$status->isGood() ) {
+ throw new MWException( 'Failed to delete page-move revision: ' . $status );
+ }
+
+ $nt->resetArticleID( false );
+ }
+
if ( $createRedirect ) {
if ( $this->oldTitle->getNamespace() == NS_CATEGORY
&& !wfMessage( 'category-move-redirect-override' )->inContentLanguage()->isDisabled()
$newpage = WikiPage::factory( $nt );
- if ( $moveOverRedirect ) {
- $newid = $nt->getArticleID();
- $newcontent = $newpage->getContent();
-
- # Delete the old redirect. We don't save it to history since
- # by definition if we've got here it's rather uninteresting.
- # We have to remove it so that the next step doesn't trigger
- # a conflict on the unique namespace+title index...
- $dbw->delete( 'page', [ 'page_id' => $newid ], __METHOD__ );
-
- $newpage->doDeleteUpdates( $newid, $newcontent );
- }
-
# Save a null revision in the page's history notifying of the move
$nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true, $user );
if ( !is_object( $nullRevision ) ) {
);
}
- if ( !$moveOverRedirect ) {
- WikiPage::onArticleCreate( $nt );
- }
+ WikiPage::onArticleCreate( $nt );
# Recreate the redirect, this time in the other direction.
if ( $redirectContent ) {
* @defgroup API API
*/
+use MediaWiki\Logger\LoggerFactory;
+
/**
* This is the main API class, used for both external and internal processing.
* When executed, it will create the requested formatter object,
$config->get( 'CrossSiteAJAXdomainExceptions' )
)
) ) {
- MediaWiki\Logger\LoggerFactory::getInstance( 'cors' )->warning(
+ LoggerFactory::getInstance( 'cors' )->warning(
'Non-whitelisted CORS request with session cookies', [
'origin' => $originHeader,
'cookies' => $sessionCookies,
protected function setRequestExpectations( ApiBase $module ) {
$limits = $this->getConfig()->get( 'TrxProfilerLimits' );
$trxProfiler = Profiler::instance()->getTransactionProfiler();
+ $trxProfiler->setLogger( LoggerFactory::getInstance( 'DBPerformance' ) );
if ( $this->getRequest()->hasSafeMethod() ) {
$trxProfiler->setExpectations( $limits['GET'], __METHOD__ );
} elseif ( $this->getRequest()->wasPosted() && !$module->isWriteMode() ) {
require_once __DIR__ . '/cleanupTable.inc';
/**
- * Maintenance script to clean up broken page links when somebody turns on $wgCapitalLinks.
+ * Maintenance script to clean up broken page links when somebody turns
+ * on or off $wgCapitalLinks.
*
* @ingroup Maintenance
*/
class CapsCleanup extends TableCleanup {
private $user;
+ private $namespace;
public function __construct() {
parent::__construct();
}
public function execute() {
- global $wgCapitalLinks;
-
- if ( $wgCapitalLinks ) {
- $this->error( "\$wgCapitalLinks is on -- no need for caps links cleanup.", true );
- }
-
$this->user = User::newSystemUser( 'Conversion script', [ 'steal' => true ] );
$this->namespace = intval( $this->getOption( 'namespace', 0 ) );
+
+ if ( MWNamespace::isCapitalized( $this->namespace ) ) {
+ $this->output( "Will be moving pages to first letter capitalized titles" );
+ $callback = 'processRowToUppercase';
+ } else {
+ $this->output( "Will be moving pages to first letter lowercase titles" );
+ $callback = 'processRowToLowercase';
+ }
+
$this->dryrun = $this->hasOption( 'dry-run' );
$this->runTable( [
'table' => 'page',
'conds' => [ 'page_namespace' => $this->namespace ],
'index' => 'page_id',
- 'callback' => 'processRow' ] );
+ 'callback' => $callback ] );
}
- protected function processRow( $row ) {
+ protected function processRowToUppercase( $row ) {
+ global $wgContLang;
+
+ $current = Title::makeTitle( $row->page_namespace, $row->page_title );
+ $display = $current->getPrefixedText();
+ $lower = $row->page_title;
+ $upper = $wgContLang->ucfirst( $row->page_title );
+ if ( $upper == $lower ) {
+ $this->output( "\"$display\" already uppercase.\n" );
+
+ return $this->progress( 0 );
+ }
+
+ $target = Title::makeTitle( $row->page_namespace, $upper );
+ if ( $target->exists() ) {
+ // Prefix "CapsCleanup" to bypass the conflict
+ $target = Title::newFromText( __CLASS__ . '/' . $display );
+ }
+ $ok = $this->movePage(
+ $current,
+ $target,
+ 'Converting page title to first-letter uppercase',
+ false
+ );
+ if ( $ok ) {
+ $this->progress( 1 );
+ if ( $row->page_namespace == $this->namespace ) {
+ $talk = $target->getTalkPage();
+ $row->page_namespace = $talk->getNamespace();
+ if ( $talk->exists() ) {
+ return $this->processRowToUppercase( $row );
+ }
+ }
+ }
+
+ return $this->progress( 0 );
+ }
+
+ protected function processRowToLowercase( $row ) {
global $wgContLang;
$current = Title::makeTitle( $row->page_namespace, $row->page_title );
}
$target = Title::makeTitle( $row->page_namespace, $lower );
- $targetDisplay = $target->getPrefixedText();
if ( $target->exists() ) {
+ $targetDisplay = $target->getPrefixedText();
$this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
return $this->progress( 0 );
}
- if ( $this->dryrun ) {
- $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
- $ok = true;
- } else {
- $mp = new MovePage( $current, $target );
- $status = $mp->move( $this->user, 'Converting page titles to lowercase', true );
- $ok = $status->isOK() ? 'OK' : $status->getWikiText( false, false, 'en' );
- $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
- }
+ $ok = $this->movePage( $current, $target, 'Converting page titles to lowercase', true );
if ( $ok === true ) {
$this->progress( 1 );
if ( $row->page_namespace == $this->namespace ) {
$talk = $target->getTalkPage();
$row->page_namespace = $talk->getNamespace();
if ( $talk->exists() ) {
- return $this->processRow( $row );
+ return $this->processRowToLowercase( $row );
}
}
}
return $this->progress( 0 );
}
+
+ /**
+ * @param Title $current
+ * @param Title $target
+ * @param string $reason
+ * @param bool $createRedirect
+ * @return bool Success
+ */
+ private function movePage( Title $current, Title $target, $reason, $createRedirect ) {
+ $display = $current->getPrefixedText();
+ $targetDisplay = $target->getPrefixedText();
+
+ if ( $this->dryrun ) {
+ $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
+ $ok = 'OK';
+ } else {
+ $mp = new MovePage( $current, $target );
+ $status = $mp->move( $this->user, $reason, $createRedirect );
+ $ok = $status->isOK() ? 'OK' : $status->getWikiText( false, false, 'en' );
+ $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
+ }
+
+ return $ok === 'OK';
+ }
}
$maintClass = "CapsCleanup";