public function __construct() {
parent::__construct();
- $this->mDescription = "";
+ $this->addDescription( 'Find and fix pages affected by namespace addition/removal' );
$this->addOption( 'fix', 'Attempt to automatically fix errors' );
$this->addOption( 'merge', "Instead of renaming conflicts, do a history merge with " .
"the correct title" );
public function execute() {
$this->db = $this->getDB( DB_MASTER );
- $options = array(
+ $options = [
'fix' => $this->hasOption( 'fix' ),
'merge' => $this->hasOption( 'merge' ),
'add-suffix' => $this->getOption( 'add-suffix', '' ),
'add-prefix' => $this->getOption( 'add-prefix', '' ),
'move-talk' => $this->hasOption( 'move-talk' ),
'source-pseudo-namespace' => $this->getOption( 'source-pseudo-namespace', '' ),
- 'dest-namespace' => intval( $this->getOption( 'dest-namespace', 0 ) ) );
+ 'dest-namespace' => intval( $this->getOption( 'dest-namespace', 0 ) ) ];
if ( $options['source-pseudo-namespace'] !== '' ) {
$retval = $this->checkPrefix( $options );
private function checkAll( $options ) {
global $wgContLang, $wgNamespaceAliases, $wgCapitalLinks;
- $spaces = array();
+ $spaces = [];
// List interwikis first, so they'll be overridden
// by any conflicting local namespaces.
// We'll need to check for lowercase keys as well,
// since we're doing case-sensitive searches in the db.
foreach ( $spaces as $name => $ns ) {
- $moreNames = array();
+ $moreNames = [];
$moreNames[] = $wgContLang->uc( $name );
$moreNames[] = $wgContLang->ucfirst( $wgContLang->lc( $name ) );
$moreNames[] = $wgContLang->ucwords( $name );
// have rd_interwiki=w and rd_namespace=0, which would match the
// query for a conflicting namespace "Foo" if filtering wasn't done.
$this->checkLinkTable( 'redirect', 'rd', $ns, $name, $options,
- array( 'rd_interwiki' => null ) );
+ [ 'rd_interwiki' => null ] );
$this->checkLinkTable( 'redirect', 'rd', $ns, $name, $options,
- array( 'rd_interwiki' => '' ) );
+ [ 'rd_interwiki' => '' ] );
}
}
*/
private function getInterwikiList() {
$result = Interwiki::getAllPrefixes();
- $prefixes = array();
+ $prefixes = [];
foreach ( $result as $row ) {
$prefixes[] = $row['iw_prefix'];
}
* @param array $extraConds Extra conditions for the SQL query
*/
private function checkLinkTable( $table, $fieldPrefix, $ns, $name, $options,
- $extraConds = array()
+ $extraConds = []
) {
- $batchConds = array();
+ $batchConds = [];
$fromField = "{$fieldPrefix}_from";
$namespaceField = "{$fieldPrefix}_namespace";
$titleField = "{$fieldPrefix}_title";
while ( true ) {
$res = $this->db->select(
$table,
- array( $fromField, $namespaceField, $titleField ),
- array_merge( $batchConds, $extraConds, array(
+ [ $fromField, $namespaceField, $titleField ],
+ array_merge( $batchConds, $extraConds, [
$namespaceField => 0,
$titleField . $this->db->buildLike( "$name:", $this->db->anyString() )
- ) ),
+ ] ),
__METHOD__,
- array(
- 'ORDER BY' => array( $titleField, $fromField ),
+ [
+ 'ORDER BY' => [ $titleField, $fromField ],
'LIMIT' => $batchSize
- )
+ ]
);
if ( $res->numRows() == 0 ) {
$this->db->update( $table,
// SET
- array(
+ [
$namespaceField => $destTitle->getNamespace(),
$titleField => $destTitle->getDBkey()
- ),
+ ],
// WHERE
- array(
+ [
$namespaceField => 0,
$titleField => $row->$titleField,
$fromField => $row->$fromField
- ),
+ ],
__METHOD__,
- array( 'IGNORE' )
+ [ 'IGNORE' ]
);
$this->output( "$table $logTitle -> " .
$destTitle->getPrefixedDBkey() . "\n" );
$encLastTitle = $this->db->addQuotes( $row->$titleField );
$encLastFrom = $this->db->addQuotes( $row->$fromField );
- $batchConds = array(
+ $batchConds = [
"$titleField > $encLastTitle " .
- "OR ($titleField = $encLastTitle AND $fromField > $encLastFrom)" );
+ "OR ($titleField = $encLastTitle AND $fromField > $encLastFrom)" ];
wfWaitForSlaves();
}
*/
private function getTargetList( $ns, $name, $options ) {
if ( $options['move-talk'] && MWNamespace::isSubject( $ns ) ) {
- $checkNamespaces = array( NS_MAIN, NS_TALK );
+ $checkNamespaces = [ NS_MAIN, NS_TALK ];
} else {
$checkNamespaces = NS_MAIN;
}
return $this->db->select( 'page',
- array(
+ [
'page_id',
'page_title',
'page_namespace',
- ),
- array(
+ ],
+ [
'page_namespace' => $checkNamespaces,
'page_title' . $this->db->buildLike( "$name:", $this->db->anyString() ),
- ),
+ ],
__METHOD__
);
}
* Get an alternative title to move a page to. This is used if the
* preferred destination title already exists.
*
- * @param Title $title
+ * @param LinkTarget $linkTarget
* @param array $options Associative array of validated command-line options
* @return Title|bool
*/
- private function getAlternateTitle( $title, $options ) {
+ private function getAlternateTitle( LinkTarget $linkTarget, $options ) {
$prefix = $options['add-prefix'];
$suffix = $options['add-suffix'];
if ( $prefix == '' && $suffix == '' ) {
return false;
}
while ( true ) {
- $dbk = $prefix . $title->getDBkey() . $suffix;
- $title = Title::makeTitleSafe( $title->getNamespace(), $dbk );
+ $dbk = $prefix . $linkTarget->getDBkey() . $suffix;
+ $title = Title::makeTitleSafe( $linkTarget->getNamespace(), $dbk );
if ( !$title ) {
return false;
}
* Move a page
*
* @param integer $id The page_id
- * @param Title $newTitle The new title
+ * @param LinkTarget $newLinkTarget The new title link target
* @return bool
*/
- private function movePage( $id, Title $newTitle ) {
+ private function movePage( $id, LinkTarget $newLinkTarget ) {
$this->db->update( 'page',
- array(
- "page_namespace" => $newTitle->getNamespace(),
- "page_title" => $newTitle->getDBkey(),
- ),
- array(
+ [
+ "page_namespace" => $newLinkTarget->getNamespace(),
+ "page_title" => $newLinkTarget->getDBkey(),
+ ],
+ [
"page_id" => $id,
- ),
+ ],
__METHOD__ );
// Update *_from_namespace in links tables
- $fromNamespaceTables = array(
- array( 'pagelinks', 'pl' ),
- array( 'templatelinks', 'tl' ),
- array( 'imagelinks', 'il' ) );
+ $fromNamespaceTables = [
+ [ 'pagelinks', 'pl' ],
+ [ 'templatelinks', 'tl' ],
+ [ 'imagelinks', 'il' ] ];
foreach ( $fromNamespaceTables as $tableInfo ) {
list( $table, $fieldPrefix ) = $tableInfo;
$this->db->update( $table,
// SET
- array( "{$fieldPrefix}_from_namespace" => $newTitle->getNamespace() ),
+ [ "{$fieldPrefix}_from_namespace" => $newLinkTarget->getNamespace() ],
// WHERE
- array( "{$fieldPrefix}_from" => $id ),
+ [ "{$fieldPrefix}_from" => $id ],
__METHOD__ );
}
* recentchanges review, etc.
*
* @param integer $id The page_id
- * @param Title $newTitle The new title
+ * @param LinkTarget $linkTarget The new link target
* @param string $logStatus This is set to the log status message on failure
* @return bool
*/
- private function canMerge( $id, Title $newTitle, &$logStatus ) {
- $latestDest = Revision::newFromTitle( $newTitle, 0, Revision::READ_LATEST );
+ private function canMerge( $id, LinkTarget $linkTarget, &$logStatus ) {
+ $latestDest = Revision::newFromTitle( $linkTarget, 0, Revision::READ_LATEST );
$latestSource = Revision::newFromPageId( $id, 0, Revision::READ_LATEST );
if ( $latestSource->getTimestamp() > $latestDest->getTimestamp() ) {
$logStatus = 'cannot merge since source is later';
$wikiPage = new WikiPage( $sourceTitle );
$wikiPage->loadPageData( 'fromdbmaster' );
- $destId = $newTitle->getArticleId();
+ $destId = $newTitle->getArticleID();
$this->beginTransaction( $this->db, __METHOD__ );
$this->db->update( 'revision',
// SET
- array( 'rev_page' => $destId ),
+ [ 'rev_page' => $destId ],
// WHERE
- array( 'rev_page' => $id ),
+ [ 'rev_page' => $id ],
__METHOD__ );
- $this->db->delete( 'page', array( 'page_id' => $id ), __METHOD__ );
+ $this->db->delete( 'page', [ 'page_id' => $id ], __METHOD__ );
/* Call LinksDeletionUpdate to delete outgoing links from the old title,
* and update category counts.