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 if ( count( $del ) ) {
44 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}' AND l_to IN(".
45 implode( ",", $del ) . ")";
46 wfQuery( $sql, $fname );
50 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
51 wfQuery( $sql, $fname );
53 # Get the addition list
54 $add = $wgLinkCache->getGoodLinks();
59 if ( 0 != count( $add ) ) {
60 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
62 foreach( $add as $lt => $lid ) {
64 if ( ! $first ) { $sql .= ","; }
67 $sql .= "('{$this->mTitleEnc}',{$lid})";
71 wfQuery( $sql, $fname );
74 #------------------------------------------------------------------------------
77 if ( $wgLinkCache->incrementalSetup( LINKCACHE_BAD
, $del, $add ) ) {
78 # Delete where necessary
79 if ( count( $del ) ) {
80 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId} AND bl_to IN('" .
81 implode( "','", $del ) . "')";
82 wfQuery( $sql, $fname );
86 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
87 wfQuery( $sql, $fname );
90 $add = $wgLinkCache->getBadLinks();
95 if ( 0 != count ( $add ) ) {
96 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
98 foreach( $add as $blt ) {
99 $blt = wfStrencode( $blt );
100 if ( ! $first ) { $sql .= ","; }
103 $sql .= "({$this->mId},'{$blt}')";
107 wfQuery( $sql, $fname );
110 #------------------------------------------------------------------------------
112 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
113 wfQuery( $sql, $fname );
116 $add = $wgLinkCache->getImageLinks();
120 if ( 0 != count ( $add ) ) {
121 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
123 foreach( $add as $iname => $val ) {
124 $iname = wfStrencode( $iname );
125 if ( ! $first ) { $sql .= ","; }
128 $sql .= "('{$this->mTitleEnc}','{$iname}')";
131 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
133 $this->fixBrokenLinks();
135 if( $wgDBtransactions ) {
137 wfQuery( $sql, $fname );
142 function doDumbUpdate()
144 # Old update function. This can probably be removed eventually, if the new one
145 # proves to be stable
146 global $wgLinkCache, $wgDBtransactions;
147 $fname = "LinksUpdate::doDumbUpdate";
148 wfProfileIn( $fname );
150 if( $wgDBtransactions ) {
152 wfQuery( $sql, $fname );
155 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
156 wfQuery( $sql, $fname );
158 $a = $wgLinkCache->getGoodLinks();
160 if ( 0 != count( $a ) ) {
161 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
163 foreach( $a as $lt => $lid ) {
164 if ( ! $first ) { $sql .= ","; }
167 $sql .= "('{$this->mTitleEnc}',{$lid})";
170 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
172 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
173 wfQuery( $sql, $fname );
175 $a = $wgLinkCache->getBadLinks();
177 if ( 0 != count ( $a ) ) {
178 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
180 foreach( $a as $blt ) {
181 $blt = wfStrencode( $blt );
182 if ( ! $first ) { $sql .= ","; }
185 $sql .= "({$this->mId},'{$blt}')";
188 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
190 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
191 wfQuery( $sql, $fname );
193 $a = $wgLinkCache->getImageLinks();
195 if ( 0 != count ( $a ) ) {
196 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
198 foreach( $a as $iname => $val ) {
199 $iname = wfStrencode( $iname );
200 if ( ! $first ) { $sql .= ","; }
203 $sql .= "('{$this->mTitleEnc}','{$iname}')";
206 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
208 $this->fixBrokenLinks();
210 if( $wgDBtransactions ) {
212 wfQuery( $sql, $fname );
217 function fixBrokenLinks() {
218 /* Update any brokenlinks *to* this page */
219 /* Call for a newly created page, or just to make sure state is consistent */
221 $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
222 $res = wfQuery( $sql, $fname );
223 if ( 0 == wfNumRows( $res ) ) { return; }
225 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
226 $now = wfTimestampNow();
227 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
229 while ( $row = wfFetchObject( $res ) ) {
230 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
232 $nl = wfStrencode( Article
::nameOf( $row->bl_from
) );
234 $sql .= "('{$nl}',{$this->mId})";
235 $sql2 .= $row->bl_from
;
238 wfQuery( $sql, $fname );
239 wfQuery( $sql2, $fname );
241 $sql = "DELETE FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
242 wfQuery( $sql, $fname );