Last modified: 2006-11-13 22:38:36 UTC
hi, i had many articles like name:namespace that should be like namespace:name. there is a moveBatch script which can move those articles but you have to create a document manually containing those articles and it creates redirects. those where useless in my case. so i wrote this script containing own code, moveBatch.php and deleteBatch.php. IT WORKED IN MY CASE BUT PROBABLY WILL NOT IN OURS because the code is VERY basic (brion says it scares him ^^) but maybe someone can polish it or whatever: <?php @mysql_connect('host', 'name', 'password') OR die(mysql_error()); mysql_select_db('tpedia') OR die(mysql_error()); //get all pages who are like "Name:Namespace" $sql="SELECT `page_id`, `page_title` FROM `page` WHERE `page_title` LIKE CONVERT( _utf8 '%:Namespace%' USING latin1 );"; $result = mysql_query($sql) OR die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $id = $row['page_id']; $title = $row['page_title']; //swap titlenames from "Name:Namespace" to "Namespace:Name" $teile = explode(":", $title); $swaptitle = "$teile[1]:$teile[0]"; //get all articles with links to "Name:Namespace" $sql1="SELECT `old_id`, `old_text` FROM `text` WHERE `old_text` LIKE CONVERT( _utf8 '%$title%' USING latin1 ) COLLATE latin1_swedish_ci;"; $result1 = mysql_query($sql1) OR die(mysql_error()); echo $title; echo " > "; echo $swaptitle; echo "\n"; //write thing into array for strtr $array = array ($title => $swaptitle); while($row = mysql_fetch_assoc($result1)) { $id = $row['old_id']; $text = $row['old_text']; //change all links in articletext from "Name:Namespace" to "Namespace:Name" $swaptext = strtr($text, $array); //escaping for sql $newtext = mysql_real_escape_string($swaptext); //update article text $sql2="UPDATE `text` SET `old_text` = '$newtext' WHERE `old_id` = '$id';"; $result2 = mysql_query($sql2) OR die(mysql_error()); } //the actual moving of the page and then the deletion of the old redirects $user = 'Move page script'; $reason = 'Swapping'; $interval = 0; $oldCwd = getcwd(); chdir( $oldCwd ); require_once( 'commandLine.inc' ); $wgUser = User::newFromName( $user ); $dbw =& wfGetDB( DB_MASTER ); //moveBatch part - move the pages $source = Title::newFromText( $title ); $dest = Title::newFromText( $swaptitle ); if ( is_null( $source ) || is_null( $dest ) ) { print "Invalid title on line $linenum\n"; continue; } $dbw->begin(); $err = $source->moveTo( $dest, false, $reason ); if( $err !== true ) { print "\nFAILED: $err"; } $dbw->immediateCommit(); print "\n"; if ( $interval ) { sleep( $interval ); } wfWaitForSlaves( 5 ); //deleteBatch part - delete useless redirects $page = Title::newFromText( $title ); if ( is_null( $page ) ) { print "Invalid title '$line' on line $linenum\n"; continue; } if( !$page->exists() ) { print "Skipping nonexistent page '$line'\n"; continue; } $dbw->begin(); if( $page->getNamespace() == NS_IMAGE ) { $art = new ImagePage( $page ); } else { $art = new Article( $page ); } $success = $art->doDeleteArticle( $reason ); $dbw->immediateCommit(); if ( !$success ) { print " FAILED\n"; } if ( $interval ) { sleep( $interval ); } wfWaitForSlaves( 5 ); } ?>
Was there a bug anywhere?
No. That's why this is filed as a request for enhancement.
(In reply to comment #2) > No. That's why this is filed as a request for enhancement. but? where is the request?
I'm not sure what this is doing here, either. Sounds like a script that fixes a one-off occurrence of an edge case.
i didn't know where to post it instead. someone said i should post it at bugzilla.
(In reply to comment #3) > but? where is the request? This *is* the request. (In reply to comment #4) > I'm not sure what this is doing here, either. Sounds like a script that fixes a > one-off occurrence of an edge case. Well, the general idea might be a useful addition to the functionality of moveBatch.php. Not every batch move will want redirects, and doubtless a built-in pattern-based move would be useful to some people who use the software.
Somebody's special-purpose one-off script is nice and all, but it really doesn't belong here. Please do not re-open, as there's not anything to fix.