Index: branches/REL1_2/phase3/index.php |
— | — | @@ -83,11 +83,11 @@ |
84 | 84 | # If the user is not logged in, the Namespace:title of the article must be in the Read array in |
85 | 85 | # order for the user to see it. |
86 | 86 | if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) { |
87 | | - if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) { |
88 | | - $wgOut->loginToUse(); |
89 | | - $wgOut->output(); |
90 | | - exit; |
91 | | - } |
| 87 | + if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) { |
| 88 | + $wgOut->loginToUse(); |
| 89 | + $wgOut->output(); |
| 90 | + exit; |
| 91 | + } |
92 | 92 | } |
93 | 93 | |
94 | 94 | |
— | — | @@ -97,9 +97,18 @@ |
98 | 98 | } else { |
99 | 99 | wfGo( $search ); |
100 | 100 | } |
101 | | -} else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) { |
| 101 | +} else if ( !$wgTitle or $wgTitle->getDBkey() == "" ) { |
102 | 102 | $wgTitle = Title::newFromText( wfMsg( "badtitle" ) ); |
103 | 103 | $wgOut->errorpage( "badtitle", "badtitletext" ); |
| 104 | +} else if ( $wgTitle->getInterwiki() != "" ) { |
| 105 | + $url = $wgTitle->getFullUrl(); |
| 106 | + # Check for a redirect loop |
| 107 | + if ( !preg_match( "/^" . preg_quote( $wgServer ) . "/", $url ) && $wgTitle->isLocal() ) { |
| 108 | + $wgOut->redirect( $url ); |
| 109 | + } else { |
| 110 | + $wgTitle = Title::newFromText( wfMsg( "badtitle" ) ); |
| 111 | + $wgOut->errorpage( "badtitle", "badtitletext" ); |
| 112 | + } |
104 | 113 | } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) { |
105 | 114 | /* redirect to canonical url, make it a 301 to allow caching */ |
106 | 115 | $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ), '301'); |
Index: branches/REL1_2/phase3/includes/Title.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | # See title.doc |
4 | 4 | |
5 | | -/* private static */ $title_interwiki_cache = array(); |
| 5 | +/* private */ $wgTitleInterwikiCache = array(); |
6 | 6 | |
7 | 7 | class Title { |
8 | 8 | /* private */ var $mTextform, $mUrlform, $mDbkeyform; |
— | — | @@ -132,19 +132,21 @@ |
133 | 133 | |
134 | 134 | function getInterwikiLink( $key ) |
135 | 135 | { |
136 | | - global $wgMemc, $wgDBname, $title_interwiki_cache; |
| 136 | + global $wgMemc, $wgDBname, $wgTitleInterwikiCache, $wgInterwikiExpiry; |
137 | 137 | $k = "$wgDBname:interwiki:$key"; |
| 138 | + |
| 139 | + if( array_key_exists( $k, $wgTitleInterwikiCache ) ) { |
| 140 | + return $wgTitleInterwikiCache[$k]->iw_url; |
| 141 | + } |
138 | 142 | |
139 | | - if( array_key_exists( $k, $title_interwiki_cache ) ) |
140 | | - return $title_interwiki_cache[$k]->iw_url; |
141 | | - |
142 | 143 | $s = $wgMemc->get( $k ); |
143 | | - if( $s ) { |
144 | | - $title_interwiki_cache[$k] = $s; |
| 144 | + # Ignore old keys with no iw_local |
| 145 | + if( $s && isset( $s->iw_local ) ) { |
| 146 | + $wgTitleInterwikiCache[$k] = $s; |
145 | 147 | return $s->iw_url; |
146 | 148 | } |
147 | 149 | $dkey = wfStrencode( $key ); |
148 | | - $query = "SELECT iw_url FROM interwiki WHERE iw_prefix='$dkey'"; |
| 150 | + $query = "SELECT iw_url,iw_local FROM interwiki WHERE iw_prefix='$dkey'"; |
149 | 151 | $res = wfQuery( $query, DB_READ, "Title::getInterwikiLink" ); |
150 | 152 | if(!$res) return ""; |
151 | 153 | |
— | — | @@ -153,11 +155,24 @@ |
154 | 156 | $s = (object)false; |
155 | 157 | $s->iw_url = ""; |
156 | 158 | } |
157 | | - $wgMemc->set( $k, $s ); |
158 | | - $title_interwiki_cache[$k] = $s; |
| 159 | + $wgMemc->set( $k, $s, $wgInterwikiExpiry ); |
| 160 | + $wgTitleInterwikiCache[$k] = $s; |
159 | 161 | return $s->iw_url; |
160 | 162 | } |
161 | 163 | |
| 164 | + function isLocal() { |
| 165 | + global $wgTitleInterwikiCache, $wgDBname; |
| 166 | + |
| 167 | + if ( $this->mInterwiki != "" ) { |
| 168 | + # Make sure key is loaded into cache |
| 169 | + $this->getInterwikiLink( $this->mInterwiki ); |
| 170 | + $k = "$wgDBname:interwiki:" . $this->mInterwiki; |
| 171 | + return (bool)($wgTitleInterwikiCache[$k]->iw_local); |
| 172 | + } else { |
| 173 | + return true; |
| 174 | + } |
| 175 | + } |
| 176 | + |
162 | 177 | function getText() { return $this->mTextform; } |
163 | 178 | function getURL() { return $this->mUrlform; } |
164 | 179 | function getDBkey() { return $this->mDbkeyform; } |
Index: branches/REL1_2/phase3/includes/DefaultSettings.php |
— | — | @@ -97,6 +97,7 @@ |
98 | 98 | $wgLocalInterwiki = "w"; |
99 | 99 | $wgShowIPinHeader = true; # For non-logged in users |
100 | 100 | $wgMaxNameChars = 32; # Maximum number of bytes in username |
| 101 | +$wgInterwikiExpiry = 10800; # Expiry time for cache of interwiki table |
101 | 102 | |
102 | 103 | # Translation using MediaWiki: namespace |
103 | 104 | # This will increase load times by 25-60% unless memcached is installed |