37 lines
		
	
	
	
		
			907 B
		
	
	
	
		
			Text
		
	
	
	
	
	
		
		
			
		
	
	
			37 lines
		
	
	
	
		
			907 B
		
	
	
	
		
			Text
		
	
	
	
	
	
| 
								 | 
							
								#!/usr/bin/env ruby
							 | 
						||
| 
								 | 
							
								require 'mediawikibot'
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								if ARGV.size() != 2
							 | 
						||
| 
								 | 
							
								  $stderr.print($0 + " <wiki-user> <wiki-password>\n")
							 | 
						||
| 
								 | 
							
								  exit(1)
							 | 
						||
| 
								 | 
							
								end
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#------------------------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								# Rock!
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								b = MediaWikiBot::WikiBot.new("http://entropia.de/wiki/")
							 | 
						||
| 
								 | 
							
								b.login(ARGV[0], ARGV[1])
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								b.get_allpages().delete_if { |title| title !~ /GPN/ }.each do |title|
							 | 
						||
| 
								 | 
							
								  if !b.is_redirect?(title) 
							 | 
						||
| 
								 | 
							
								    puts "Processing #{title}"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if !b.is_in_category?(title, "Kategorie:GPN") 
							 | 
						||
| 
								 | 
							
								      puts "* [[#{title}]] fehlt in [[Kategorie:GPN]]"
							 | 
						||
| 
								 | 
							
								    end
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if b.get_categories(title).delete_if {|c| c !~ /Kategorie:GPN\d/} .size == 0
							 | 
						||
| 
								 | 
							
								      # Try to fix it
							 | 
						||
| 
								 | 
							
								      if title =~ /^(GPN\d)/
							 | 
						||
| 
								 | 
							
								        cat = "[[Kategorie:#{$1}]]"
							 | 
						||
| 
								 | 
							
								        body = b.get_raw(title) + "\n#{cat}\n"
							 | 
						||
| 
								 | 
							
								        b.edit(title, body, cat)
							 | 
						||
| 
								 | 
							
								      else
							 | 
						||
| 
								 | 
							
								        puts "* [[#{title}]] keiner GPN zugeordnet"
							 | 
						||
| 
								 | 
							
								      end
							 | 
						||
| 
								 | 
							
								    end
							 | 
						||
| 
								 | 
							
								    sleep(1)
							 | 
						||
| 
								 | 
							
								  end
							 | 
						||
| 
								 | 
							
								end
							 | 
						||
| 
								 | 
							
								
							 |