MediaWiki的标题和链接处理

<?php
function showTitle($title){
    $title = iconv('gbk', 'utf-8', str_replace(' ', '_', $title));
    $sql = "SELECT page_title FROM  `page` WHERE  `page_title` LIKE  '%$title%'";
    $result = mysql_query( $sql );
    while ( $line = mysql_fetch_array( $result ) ) {
        echo iconv('utf-8', 'gbk', $line[0]) . "\n";
    }
    mysql_free_result( $result );

    echo "-------------------------- \n";
    /*$sql = "SELECT pl_from, pl_title FROM  `pagelinks` WHERE  `pl_title` LIKE  '%$title%'";
    $result = mysql_query( $sql );
    while ( $line = mysql_fetch_array( $result ) ) {
        echo $line[0] . " -> " . iconv('utf-8', 'gbk', $line[1]) . "\n";
    }
    mysql_free_result( $result );*/
}

function findDeadLinks($title){
    $title = iconv('gbk', 'utf-8', str_replace(' ', '_', $title));
    $sql = "SELECT page_title FROM `page` p, revision r, text t WHERE page_latest = r.rev_id and r.rev_text_id = t.old_id and old_text like '%$title%'";
    $result = mysql_query( $sql );
    while ( $line = mysql_fetch_array( $result ) ) {
        echo 'http://witube.hkma.org.gz/index.php?title=' . iconv('utf-8', 'gbk', $line[0]) . "\n";
    }
    mysql_free_result( $result );
}

function deleteTitle($title){
    $title = iconv('gbk', 'utf-8', str_replace(' ', '_', $title));
    $sql = "delete FROM `pagelinks` WHERE  `pl_title` = '$title'";
    mysql_query( $sql );
    echo "Record Deleted: " . mysql_affected_rows() . "\n";
}

function main(){
    $link = mysql_connect( 'Server', 'wiki', 'passwd' ) or die( 'Could not connect' . mysql_error() );
    mysql_select_db( 'wiki' );
    //deleteTitle('规范参考/技术类/语法检查/CheckStyle/AbstractBase/公共属性列表');

    $handle = fopen("Noname2", "r");
    while (!feof($handle)) {
        $item = fgets($handle);
        $item = str_replace("\r\n", '', $item);
        echo $item . "\n";
        deleteTitle($item);
    }
    fclose($handle);
    
    /*$title = "ruts2Adapter替换I18nStrut";
    showTitle($title);*/
    //findDeadLinks('规范参考/技术类');
    mysql_close( $link );
}
main()
?>

你可能感兴趣的:(MediaWiki的标题和链接处理)