36661905c555275fd0d8f365588347ea74ab8d5a
6 /* private */ var $mId, $mTitle;
8 function LinksUpdate( $id, $title )
11 $this->mTitle
= $title;
12 $this->mTitleEnc
= wfStrencode( $title );
18 global $wgUseBetterLinksUpdate, $wgLinkCache, $wgDBtransactions;
19 global $wgEnablePersistentLC;
21 /* Update link tables with outgoing links from an updated article */
22 /* Relies on the 'link cache' to be filled out */
24 if ( $wgEnablePersistentLC ) {
25 // Make sure links cache is regenerated on next load
26 wfQuery("DELETE FROM linkscc WHERE lcc_title = '{$safeTitle}'", DB_WRITE
);
29 if ( !$wgUseBetterLinksUpdate ) {
30 $this->doDumbUpdate();
34 $fname = "LinksUpdate::doUpdate";
35 wfProfileIn( $fname );
40 if( $wgDBtransactions ) {
42 wfQuery( $sql, DB_WRITE
, $fname );
45 #------------------------------------------------------------------------------
48 if ( $wgLinkCache->incrementalSetup( LINKCACHE_GOOD
, $del, $add ) ) {
49 # Delete where necessary
50 if ( count( $del ) ) {
51 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}' AND l_to IN(".
52 implode( ",", $del ) . ")";
53 wfQuery( $sql, DB_WRITE
, $fname );
57 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
58 wfQuery( $sql, DB_WRITE
, $fname );
60 # Get the addition list
61 $add = $wgLinkCache->getGoodLinks();
66 if ( 0 != count( $add ) ) {
67 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
69 foreach( $add as $lt => $lid ) {
71 if ( ! $first ) { $sql .= ","; }
74 $sql .= "('{$this->mTitleEnc}',{$lid})";
78 wfQuery( $sql, DB_WRITE
, $fname );
81 #------------------------------------------------------------------------------
84 if ( $wgLinkCache->incrementalSetup( LINKCACHE_BAD
, $del, $add ) ) {
85 # Delete where necessary
86 if ( count( $del ) ) {
87 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId} AND bl_to IN('" .
88 implode( "','", $del ) . "')";
89 wfQuery( $sql, DB_WRITE
, $fname );
93 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
94 wfQuery( $sql, DB_WRITE
, $fname );
97 $add = $wgLinkCache->getBadLinks();
102 if ( 0 != count ( $add ) ) {
103 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
105 foreach( $add as $blt ) {
106 $blt = wfStrencode( $blt );
107 if ( ! $first ) { $sql .= ","; }
110 $sql .= "({$this->mId},'{$blt}')";
114 wfQuery( $sql, DB_WRITE
, $fname );
117 #------------------------------------------------------------------------------
119 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
120 wfQuery( $sql, DB_WRITE
, $fname );
123 $add = $wgLinkCache->getImageLinks();
127 $image = Namespace::getImage();
128 if ( 0 != count ( $add ) ) {
129 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
131 foreach( $add as $iname => $val ) {
132 # FIXME: Change all this to avoid unnecessary duplication
133 $nt = Title
::makeTitle( $image, $iname );
134 $nt->invalidateCache();
136 $iname = wfStrencode( $iname );
137 if ( ! $first ) { $sql .= ","; }
140 $sql .= "('{$this->mTitleEnc}','{$iname}')";
143 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
145 $this->fixBrokenLinks();
147 if( $wgDBtransactions ) {
149 wfQuery( $sql, DB_WRITE
, $fname );
151 wfProfileOut( $fname );
154 function doDumbUpdate()
156 # Old update function. This can probably be removed eventually, if the new one
157 # proves to be stable
158 global $wgLinkCache, $wgDBtransactions;
159 $fname = "LinksUpdate::doDumbUpdate";
160 wfProfileIn( $fname );
162 if( $wgDBtransactions ) {
164 wfQuery( $sql, DB_WRITE
, $fname );
167 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
168 wfQuery( $sql, DB_WRITE
, $fname );
170 $a = $wgLinkCache->getGoodLinks();
172 if ( 0 != count( $a ) ) {
173 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
175 foreach( $a as $lt => $lid ) {
176 if ( ! $first ) { $sql .= ","; }
179 $sql .= "('{$this->mTitleEnc}',{$lid})";
182 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
184 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
185 wfQuery( $sql, DB_WRITE
, $fname );
187 $a = $wgLinkCache->getBadLinks();
189 if ( 0 != count ( $a ) ) {
190 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
192 foreach( $a as $blt ) {
193 $blt = wfStrencode( $blt );
194 if ( ! $first ) { $sql .= ","; }
197 $sql .= "({$this->mId},'{$blt}')";
200 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
202 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
203 wfQuery( $sql, DB_WRITE
, $fname );
205 $a = $wgLinkCache->getImageLinks();
207 if ( 0 != count ( $a ) ) {
208 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
210 foreach( $a as $iname => $val ) {
211 $iname = wfStrencode( $iname );
212 if ( ! $first ) { $sql .= ","; }
215 $sql .= "('{$this->mTitleEnc}','{$iname}')";
218 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
220 $this->fixBrokenLinks();
222 if( $wgDBtransactions ) {
224 wfQuery( $sql, DB_WRITE
, $fname );
226 wfProfileOut( $fname );
229 function fixBrokenLinks() {
230 /* Update any brokenlinks *to* this page */
231 /* Call for a newly created page, or just to make sure state is consistent */
233 $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
234 $res = wfQuery( $sql, DB_READ
, $fname );
235 if ( 0 == wfNumRows( $res ) ) { return; }
237 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
238 $now = wfTimestampNow();
239 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
241 while ( $row = wfFetchObject( $res ) ) {
242 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
244 $nl = wfStrencode( Title
::nameOf( $row->bl_from
) );
246 $sql .= "('{$nl}',{$this->mId})";
247 $sql2 .= $row->bl_from
;
250 wfQuery( $sql, DB_WRITE
, $fname );
251 wfQuery( $sql2, DB_WRITE
, $fname );
253 $sql = "DELETE FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
254 wfQuery( $sql, DB_WRITE
, $fname );