Fix edit-new-page link for results not found.
[mediawiki.git] / includes / LinksUpdate.php
blob4f1ebbb3b4ef594aa10a8c645b01d40751bcd461
1 <?
2 # See deferred.doc
4 class LinksUpdate {
6 /* private */ var $mId, $mTitle;
8 function LinksUpdate( $id, $title )
10 $this->mId = $id;
11 $this->mTitle = $title;
12 $this->mTitleEnc = wfStrencode( $title );
15 function doUpdate()
17 /* Update link tables with outgoing links from an updated article */
18 /* Currently this is 'dumb', removing all links and putting them back. */
20 /* Relies on the 'link cache' to be filled out */
21 global $wgLinkCache, $wgDBtransactions;
22 $fname = "LinksUpdate::doUpdate";
23 wfProfileIn( $fname );
25 if( $wgDBtransactions ) {
26 $sql = "BEGIN";
27 wfQuery( $sql, $fname );
30 $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
31 wfQuery( $sql, $fname );
33 $a = $wgLinkCache->getGoodLinks();
34 $sql = "";
35 if ( 0 != count( $a ) ) {
36 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
37 $first = true;
38 foreach( $a as $lt => $lid ) {
39 if ( ! $first ) { $sql .= ","; }
40 $first = false;
42 $sql .= "('{$this->mTitleEnc}',{$lid})";
45 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
47 $sql = "DELETE FROM brokenlinks WHERE bl_from={$this->mId}";
48 wfQuery( $sql, $fname );
50 $a = $wgLinkCache->getBadLinks();
51 $sql = "";
52 if ( 0 != count ( $a ) ) {
53 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
54 $first = true;
55 foreach( $a as $blt ) {
56 $blt = wfStrencode( $blt );
57 if ( ! $first ) { $sql .= ","; }
58 $first = false;
60 $sql .= "({$this->mId},'{$blt}')";
63 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
65 $sql = "DELETE FROM imagelinks WHERE il_from='{$t}'";
66 wfQuery( $sql, $fname );
68 $a = $wgLinkCache->getImageLinks();
69 $sql = "";
70 if ( 0 != count ( $a ) ) {
71 $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
72 $first = true;
73 foreach( $a as $iname => $val ) {
74 $iname = wfStrencode( $iname );
75 if ( ! $first ) { $sql .= ","; }
76 $first = false;
78 $sql .= "('{$t}','{$iname}')";
81 if ( "" != $sql ) { wfQuery( $sql, $fname ); }
83 $this->fixBrokenLinks();
85 if( $wgDBtransactions ) {
86 $sql = "COMMIT";
87 wfQuery( $sql, $fname );
89 wfProfileOut();
92 function fixBrokenLinks() {
93 /* Update any brokenlinks *to* this page */
94 /* Call for a newly created page, or just to make sure state is consistent */
96 $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
97 $res = wfQuery( $sql, $fname );
98 if ( 0 == wfNumRows( $res ) ) { return; }
100 $sql = "INSERT INTO links (l_from,l_to) VALUES ";
101 $now = wfTimestampNow();
102 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
103 $first = true;
104 while ( $row = wfFetchObject( $res ) ) {
105 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
106 $first = false;
107 $nl = wfStrencode( Article::nameOf( $row->bl_from ) );
109 $sql .= "('{$nl}',{$this->mId})";
110 $sql2 .= $row->bl_from;
112 $sql2 .= ")";
113 wfQuery( $sql, $fname );
114 wfQuery( $sql2, $fname );
116 $sql = "DELETE FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
117 wfQuery( $sql, $fname );