6 /* private */ var $mId, $mTitle;
8 function LinksUpdate( $id, $title )
11 $this->mTitle
= $title;
12 $this->mTitleEnc
= wfStrencode( $title );
18 global $wgUseBetterLinksUpdate, $wgLinkCache, $wgDBtransactions;
20 /* Update link tables with outgoing links from an updated article */
21 /* Relies on the 'link cache' to be filled out */
23 // Make sure links cache is regenerated on next load
24 wfQuery("DELETE FROM linkscc WHERE lcc_title = '{$safeTitle}'", DB_WRITE
);
26 if ( !$wgUseBetterLinksUpdate ) {
27 $this->doDumbUpdate();
31 $fname = "LinksUpdate::doUpdate";
32 wfProfileIn( $fname );
37 if( $wgDBtransactions ) {
39 wfQuery( $sql, DB_WRITE
, $fname );
42 #------------------------------------------------------------------------------
45 if ( $wgLinkCache->incrementalSetup( LINKCACHE_GOOD
, $del, $add ) ) {
46 # Delete where necessary
47 if ( count( $del ) ) {
48 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}' AND l_to IN(".
49 implode( ",", $del ) . ")";
50 wfQuery( $sql, DB_WRITE
, $fname );
54 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
55 wfQuery( $sql, DB_WRITE
, $fname );
57 # Get the addition list
58 $add = $wgLinkCache->getGoodLinks();
63 if ( 0 != count( $add ) ) {
64 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
66 foreach( $add as $lt => $lid ) {
68 if ( ! $first ) { $sql .= ","; }
71 $sql .= "('{$this->mTitleEnc}',{$lid})";
75 wfQuery( $sql, DB_WRITE
, $fname );
78 #------------------------------------------------------------------------------
81 if ( $wgLinkCache->incrementalSetup( LINKCACHE_BAD
, $del, $add ) ) {
82 # Delete where necessary
83 if ( count( $del ) ) {
84 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId} AND bl_to IN('" .
85 implode( "','", $del ) . "')";
86 wfQuery( $sql, DB_WRITE
, $fname );
90 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
91 wfQuery( $sql, DB_WRITE
, $fname );
94 $add = $wgLinkCache->getBadLinks();
99 if ( 0 != count ( $add ) ) {
100 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
102 foreach( $add as $blt ) {
103 $blt = wfStrencode( $blt );
104 if ( ! $first ) { $sql .= ","; }
107 $sql .= "({$this->mId},'{$blt}')";
111 wfQuery( $sql, DB_WRITE
, $fname );
114 #------------------------------------------------------------------------------
116 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
117 wfQuery( $sql, DB_WRITE
, $fname );
120 $add = $wgLinkCache->getImageLinks();
124 if ( 0 != count ( $add ) ) {
125 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
127 foreach( $add as $iname => $val ) {
128 $iname = wfStrencode( $iname );
129 if ( ! $first ) { $sql .= ","; }
132 $sql .= "('{$this->mTitleEnc}','{$iname}')";
135 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
137 $this->fixBrokenLinks();
139 if( $wgDBtransactions ) {
141 wfQuery( $sql, DB_WRITE
, $fname );
143 wfProfileOut( $fname );
146 function doDumbUpdate()
148 # Old update function. This can probably be removed eventually, if the new one
149 # proves to be stable
150 global $wgLinkCache, $wgDBtransactions;
151 $fname = "LinksUpdate::doDumbUpdate";
152 wfProfileIn( $fname );
154 if( $wgDBtransactions ) {
156 wfQuery( $sql, DB_WRITE
, $fname );
159 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
160 wfQuery( $sql, DB_WRITE
, $fname );
162 $a = $wgLinkCache->getGoodLinks();
164 if ( 0 != count( $a ) ) {
165 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
167 foreach( $a as $lt => $lid ) {
168 if ( ! $first ) { $sql .= ","; }
171 $sql .= "('{$this->mTitleEnc}',{$lid})";
174 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
176 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
177 wfQuery( $sql, DB_WRITE
, $fname );
179 $a = $wgLinkCache->getBadLinks();
181 if ( 0 != count ( $a ) ) {
182 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
184 foreach( $a as $blt ) {
185 $blt = wfStrencode( $blt );
186 if ( ! $first ) { $sql .= ","; }
189 $sql .= "({$this->mId},'{$blt}')";
192 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
194 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
195 wfQuery( $sql, DB_WRITE
, $fname );
197 $a = $wgLinkCache->getImageLinks();
199 if ( 0 != count ( $a ) ) {
200 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
202 foreach( $a as $iname => $val ) {
203 $iname = wfStrencode( $iname );
204 if ( ! $first ) { $sql .= ","; }
207 $sql .= "('{$this->mTitleEnc}','{$iname}')";
210 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
212 $this->fixBrokenLinks();
214 if( $wgDBtransactions ) {
216 wfQuery( $sql, DB_WRITE
, $fname );
218 wfProfileOut( $fname );
221 function fixBrokenLinks() {
222 /* Update any brokenlinks *to* this page */
223 /* Call for a newly created page, or just to make sure state is consistent */
225 $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
226 $res = wfQuery( $sql, DB_READ
, $fname );
227 if ( 0 == wfNumRows( $res ) ) { return; }
229 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
230 $now = wfTimestampNow();
231 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
233 while ( $row = wfFetchObject( $res ) ) {
234 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
236 $nl = wfStrencode( Title
::nameOf( $row->bl_from
) );
238 $sql .= "('{$nl}',{$this->mId})";
239 $sql2 .= $row->bl_from
;
242 wfQuery( $sql, DB_WRITE
, $fname );
243 wfQuery( $sql2, DB_WRITE
, $fname );
245 $sql = "DELETE FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
246 wfQuery( $sql, DB_WRITE
, $fname );