function newFromText( $text, $defaultNamespace = NS_MAIN ) {
global $wgTitleCache;
$fname = 'Title::newFromText';
- wfProfileIn( $fname );
if( is_object( $text ) ) {
wfDebugDieBacktrace( 'Title::newFromText given an object' );
* In theory these are value objects and won't get changed...
*/
if( $defaultNamespace == NS_MAIN && isset( $wgTitleCache[$text] ) ) {
- wfProfileOut( $fname );
return $wgTitleCache[$text];
}
$cachedcount++;
$wgTitleCache[$text] =& $t;
}
- wfProfileOut( $fname );
return $t;
} else {
- wfProfileOut( $fname );
$ret = NULL;
return $ret;
}
global $wgInterwikiCache;
$fname = 'Title::getInterwikiLink';
- wfProfileIn( $fname );
-
$key = strtolower( $key );
$k = $wgDBname.':interwiki:'.$key;
if( array_key_exists( $k, $wgTitleInterwikiCache ) ) {
- wfProfileOut( $fname );
return $wgTitleInterwikiCache[$k]->iw_url;
}
if ($wgInterwikiCache) {
- wfProfileOut( $fname );
- return $this->getInterwikiCached( $key );
+ return Title::getInterwikiCached( $key );
}
$s = $wgMemc->get( $k );
# Ignore old keys with no iw_local
if( $s && isset( $s->iw_local ) && isset($s->iw_trans)) {
$wgTitleInterwikiCache[$k] = $s;
- wfProfileOut( $fname );
return $s->iw_url;
}
array( 'iw_url', 'iw_local', 'iw_trans' ),
array( 'iw_prefix' => $key ), $fname );
if( !$res ) {
- wfProfileOut( $fname );
return '';
}
$wgMemc->set( $k, $s, $wgInterwikiExpiry );
$wgTitleInterwikiCache[$k] = $s;
- wfProfileOut( $fname );
return $s->iw_url;
}
global $wgDBname, $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
global $wgTitleInterwikiCache;
static $db, $site;
- if (!db)
+
+ if (!$db)
$db=dba_open($wgInterwikiCache,'r','cdb');
/* Resolve site name */
if ($wgInterwikiScopes>=3 and !$site) {
}
if ($value=='' and $wgInterwikiScopes>=2) {
/* try globals */
- $value = dba_fetch("__globals:{$key}", $db);
+ $value = dba_fetch("__global:{$key}", $db);
}
if ($value=='undef')
$value='';
if ($value!='') {
list($local,$url)=explode(' ',$value,2);
$s->iw_url=$url;
- $s->iw_local=$local;
+ $s->iw_local=(int)$local;
}
$wgTitleInterwikiCache[$wgDBname.':interwiki:'.$key] = $s;
return $s->iw_url;
function isTrans() {
global $wgTitleInterwikiCache, $wgDBname;
- if ($this->mInterwiki == '' || !$this->isLocal())
+ if ($this->mInterwiki == '')
return false;
# Make sure key is loaded into cache
$this->getInterwikiLink( $this->mInterwiki );
if ( $this->isExternal() ) {
$url = $this->getFullURL();
+ if ( $query ) {
+ // This is currently only used for edit section links in the
+ // context of interwiki transclusion. In theory we should
+ // append the query to the end of any existing query string,
+ // but interwiki transclusion is already broken in that case.
+ $url .= "?$query";
+ }
} else {
$dbkey = wfUrlencode( $this->getPrefixedDBkey() );
if ( $query == '' ) {
*/
function isExternal() { return ( '' != $this->mInterwiki ); }
+ /**
+ * Is this page "semi-protected" - the *only* protection is autoconfirm?
+ *
+ * @param string Action to check (default: edit)
+ * @return bool
+ */
+ function isSemiProtected( $action = 'edit' ) {
+ $restrictions = $this->getRestrictions( $action );
+ # We do a full compare because this could be an array
+ foreach( $restrictions as $restriction ) {
+ if( strtolower( $restriction ) != 'autoconfirmed' ) {
+ return( false );
+ }
+ }
+ return( true );
+ }
+
/**
* Does the title correspond to a protected article?
* @param string $what the action the page is protected from,
wfProfileIn( $fname );
global $wgUser;
+
+ $result = true;
+ if ( !wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) ) ) {
+ wfProfileOut( $fname );
+ return $result;
+ }
+
if( NS_SPECIAL == $this->mNamespace ) {
wfProfileOut( $fname );
return false;
function userCanRead() {
global $wgUser;
+ $result = true;
+ if ( !wfRunHooks( 'userCan', array( &$this, &$wgUser, "read", &$result ) ) ) {
+ return $result;
+ }
+
if( $wgUser->isAllowed('read') ) {
return true;
} else {
/* private */ function secureAndSplit() {
global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
$fname = 'Title::secureAndSplit';
- wfProfileIn( $fname );
# Initialisation
static $rxTc = false;
$t = trim( $t, '_' );
if ( '' == $t ) {
- wfProfileOut( $fname );
return false;
}
if( false !== strpos( $t, UTF8_REPLACEMENT ) ) {
# Contained illegal UTF-8 sequences or forbidden Unicode chars.
- wfProfileOut( $fname );
return false;
}
if( !$firstPass ) {
# Can't make a local interwiki link to an interwiki link.
# That's just crazy!
- wfProfileOut( $fname );
return false;
}
if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) {
if( $t == '' ) {
# Can't have an empty self-link
- wfProfileOut( $fname );
return false;
}
$this->mInterwiki = '';
# Do another namespace split...
continue;
}
+
+ # If there's an initial colon after the interwiki, that also
+ # resets the default namespace
+ if ( $t !== '' && $t[0] == ':' ) {
+ $this->mNamespace = NS_MAIN;
+ $t = substr( $t, 1 );
+ }
}
# If there's no recognized interwiki or namespace,
# then let the colon expression be part of the title.
# Reject illegal characters.
#
if( preg_match( $rxTc, $r ) ) {
- wfProfileOut( $fname );
return false;
}
strpos( $r, '/./' ) !== false ||
strpos( $r, '/../' ) !== false ) )
{
- wfProfileOut( $fname );
return false;
}
# We shouldn't need to query the DB for the size.
#$maxSize = $dbr->textFieldSize( 'page', 'page_title' );
if ( strlen( $r ) > 255 ) {
- wfProfileOut( $fname );
return false;
}
if( $t == '' &&
$this->mInterwiki == '' &&
$this->mNamespace != NS_MAIN ) {
- wfProfileOut( $fname );
return false;
}
$this->mTextform = str_replace( '_', ' ', $t );
- wfProfileOut( $fname );
return true;
}
* @return bool
*/
function equals( $title ) {
- return $this->getInterwiki() == $title->getInterwiki()
+ // Note: === is necessary for proper matching of number-like titles.
+ return $this->getInterwiki() === $title->getInterwiki()
&& $this->getNamespace() == $title->getNamespace()
- && $this->getDbkey() == $title->getDbkey();
+ && $this->getDbkey() === $title->getDbkey();
}
/**