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->mTitleEnc}' AND l_to IN(".
42 implode( ",", $del ) . ")";
43 wfQuery( $sql, DB_WRITE
, $fname );
47 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
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->mTitleEnc}',{$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->mTitleEnc}'";
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->mTitleEnc}','{$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 fixBrokenLinks() {
146 /* Update any brokenlinks *to* this page */
147 /* Call for a newly created page, or just to make sure state is consistent */
149 $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
150 $res = wfQuery( $sql, DB_READ
, $fname );
151 if ( 0 == wfNumRows( $res ) ) { return; }
153 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
154 $now = wfTimestampNow();
155 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
157 while ( $row = wfFetchObject( $res ) ) {
158 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
160 $nl = wfStrencode( Title
::nameOf( $row->bl_from
) );
162 $sql .= "('{$nl}',{$this->mId})";
163 $sql2 .= $row->bl_from
;
166 wfQuery( $sql, DB_WRITE
, $fname );
167 wfQuery( $sql2, DB_WRITE
, $fname );
169 $sql = "DELETE FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
170 wfQuery( $sql, DB_WRITE
, $fname );