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 ( !$wgUseBetterLinksUpdate ) {
25 $this->doDumbUpdate();
29 $fname = "LinksUpdate::doUpdate";
30 wfProfileIn( $fname );
35 if( $wgDBtransactions ) {
37 wfQuery( $sql, DB_WRITE
, $fname );
40 #------------------------------------------------------------------------------
43 if ( $wgLinkCache->incrementalSetup( LINKCACHE_GOOD
, $del, $add ) ) {
44 # Delete where necessary
45 if ( count( $del ) ) {
46 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}' AND l_to IN(".
47 implode( ",", $del ) . ")";
48 wfQuery( $sql, DB_WRITE
, $fname );
52 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
53 wfQuery( $sql, DB_WRITE
, $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 ) {
66 if ( ! $first ) { $sql .= ","; }
69 $sql .= "('{$this->mTitleEnc}',{$lid})";
73 wfQuery( $sql, DB_WRITE
, $fname );
76 #------------------------------------------------------------------------------
79 if ( $wgLinkCache->incrementalSetup( LINKCACHE_BAD
, $del, $add ) ) {
80 # Delete where necessary
81 if ( count( $del ) ) {
82 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId} AND bl_to IN('" .
83 implode( "','", $del ) . "')";
84 wfQuery( $sql, DB_WRITE
, $fname );
88 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
89 wfQuery( $sql, DB_WRITE
, $fname );
92 $add = $wgLinkCache->getBadLinks();
97 if ( 0 != count ( $add ) ) {
98 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
100 foreach( $add as $blt ) {
101 $blt = wfStrencode( $blt );
102 if ( ! $first ) { $sql .= ","; }
105 $sql .= "({$this->mId},'{$blt}')";
109 wfQuery( $sql, DB_WRITE
, $fname );
112 #------------------------------------------------------------------------------
114 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
115 wfQuery( $sql, DB_WRITE
, $fname );
118 $add = $wgLinkCache->getImageLinks();
122 $image = Namespace::getImage();
123 if ( 0 != count ( $add ) ) {
124 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
126 foreach( $add as $iname => $val ) {
127 # FIXME: Change all this to avoid unnecessary duplication
128 $nt = Title
::makeTitle( $image, $iname );
129 $nt->invalidateCache();
131 $iname = wfStrencode( $iname );
132 if ( ! $first ) { $sql .= ","; }
135 $sql .= "('{$this->mTitleEnc}','{$iname}')";
138 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
140 $this->fixBrokenLinks();
142 if( $wgDBtransactions ) {
144 wfQuery( $sql, DB_WRITE
, $fname );
146 wfProfileOut( $fname );
149 function doDumbUpdate()
151 # Old update function. This can probably be removed eventually, if the new one
152 # proves to be stable
153 global $wgLinkCache, $wgDBtransactions;
154 $fname = "LinksUpdate::doDumbUpdate";
155 wfProfileIn( $fname );
157 if( $wgDBtransactions ) {
159 wfQuery( $sql, DB_WRITE
, $fname );
162 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
163 wfQuery( $sql, DB_WRITE
, $fname );
165 $a = $wgLinkCache->getGoodLinks();
167 if ( 0 != count( $a ) ) {
168 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
170 foreach( $a as $lt => $lid ) {
171 if ( ! $first ) { $sql .= ","; }
174 $sql .= "('{$this->mTitleEnc}',{$lid})";
177 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
179 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
180 wfQuery( $sql, DB_WRITE
, $fname );
182 $a = $wgLinkCache->getBadLinks();
184 if ( 0 != count ( $a ) ) {
185 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
187 foreach( $a as $blt ) {
188 $blt = wfStrencode( $blt );
189 if ( ! $first ) { $sql .= ","; }
192 $sql .= "({$this->mId},'{$blt}')";
195 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
197 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
198 wfQuery( $sql, DB_WRITE
, $fname );
200 $a = $wgLinkCache->getImageLinks();
202 if ( 0 != count ( $a ) ) {
203 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
205 foreach( $a as $iname => $val ) {
206 $iname = wfStrencode( $iname );
207 if ( ! $first ) { $sql .= ","; }
210 $sql .= "('{$this->mTitleEnc}','{$iname}')";
213 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
215 $this->fixBrokenLinks();
217 if( $wgDBtransactions ) {
219 wfQuery( $sql, DB_WRITE
, $fname );
221 wfProfileOut( $fname );
224 function fixBrokenLinks() {
225 /* Update any brokenlinks *to* this page */
226 /* Call for a newly created page, or just to make sure state is consistent */
228 $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
229 $res = wfQuery( $sql, DB_READ
, $fname );
230 if ( 0 == wfNumRows( $res ) ) { return; }
232 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
233 $now = wfTimestampNow();
234 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
236 while ( $row = wfFetchObject( $res ) ) {
237 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
239 $nl = wfStrencode( Title
::nameOf( $row->bl_from
) );
241 $sql .= "('{$nl}',{$this->mId})";
242 $sql2 .= $row->bl_from
;
245 wfQuery( $sql, DB_WRITE
, $fname );
246 wfQuery( $sql2, DB_WRITE
, $fname );
248 $sql = "DELETE FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
249 wfQuery( $sql, DB_WRITE
, $fname );