Last modified: 2006-11-13 22:38:36 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T9884, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 7884 - More versatile moveBatch.php (disable redirects, move according to pattern)
More versatile moveBatch.php (disable redirects, move according to pattern)
Status: RESOLVED INVALID
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
unspecified
All All
: Normal enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
http://nopaste.php-q.net/253539
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-11-12 14:18 UTC by DarsVaeda
Modified: 2006-11-13 22:38 UTC (History)
0 users

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description DarsVaeda 2006-11-12 14:18:47 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 );
}       
?>
Comment 1 Carl Fürstenberg 2006-11-12 14:21:56 UTC
Was there a bug anywhere?
Comment 2 Aryeh Gregor (not reading bugmail, please e-mail directly) 2006-11-12 18:34:50 UTC
No.  That's why this is filed as a request for enhancement.
Comment 3 Carl Fürstenberg 2006-11-12 18:41:21 UTC
(In reply to comment #2)
> No.  That's why this is filed as a request for enhancement.

but? where is the request?
Comment 4 Rob Church 2006-11-12 18:52:07 UTC
I'm not sure what this is doing here, either. Sounds like a script that fixes a
one-off occurrence of an edge case.
Comment 5 DarsVaeda 2006-11-12 19:03:21 UTC
i didn't know where to post it instead.
someone said i should post it at bugzilla.
Comment 6 Aryeh Gregor (not reading bugmail, please e-mail directly) 2006-11-12 19:06:31 UTC
(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.
Comment 7 Brion Vibber 2006-11-13 22:38:36 UTC
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.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links