r23436 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23435‎ | r23436 | r23437 >
Date:21:18, 26 June 2007
Author:brion
Status:old
Tags:
Comment:
* (bug 10198) namespaceDupes.php no longer ignores interwiki prefixes
* namespaceDupes.php should work better for initial-lowercase wikis
Also reduced verbosity of output by default. Use --verbose to list eeeverything it checks
Modified paths:
  • /trunk/phase3/maintenance/namespaceDupes.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/namespaceDupes.php
@@ -31,32 +31,59 @@
3232 appended after the article name.
3333 --prefix=<text> : Do an explicit check for the given title prefix
3434 in place of the standard namespace list.
 35+ --verbose : Display output for checked namespaces without conflicts
3536
3637 END;
3738 die;
3839 }
3940
4041 class NamespaceConflictChecker {
41 - function NamespaceConflictChecker( $db ) {
 42+ function NamespaceConflictChecker( $db, $verbose=false ) {
4243 $this->db = $db;
 44+ $this->verbose = $verbose;
4345 }
4446
4547 function checkAll( $fix, $suffix = '' ) {
4648 global $wgContLang, $wgNamespaceAliases, $wgCanonicalNamespaceNames;
 49+ global $wgCapitalLinks;
4750
4851 $spaces = array();
49 - foreach( $wgContLang->getNamespaces() as $ns => $name ) {
50 - $spaces[$name] = $ns;
 52+
 53+ // List interwikis first, so they'll be overridden
 54+ // by any conflicting local namespaces.
 55+ foreach( $this->getInterwikiList() as $prefix ) {
 56+ $name = $wgContLang->ucfirst( $prefix );
 57+ $spaces[$name] = 0;
5158 }
 59+
 60+ // Now pull in all canonical and alias namespaces...
5261 foreach( $wgCanonicalNamespaceNames as $ns => $name ) {
53 - $spaces[$name] = $ns;
 62+ // This includes $wgExtraNamespaces
 63+ if( $name !== '' ) {
 64+ $spaces[$name] = $ns;
 65+ }
5466 }
 67+ foreach( $wgContLang->getNamespaces() as $ns => $name ) {
 68+ if( $name !== '' ) {
 69+ $spaces[$name] = $ns;
 70+ }
 71+ }
5572 foreach( $wgNamespaceAliases as $name => $ns ) {
5673 $spaces[$name] = $ns;
5774 }
5875 foreach( $wgContLang->namespaceAliases as $name => $ns ) {
5976 $spaces[$name] = $ns;
6077 }
 78+
 79+ if( !$wgCapitalLinks ) {
 80+ // We'll need to check for lowercase keys as well,
 81+ // since we're doing case-sensitive searches in the db.
 82+ foreach( array_values( $spaces ) as $name => $ns ) {
 83+ $lcname = $wgContLang->lcfirst( $name );
 84+ $spaces[$lcname] = $ns;
 85+ }
 86+ }
 87+ ksort( $spaces );
6188 asort( $spaces );
6289
6390 $ok = true;
@@ -65,21 +92,34 @@
6693 }
6794 return $ok;
6895 }
 96+
 97+ private function getInterwikiList() {
 98+ $result = $this->db->select( 'interwiki', array( 'iw_prefix' ) );
 99+ while( $row = $this->db->fetchObject( $result ) ) {
 100+ $prefixes[] = $row->iw_prefix;
 101+ }
 102+ $this->db->freeResult( $result );
 103+ return $prefixes;
 104+ }
69105
70106 function checkNamespace( $ns, $name, $fix, $suffix = '' ) {
71 - echo "Checking namespace $ns: \"$name\"\n";
72 - if( $name == '' ) {
73 - echo "... skipping article namespace\n";
74 - return true;
 107+ if( $ns == 0 ) {
 108+ $header = "Checking interwiki prefix: \"$name\"\n";
 109+ } else {
 110+ $header = "Checking namespace $ns: \"$name\"\n";
75111 }
76112
77113 $conflicts = $this->getConflicts( $ns, $name );
78114 $count = count( $conflicts );
79115 if( $count == 0 ) {
80 - echo "... no conflicts detected!\n";
 116+ if( $this->verbose ) {
 117+ echo $header;
 118+ echo "... no conflicts detected!\n";
 119+ }
81120 return true;
82121 }
83122
 123+ echo $header;
84124 echo "... $count conflicts detected:\n";
85125 $ok = true;
86126 foreach( $conflicts as $row ) {
@@ -106,11 +146,18 @@
107147
108148 $prefix = $this->db->strencode( $name );
109149 $likeprefix = str_replace( '_', '\\_', $prefix);
 150+ $encNamespace = $this->db->addQuotes( $ns );
110151
111 - $sql = "SELECT {$page}_id AS id,
112 - {$page}_title AS oldtitle,
113 - $ns AS namespace,
114 - TRIM(LEADING '$prefix:' FROM {$page}_title) AS title
 152+ $titleSql = "TRIM(LEADING '$prefix:' FROM {$page}_title)";
 153+ if( $ns == 0 ) {
 154+ // An interwiki; try an alternate encoding with '-' for ':'
 155+ $titleSql = "CONCAT('$prefix-',$titleSql)";
 156+ }
 157+
 158+ $sql = "SELECT {$page}_id AS id,
 159+ {$page}_title AS oldtitle,
 160+ $encNamespace AS namespace,
 161+ $titleSql AS title
115162 FROM {$table}
116163 WHERE {$page}_namespace=0
117164 AND {$page}_title LIKE '$likeprefix:%'";
@@ -181,12 +228,14 @@
182229
183230 $wgTitle = Title::newFromText( 'Namespace title conflict cleanup script' );
184231
 232+$verbose = isset( $options['verbose'] );
185233 $fix = isset( $options['fix'] );
186234 $suffix = isset( $options['suffix'] ) ? $options['suffix'] : '';
187235 $prefix = isset( $options['prefix'] ) ? $options['prefix'] : '';
188236 $key = isset( $options['key'] ) ? intval( $options['key'] ) : 0;
 237+
189238 $dbw = wfGetDB( DB_MASTER );
190 -$duper = new NamespaceConflictChecker( $dbw );
 239+$duper = new NamespaceConflictChecker( $dbw, $verbose );
191240
192241 if( $prefix ) {
193242 $retval = $duper->checkPrefix( $key, $prefix, $fix, $suffix );

Follow-up revisions

RevisionCommit summaryAuthorDate
r23581Merged revisions 23406-23580 via svnmerge from...david04:50, 30 June 2007

Status & tagging log