r3469 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r3468‎ | r3469 | r3470 >
Date:02:25, 4 May 2004
Author:timstarling
Status:old
Tags:
Comment:
Local interwiki prefixes in the URL generate a redirect to the relevant page
Modified paths:
  • /branches/REL1_2/phase3/includes/DefaultSettings.php (modified) (history)
  • /branches/REL1_2/phase3/includes/Title.php (modified) (history)
  • /branches/REL1_2/phase3/index.php (modified) (history)

Diff [purge]

Index: branches/REL1_2/phase3/index.php
@@ -83,11 +83,11 @@
8484 # If the user is not logged in, the Namespace:title of the article must be in the Read array in
8585 # order for the user to see it.
8686 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+ }
9292 }
9393
9494
@@ -97,9 +97,18 @@
9898 } else {
9999 wfGo( $search );
100100 }
101 -} else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) {
 101+} else if ( !$wgTitle or $wgTitle->getDBkey() == "" ) {
102102 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
103103 $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+ }
104113 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
105114 /* redirect to canonical url, make it a 301 to allow caching */
106115 $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ), '301');
Index: branches/REL1_2/phase3/includes/Title.php
@@ -1,7 +1,7 @@
22 <?php
33 # See title.doc
44
5 -/* private static */ $title_interwiki_cache = array();
 5+/* private */ $wgTitleInterwikiCache = array();
66
77 class Title {
88 /* private */ var $mTextform, $mUrlform, $mDbkeyform;
@@ -132,19 +132,21 @@
133133
134134 function getInterwikiLink( $key )
135135 {
136 - global $wgMemc, $wgDBname, $title_interwiki_cache;
 136+ global $wgMemc, $wgDBname, $wgTitleInterwikiCache, $wgInterwikiExpiry;
137137 $k = "$wgDBname:interwiki:$key";
 138+
 139+ if( array_key_exists( $k, $wgTitleInterwikiCache ) ) {
 140+ return $wgTitleInterwikiCache[$k]->iw_url;
 141+ }
138142
139 - if( array_key_exists( $k, $title_interwiki_cache ) )
140 - return $title_interwiki_cache[$k]->iw_url;
141 -
142143 $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;
145147 return $s->iw_url;
146148 }
147149 $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'";
149151 $res = wfQuery( $query, DB_READ, "Title::getInterwikiLink" );
150152 if(!$res) return "";
151153
@@ -153,11 +155,24 @@
154156 $s = (object)false;
155157 $s->iw_url = "";
156158 }
157 - $wgMemc->set( $k, $s );
158 - $title_interwiki_cache[$k] = $s;
 159+ $wgMemc->set( $k, $s, $wgInterwikiExpiry );
 160+ $wgTitleInterwikiCache[$k] = $s;
159161 return $s->iw_url;
160162 }
161163
 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+
162177 function getText() { return $this->mTextform; }
163178 function getURL() { return $this->mUrlform; }
164179 function getDBkey() { return $this->mDbkeyform; }
Index: branches/REL1_2/phase3/includes/DefaultSettings.php
@@ -97,6 +97,7 @@
9898 $wgLocalInterwiki = "w";
9999 $wgShowIPinHeader = true; # For non-logged in users
100100 $wgMaxNameChars = 32; # Maximum number of bytes in username
 101+$wgInterwikiExpiry = 10800; # Expiry time for cache of interwiki table
101102
102103 # Translation using MediaWiki: namespace
103104 # This will increase load times by 25-60% unless memcached is installed

Status & tagging log