Initial revision
[lhc/web/wiklou.git] / includes / LinksUpdate.php
1 <?
2 # See deferred.doc
3
4 class LinksUpdate {
5
6 /* private */ var $mId, $mTitle;
7
8 function LinksUpdate( $id, $title )
9 {
10 $this->mId = $id;
11 $this->mTitle = $title;
12 }
13
14 function doUpdate()
15 {
16 global $wgLinkCache, $wgDBtransactions;
17 $fname = "LinksUpdate::doUpdate";
18 wfProfileIn( $fname );
19 $t = wfStrencode( $this->mTitle );
20
21 if( $wgDBtransactions ) {
22 $sql = "BEGIN";
23 wfQuery( $sql, $fname );
24 }
25
26 $sql = "DELETE FROM links WHERE l_from='{$t}'";
27 wfQuery( $sql, $fname );
28
29 $a = $wgLinkCache->getGoodLinks();
30 $sql = "";
31 if ( 0 != count( $a ) ) {
32 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
33 $first = true;
34 foreach( $a as $lt => $lid ) {
35 if ( ! $first ) { $sql .= ","; }
36 $first = false;
37
38 $sql .= "('{$t}',{$lid})";
39 }
40 }
41 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
42
43 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
44 wfQuery( $sql, $fname );
45
46 $a = $wgLinkCache->getBadLinks();
47 $sql = "";
48 if ( 0 != count ( $a ) ) {
49 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
50 $first = true;
51 foreach( $a as $blt ) {
52 $blt = wfStrencode( $blt );
53 if ( ! $first ) { $sql .= ","; }
54 $first = false;
55
56 $sql .= "({$this->mId},'{$blt}')";
57 }
58 }
59 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
60
61 $sql = "DELETE FROM imagelinks WHERE il_from='{$t}'";
62 wfQuery( $sql, $fname );
63
64 $a = $wgLinkCache->getImageLinks();
65 $sql = "";
66 if ( 0 != count ( $a ) ) {
67 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
68 $first = true;
69 foreach( $a as $iname => $val ) {
70 $iname = wfStrencode( $iname );
71 if ( ! $first ) { $sql .= ","; }
72 $first = false;
73
74 $sql .= "('{$t}','{$iname}')";
75 }
76 }
77 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
78
79 $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$t}'";
80 $res = wfQuery( $sql, $fname );
81 if ( 0 == wfNumRows( $res ) ) { return; }
82
83 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
84 $now = wfTimestampNow();
85 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
86 $first = true;
87 while ( $row = wfFetchObject( $res ) ) {
88 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
89 $first = false;
90 $nl = wfStrencode( Article::nameOf( $row->bl_from ) );
91
92 $sql .= "('{$nl}',{$this->mId})";
93 $sql2 .= $row->bl_from;
94 }
95 $sql2 .= ")";
96 wfQuery( $sql, $fname );
97 wfQuery( $sql2, $fname );
98
99 $sql = "DELETE FROM brokenlinks WHERE bl_to='{$t}'";
100 wfQuery( $sql, $fname );
101
102 if( $wgDBtransactions ) {
103 $sql = "COMMIT";
104 wfQuery( $sql, $fname );
105 }
106 wfProfileOut();
107 }
108 }
109
110 ?>