2 # Cache for article titles and ids linked from one source
6 /* private */ var $mGoodLinks, $mBadLinks, $mActive;
7 /* private */ var $mImageLinks;
11 $this->mActive
= true;
12 $this->mGoodLinks
= array();
13 $this->mBadLinks
= array();
14 $this->mImageLinks
= array();
17 function getGoodLinkID( $title )
19 if ( array_key_exists( $title, $this->mGoodLinks
) ) {
20 return $this->mGoodLinks
[$title];
26 function isBadLink( $title )
28 return in_array( $title, $this->mBadLinks
);
31 function addGoodLink( $id, $title )
33 if ( $this->mActive
) {
34 $this->mGoodLinks
[$title] = $id;
38 function addBadLink( $title )
40 if ( $this->mActive
&& ( ! $this->isBadLink( $title ) ) ) {
41 array_push( $this->mBadLinks
, $title );
45 function addImageLink( $title )
47 if ( $this->mActive
) { $this->mImageLinks
[$title] = 1; }
50 function clearBadLink( $title )
52 $index = array_search( $title, $this->mBadLinks
);
53 if ( isset( $index ) ) {
54 unset( $this->mBadLinks
[$index] );
58 function suspend() { $this->mActive
= false; }
59 function resume() { $this->mActive
= true; }
60 function getGoodLinks() { return $this->mGoodLinks
; }
61 function getBadLinks() { return $this->mBadLinks
; }
62 function getImageLinks() { return $this->mImageLinks
; }
64 function addLink( $title )
66 if ( $this->isBadLink( $title ) ) { return 0; }
67 $id = $this->getGoodLinkID( $title );
68 if ( 0 != $id ) { return $id; }
70 wfProfileIn( "LinkCache::addLink-checkdatabase" );
72 $nt = Title
::newFromDBkey( $title );
73 $ns = $nt->getNamespace();
76 if ( "" == $t ) { return 0; }
77 $sql = "SELECT HIGH_PRIORITY cur_id FROM cur WHERE cur_namespace=" .
78 "{$ns} AND cur_title='" . wfStrencode( $t ) . "'";
79 $res = wfQuery( $sql, "LinkCache::addLink" );
81 if ( 0 == wfNumRows( $res ) ) {
84 $s = wfFetchObject( $res );
87 if ( 0 == $id ) { $this->addBadLink( $title ); }
88 else { $this->addGoodLink( $id, $title ); }
93 function preFill( $fromtitle )
95 wfProfileIn( "LinkCache::preFill" );
96 # Note -- $fromtitle is a Title *object*
97 $dbkeyfrom = wfStrencode( $fromtitle->getPrefixedDBKey() );
98 $sql = "SELECT HIGH_PRIORITY cur_id,cur_namespace,cur_title
100 WHERE cur_id=l_to AND l_from='{$dbkeyfrom}'";
101 $res = wfQuery( $sql, "LinkCache::preFill" );
102 while( $s = wfFetchObject( $res ) ) {
103 $this->addGoodLink( $s->cur_id
,
104 Title
::makeName( $s->cur_namespace
, $s->cur_title
)
108 $sql = "SELECT HIGH_PRIORITY bl_to
110 WHERE bl_from='{$dbkeyfrom}'";
111 $res = wfQuery( $sql, "LinkCache::preFill" );
112 while( $s = wfFetchObject( $res ) ) {
113 $this->addBadLink( $s->bl_to
);