00001 <?php 00002 00017 $oldCwd = getcwd(); 00018 $optionsWithArgs = array( 'u', 'r', 'i' ); 00019 require_once( 'commandLine.inc' ); 00020 00021 chdir( $oldCwd ); 00022 00023 # Options processing 00024 00025 $filename = 'php://stdin'; 00026 $user = 'Delete page script'; 00027 $reason = ''; 00028 $interval = 0; 00029 00030 if ( isset( $args[0] ) ) { 00031 $filename = $args[0]; 00032 } 00033 if ( isset( $options['u'] ) ) { 00034 $user = $options['u']; 00035 } 00036 if ( isset( $options['r'] ) ) { 00037 $reason = $options['r']; 00038 } 00039 if ( isset( $options['i'] ) ) { 00040 $interval = $options['i']; 00041 } 00042 00043 $wgUser = User::newFromName( $user ); 00044 00045 00046 # Setup complete, now start 00047 00048 $file = fopen( $filename, 'r' ); 00049 if ( !$file ) { 00050 print "Unable to read file, exiting\n"; 00051 exit; 00052 } 00053 00054 $dbw = wfGetDB( DB_MASTER ); 00055 00056 for ( $linenum = 1; !feof( $file ); $linenum++ ) { 00057 $line = trim( fgets( $file ) ); 00058 if ( $line == '' ) { 00059 continue; 00060 } 00061 $page = Title::newFromText( $line ); 00062 if ( is_null( $page ) ) { 00063 print "Invalid title '$line' on line $linenum\n"; 00064 continue; 00065 } 00066 if( !$page->exists() ) { 00067 print "Skipping nonexistent page '$line'\n"; 00068 continue; 00069 } 00070 00071 00072 print $page->getPrefixedText(); 00073 $dbw->begin(); 00074 if( $page->getNamespace() == NS_FILE ) { 00075 $art = new ImagePage( $page ); 00076 $img = wfFindFile( $art->mTitle ); 00077 if( !$img || !$img->delete( $reason ) ) { 00078 print "FAILED to delete image file... "; 00079 } 00080 } else { 00081 $art = new Article( $page ); 00082 } 00083 $success = $art->doDeleteArticle( $reason ); 00084 $dbw->immediateCommit(); 00085 if ( $success ) { 00086 print "\n"; 00087 } else { 00088 print " FAILED to delete image page\n"; 00089 } 00090 00091 if ( $interval ) { 00092 sleep( $interval ); 00093 } 00094 wfWaitForSlaves( 5 ); 00095 } 00096 00097 00098