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 $fname = "LinksUpdate::doUpdate";
25 wfProfileIn( $fname );
30 if( $wgDBtransactions ) {
32 wfQuery( $sql, DB_WRITE
, $fname );
35 #------------------------------------------------------------------------------
38 if ( $wgLinkCache->incrementalSetup( LINKCACHE_GOOD
, $del, $add ) ) {
39 # Delete where necessary
40 if ( count( $del ) ) {
41 $sql = "DELETE FROM links WHERE l_from={$this->mId} AND l_to IN(".
42 implode( ",", $del ) . ")";
43 wfQuery( $sql, DB_WRITE
, $fname );
47 $sql = "DELETE FROM links WHERE l_from={$this->mId}";
48 wfQuery( $sql, DB_WRITE
, $fname );
50 # Get the addition list
51 $add = $wgLinkCache->getGoodLinks();
56 if ( 0 != count( $add ) ) {
57 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
59 foreach( $add as $lt => $lid ) {
61 if ( ! $first ) { $sql .= ","; }
64 $sql .= "({$this->mId},{$lid})";
68 wfQuery( $sql, DB_WRITE
, $fname );
71 #------------------------------------------------------------------------------
74 if ( $wgLinkCache->incrementalSetup( LINKCACHE_BAD
, $del, $add ) ) {
75 # Delete where necessary
76 if ( count( $del ) ) {
77 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId} AND bl_to IN('" .
78 implode( "','", array_map( "wfStrencode", $del ) ) . "')";
79 wfQuery( $sql, DB_WRITE
, $fname );
83 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
84 wfQuery( $sql, DB_WRITE
, $fname );
87 $add = $wgLinkCache->getBadLinks();
92 if ( 0 != count ( $add ) ) {
93 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
95 foreach( $add as $blt ) {
96 $blt = wfStrencode( $blt );
97 if ( ! $first ) { $sql .= ","; }
100 $sql .= "({$this->mId},'{$blt}')";
104 wfQuery( $sql, DB_WRITE
, $fname );
107 #------------------------------------------------------------------------------
109 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mId}'";
110 wfQuery( $sql, DB_WRITE
, $fname );
113 $add = $wgLinkCache->getImageLinks();
117 $image = Namespace::getImage();
118 if ( 0 != count ( $add ) ) {
119 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
121 foreach( $add as $iname => $val ) {
122 # FIXME: Change all this to avoid unnecessary duplication
123 $nt = Title
::makeTitle( $image, $iname );
125 $nt->invalidateCache();
127 $iname = wfStrencode( $iname );
128 if ( ! $first ) { $sql .= ","; }
131 $sql .= "({$this->mId},'{$iname}')";
134 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
136 $this->fixBrokenLinks();
138 if( $wgDBtransactions ) {
140 wfQuery( $sql, DB_WRITE
, $fname );
142 wfProfileOut( $fname );
145 function doDumbUpdate()
147 # Old inefficient update function
148 # Used for rebuilding the link table
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->mId}";
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->mId},{$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->mId}";
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->mId},'{$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 */
224 $fname = "LinksUpdate::fixBrokenLinks";
226 $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
227 $res = wfQuery( $sql, DB_READ
, $fname );
228 if ( 0 == wfNumRows( $res ) ) { return; }
230 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
231 $now = wfTimestampNow();
232 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
234 while ( $row = wfFetchObject( $res ) ) {
235 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
238 $sql .= "({$row->bl_from},{$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 );