MediaWiki的标题和链接处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?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()
?>