Index: trunk/phpwiki/newcodebase/LinkCache.php |
— | — | @@ -0,0 +1,71 @@ |
| 2 | +<? |
| 3 | +# Cache for article titles and ids linked from one source |
| 4 | + |
| 5 | +class LinkCache { |
| 6 | + |
| 7 | + /* private */ var $mGoodLinks, $mBadLinks; |
| 8 | + |
| 9 | + function LinkCache() |
| 10 | + { |
| 11 | + $this->mGoodLinks = $this->mBadLinks = array(); |
| 12 | + } |
| 13 | + |
| 14 | + function getGoodLinkID( $title ) |
| 15 | + { |
| 16 | + if ( key_exists( $title, $this->mGoodLinks ) ) { |
| 17 | + return $this->mGoodLinks[$title]; |
| 18 | + } else { |
| 19 | + return 0; |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + function isBadLink( $title ) |
| 24 | + { |
| 25 | + return in_array( $title, $this->mBadLinks ); |
| 26 | + } |
| 27 | + |
| 28 | + function addGoodLink( $id, $title ) |
| 29 | + { |
| 30 | + $this->mGoodLinks[$title] = $id; |
| 31 | + } |
| 32 | + |
| 33 | + function addBadLink( $title ) |
| 34 | + { |
| 35 | + if ( ! $this->isBadLink( $title ) ) { |
| 36 | + array_push( $this->mBadLinks, $title ); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + function getGoodLinks() { return $this->mGoodLinks; } |
| 41 | + function getBadLinks() { return $this->mBadLinks; } |
| 42 | + |
| 43 | + function addLink( $title ) |
| 44 | + { |
| 45 | + if ( $this->isBadLink( $title ) ) { return 0; } |
| 46 | + $id = $this->getGoodLinkID( $title ); |
| 47 | + if ( 0 != $id ) { return $id; } |
| 48 | + |
| 49 | + $nt = Title::newFromDBKey( $title ); |
| 50 | + $ns = $nt->getNamespace(); |
| 51 | + $t = $nt->getDBKey(); |
| 52 | + |
| 53 | + $conn = wfGetDB(); |
| 54 | + $sql = "SELECT cur_id FROM cur WHERE (cur_namespace=" . |
| 55 | + "{$ns} AND cur_title='{$t}')"; |
| 56 | + # wfDebug( "Title: 1: $sql\n" ); |
| 57 | + $res = mysql_query( $sql, $conn ); |
| 58 | + |
| 59 | + if ( ( false === $res ) || 0 == mysql_num_rows( $res ) ) { |
| 60 | + $id = 0; |
| 61 | + } else { |
| 62 | + $s = mysql_fetch_object( $res ); |
| 63 | + $id = $s->cur_id; |
| 64 | + mysql_free_result( $res ); |
| 65 | + } |
| 66 | + if ( 0 == $id ) { $this->addBadLink( $title ); } |
| 67 | + else { $this->addGoodLink( $id, $title ); } |
| 68 | + return $id; |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +?> |
Property changes on: trunk/phpwiki/newcodebase/LinkCache.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 73 | + native |
Added: svn:keywords |
2 | 74 | + Author Date Id Revision |