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( "','", array_map( "wfStrencode", $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 );
130 $nt->invalidateCache();
132 $iname = wfStrencode( $iname );
133 if ( ! $first ) { $sql .= ","; }
136 $sql .= "('{$this->mTitleEnc}','{$iname}')";
139 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
141 $this->fixBrokenLinks();
143 if( $wgDBtransactions ) {
145 wfQuery( $sql, DB_WRITE
, $fname );
147 wfProfileOut( $fname );
150 function doDumbUpdate()
152 # Old update function. This can probably be removed eventually, if the new one
153 # proves to be stable
154 global $wgLinkCache, $wgDBtransactions;
155 $fname = "LinksUpdate::doDumbUpdate";
156 wfProfileIn( $fname );
158 if( $wgDBtransactions ) {
160 wfQuery( $sql, DB_WRITE
, $fname );
163 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
164 wfQuery( $sql, DB_WRITE
, $fname );
166 $a = $wgLinkCache->getGoodLinks();
168 if ( 0 != count( $a ) ) {
169 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
171 foreach( $a as $lt => $lid ) {
172 if ( ! $first ) { $sql .= ","; }
175 $sql .= "('{$this->mTitleEnc}',{$lid})";
178 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
180 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
181 wfQuery( $sql, DB_WRITE
, $fname );
183 $a = $wgLinkCache->getBadLinks();
185 if ( 0 != count ( $a ) ) {
186 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
188 foreach( $a as $blt ) {
189 $blt = wfStrencode( $blt );
190 if ( ! $first ) { $sql .= ","; }
193 $sql .= "({$this->mId},'{$blt}')";
196 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
198 $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
199 wfQuery( $sql, DB_WRITE
, $fname );
201 $a = $wgLinkCache->getImageLinks();
203 if ( 0 != count ( $a ) ) {
204 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
206 foreach( $a as $iname => $val ) {
207 $iname = wfStrencode( $iname );
208 if ( ! $first ) { $sql .= ","; }
211 $sql .= "('{$this->mTitleEnc}','{$iname}')";
214 if ( "" != $sql ) { wfQuery( $sql, DB_WRITE
, $fname ); }
216 $this->fixBrokenLinks();
218 if( $wgDBtransactions ) {
220 wfQuery( $sql, DB_WRITE
, $fname );
222 wfProfileOut( $fname );
225 function fixBrokenLinks() {
226 /* Update any brokenlinks *to* this page */
227 /* Call for a newly created page, or just to make sure state is consistent */
229 $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
230 $res = wfQuery( $sql, DB_READ
, $fname );
231 if ( 0 == wfNumRows( $res ) ) { return; }
233 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
234 $now = wfTimestampNow();
235 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
237 while ( $row = wfFetchObject( $res ) ) {
238 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
240 $nl = wfStrencode( Title
::nameOf( $row->bl_from
) );
242 $sql .= "('{$nl}',{$this->mId})";
243 $sql2 .= $row->bl_from
;
246 wfQuery( $sql, DB_WRITE
, $fname );
247 wfQuery( $sql2, DB_WRITE
, $fname );
249 $sql = "DELETE FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
250 wfQuery( $sql, DB_WRITE
, $fname );