6 /* private */ var $mId, $mTitle;
8 function LinksUpdate( $id, $title )
11 $this->mTitle
= $title;
12 $this->mTitleEnc
= wfStrencode( $title );
17 global $wgUseBetterLinksUpdate, $wgLinkCache, $wgDBtransactions;
19 /* Update link tables with outgoing links from an updated article */
20 /* Relies on the 'link cache' to be filled out */
22 if ( !$wgUseBetterLinksUpdate ) {
23 $this->doDumbUpdate();
27 $fname = "LinksUpdate::doUpdate";
28 wfProfileIn( $fname );
33 if( $wgDBtransactions ) {
35 wfQuery( $sql, $fname );
38 #------------------------------------------------------------------------------
41 if ( $wgLinkCache->incrementalSetup( LINKCACHE_GOOD
, $del, $add ) ) {
42 # Delete where necessary
43 $baseSql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
44 foreach ($del as $title => $id ) {
45 wfDebug( "Incremental deletion from {$this->mTitleEnc} to $title\n" );
46 $sql = $baseSql . " AND l_to={$id}";
47 wfQuery( $sql, $fname );
51 wfDebug( "Complete deletion from {$this->mTitleEnc}\n" );
52 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
53 wfQuery( $sql, $fname );
55 # Get the addition list
56 $add = $wgLinkCache->getGoodLinks();
61 if ( 0 != count( $add ) ) {
62 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
64 foreach( $add as $lt => $lid ) {
65 wfDebug( "Inserting from {$this->mTitleEnc} to $lt\n" );
67 if ( ! $first ) { $sql .= ","; }
70 $sql .= "('{$this->mTitleEnc}',{$lid})";
73 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
75 #------------------------------------------------------------------------------
78 if ( $wgLinkCache->incrementalSetup( LINKCACHE_BAD
, $del, $add ) ) {
79 # Delete where necessary
80 $baseSql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
81 foreach ( $del as $title ) {
82 $sql = $baseSql . " AND bl_to={$title}";
83 wfQuery( $sql, $fname );
87 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
88 wfQuery( $sql, $fname );
91 $add = $wgLinkCache->getBadLinks();
96 if ( 0 != count ( $add ) ) {
97 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
99 foreach( $add as $blt ) {
100 $blt = wfStrencode( $blt );
101 if ( ! $first ) { $sql .= ","; }
104 $sql .= "({$this->mId},'{$blt}')";
107 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
109 #------------------------------------------------------------------------------
111 if ( $wgLinkCache->incrementalSetup( LINKCACHE_IMAGE
, $del, $add ) ) {
112 # Delete where necessary
113 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
114 foreach ($del as $title ) {
115 $sql = $baseSql . " AND il_to={$title}";
116 wfQuery( $sql, $fname );
120 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
121 wfQuery( $sql, $fname );
124 $add = $wgLinkCache->getImageLinks();
129 if ( 0 != count ( $add ) ) {
130 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
132 foreach( $add as $iname => $val ) {
133 $iname = wfStrencode( $iname );
134 if ( ! $first ) { $sql .= ","; }
137 $sql .= "('{$this->mTitleEnc}','{$iname}')";
140 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
142 $this->fixBrokenLinks();
144 if( $wgDBtransactions ) {
146 wfQuery( $sql, $fname );
151 function doDumbUpdate()
153 # Old update function. This can probably be removed eventually, if the new one
154 # proves to be stable
155 global $wgLinkCache, $wgDBtransactions;
156 $fname = "LinksUpdate::doDumbUpdate";
157 wfProfileIn( $fname );
159 if( $wgDBtransactions ) {
161 wfQuery( $sql, $fname );
164 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
165 wfQuery( $sql, $fname );
167 $a = $wgLinkCache->getGoodLinks();
169 if ( 0 != count( $a ) ) {
170 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
172 foreach( $a as $lt => $lid ) {
173 if ( ! $first ) { $sql .= ","; }
176 $sql .= "('{$this->mTitleEnc}',{$lid})";
179 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
181 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
182 wfQuery( $sql, $fname );
184 $a = $wgLinkCache->getBadLinks();
186 if ( 0 != count ( $a ) ) {
187 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
189 foreach( $a as $blt ) {
190 $blt = wfStrencode( $blt );
191 if ( ! $first ) { $sql .= ","; }
194 $sql .= "({$this->mId},'{$blt}')";
197 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
199 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
200 wfQuery( $sql, $fname );
202 $a = $wgLinkCache->getImageLinks();
204 if ( 0 != count ( $a ) ) {
205 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
207 foreach( $a as $iname => $val ) {
208 $iname = wfStrencode( $iname );
209 if ( ! $first ) { $sql .= ","; }
212 $sql .= "('{$this->mTitleEnc}','{$iname}')";
215 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
217 $this->fixBrokenLinks();
219 if( $wgDBtransactions ) {
221 wfQuery( $sql, $fname );
226 function fixBrokenLinks() {
227 /* Update any brokenlinks *to* this page */
228 /* Call for a newly created page, or just to make sure state is consistent */
230 $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
231 $res = wfQuery( $sql, $fname );
232 if ( 0 == wfNumRows( $res ) ) { return; }
234 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
235 $now = wfTimestampNow();
236 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
238 while ( $row = wfFetchObject( $res ) ) {
239 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
241 $nl = wfStrencode( Article
::nameOf( $row->bl_from
) );
243 $sql .= "('{$nl}',{$this->mId})";
244 $sql2 .= $row->bl_from
;
247 wfQuery( $sql, $fname );
248 wfQuery( $sql2, $fname );
250 $sql = "DELETE FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
251 wfQuery( $sql, $fname );