$this->mDescription = "";
$this->addOption( 'fix', 'Attempt to automatically fix errors' );
$this->addOption( 'suffix', "Dupes will be renamed with correct namespace with " .
- "<text> appended after the article name", false, true );
+ "<text> appended after the article name", false, true );
$this->addOption( 'prefix', "Do an explicit check for the given title prefix " .
- "appended after the article name", false, true );
+ "appended after the article name", false, true );
}
public function execute() {
foreach ( $spaces as $name => $ns ) {
$ok = $this->checkNamespace( $ns, $name, $fix, $suffix ) && $ok;
}
+
return $ok;
}
foreach ( $result as $row ) {
$prefixes[] = $row['iw_prefix'];
}
+
return $prefixes;
}
$ok = $this->resolveConflict( $row, $resolvable, $suffix ) && $ok;
}
}
+
return $ok;
}
/**
* @todo Do this for real
- * @param int $ns
- * @param string $name
+ * @param int $key
+ * @param string $prefix
* @param bool $fix
* @param string $suffix
* @return bool
*/
private function checkPrefix( $key, $prefix, $fix, $suffix = '' ) {
$this->output( "Checking prefix \"$prefix\" vs namespace $key\n" );
+
return $this->checkNamespace( $key, $prefix, $fix, $suffix );
}
* @return array
*/
private function getConflicts( $ns, $name ) {
- $page = 'page';
- $table = $this->db->tableName( $page );
-
- $prefix = $this->db->strencode( $name );
- $encNamespace = $this->db->addQuotes( $ns );
-
- $titleSql = "TRIM(LEADING '$prefix:' FROM {$page}_title)";
+ $titleSql = "TRIM(LEADING {$this->db->addQuotes( "$name:" )} FROM page_title)";
if ( $ns == 0 ) {
// An interwiki; try an alternate encoding with '-' for ':'
- $titleSql = $this->db->buildConcat( array( "'$prefix-'", $titleSql ) );
+ $titleSql = $this->db->buildConcat( array(
+ $this->db->addQuotes( "$name-" ),
+ $titleSql,
+ ) );
}
- $sql = "SELECT {$page}_id AS id,
- {$page}_title AS oldtitle,
- $encNamespace + {$page}_namespace AS namespace,
- $titleSql AS title,
- {$page}_namespace AS oldnamespace
- FROM {$table}
- WHERE ( {$page}_namespace=0 OR {$page}_namespace=1 )
- AND {$page}_title " . $this->db->buildLike( $name . ':', $this->db->anyString() );
-
- $result = $this->db->query( $sql, __METHOD__ );
-
- $set = array();
- foreach ( $result as $row ) {
- $set[] = $row;
- }
- return $set;
+ return iterator_to_array( $this->db->select( 'page',
+ array(
+ 'id' => 'page_id',
+ 'oldtitle' => 'page_title',
+ 'namespace' => $this->db->addQuotes( $ns ) . ' + page_namespace',
+ 'title' => $titleSql,
+ 'oldnamespace' => 'page_namespace',
+ ),
+ array(
+ 'page_namespace' => array( 0, 1 ),
+ 'page_title' . $this->db->buildLike( "$name:", $this->db->anyString() ),
+ ),
+ __METHOD__
+ ) );
}
/**
$row->oldnamespace,
$row->oldtitle ) );
$this->output( "... *** cannot resolve automatically; illegal title ***\n" );
+
return false;
}
$id = $newTitle->getArticleID();
if ( $id ) {
$this->output( "... *** cannot resolve automatically; page exists with ID $id ***\n" );
+
return false;
} else {
return true;
$title = Title::makeTitleSafe( $row->namespace, $row->title );
if ( !$title ) {
$this->output( "... !!! invalid title\n" );
+
return false;
}
$id = $title->getArticleID();
$this->output( "... *** using suffixed form [[" . $title->getPrefixedText() . "]] ***\n" );
}
$this->resolveConflictOn( $row, 'page', 'page' );
+
return true;
}
),
__METHOD__ );
$this->output( "ok.\n" );
+
return true;
}
}