/** */
require_once( 'normal/UtfNormal.php' );
-$wgTitleInterwikiCache = array();
-$wgTitleCache = array();
-
define ( 'GAID_FOR_UPDATE', 1 );
# Title::newFromTitle maintains a cache to avoid
* @package MediaWiki
*/
class Title {
+ /**
+ * Static cache variables
+ */
+ static private $titleCache=array();
+ static private $interwikiCache=array();
+
+
/**
* All member variables should be considered private
* Please use the accessor functions
* @access public
*/
function newFromText( $text, $defaultNamespace = NS_MAIN ) {
- global $wgTitleCache;
$fname = 'Title::newFromText';
if( is_object( $text ) ) {
- wfDebugDieBacktrace( 'Title::newFromText given an object' );
+ throw new MWException( 'Title::newFromText given an object' );
}
/**
*
* In theory these are value objects and won't get changed...
*/
- if( $defaultNamespace == NS_MAIN && isset( $wgTitleCache[$text] ) ) {
- return $wgTitleCache[$text];
+ if( $defaultNamespace == NS_MAIN && isset( Title::$titleCache[$text] ) ) {
+ return Title::$titleCache[$text];
}
/**
if( $defaultNamespace == NS_MAIN ) {
if( $cachedcount >= MW_TITLECACHE_MAX ) {
# Avoid memory leaks on mass operations...
- $wgTitleCache = array();
+ Title::$titleCache = array();
$cachedcount=0;
}
$cachedcount++;
- $wgTitleCache[$text] =& $t;
+ Title::$titleCache[$text] =& $t;
}
return $t;
} else {
*/
/* static */ function indexTitle( $ns, $title ) {
global $wgContLang;
- require_once( 'SearchEngine.php' );
$lc = SearchEngine::legalSearchChars() . '&#;';
$t = $wgContLang->stripForSearch( $title );
* @access public
*/
function getInterwikiLink( $key ) {
- global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgTitleInterwikiCache;
+ global $wgMemc, $wgDBname, $wgInterwikiExpiry;
global $wgInterwikiCache;
$fname = 'Title::getInterwikiLink';
$key = strtolower( $key );
$k = $wgDBname.':interwiki:'.$key;
- if( array_key_exists( $k, $wgTitleInterwikiCache ) ) {
- return $wgTitleInterwikiCache[$k]->iw_url;
+ if( array_key_exists( $k, Title::$interwikiCache ) ) {
+ return Title::$interwikiCache[$k]->iw_url;
}
if ($wgInterwikiCache) {
$s = $wgMemc->get( $k );
# Ignore old keys with no iw_local
if( $s && isset( $s->iw_local ) && isset($s->iw_trans)) {
- $wgTitleInterwikiCache[$k] = $s;
+ Title::$interwikiCache[$k] = $s;
return $s->iw_url;
}
$s->iw_trans = 0;
}
$wgMemc->set( $k, $s, $wgInterwikiExpiry );
- $wgTitleInterwikiCache[$k] = $s;
+ Title::$interwikiCache[$k] = $s;
return $s->iw_url;
}
*/
function getInterwikiCached( $key ) {
global $wgDBname, $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
- global $wgTitleInterwikiCache;
static $db, $site;
if (!$db)
$s->iw_url=$url;
$s->iw_local=(int)$local;
}
- $wgTitleInterwikiCache[$wgDBname.':interwiki:'.$key] = $s;
+ Title::$interwikiCache[$wgDBname.':interwiki:'.$key] = $s;
return $s->iw_url;
}
/**
* @access public
*/
function isLocal() {
- global $wgTitleInterwikiCache, $wgDBname;
+ global $wgDBname;
if ( $this->mInterwiki != '' ) {
# Make sure key is loaded into cache
$this->getInterwikiLink( $this->mInterwiki );
$k = $wgDBname.':interwiki:' . $this->mInterwiki;
- return (bool)($wgTitleInterwikiCache[$k]->iw_local);
+ return (bool)(Title::$interwikiCache[$k]->iw_local);
} else {
return true;
}
* @access public
*/
function isTrans() {
- global $wgTitleInterwikiCache, $wgDBname;
+ global $wgDBname;
if ($this->mInterwiki == '')
return false;
# Make sure key is loaded into cache
$this->getInterwikiLink( $this->mInterwiki );
$k = $wgDBname.':interwiki:' . $this->mInterwiki;
- return (bool)($wgTitleInterwikiCache[$k]->iw_trans);
+ return (bool)(Title::$interwikiCache[$k]->iw_trans);
}
/**
return $wgContLang->getNsText( Namespace::getSubject( $this->mNamespace ) );
}
+ /**
+ * Get the namespace text of the talk page
+ * @return string
+ */
+ function getTalkNsText() {
+ global $wgContLang;
+ return( $wgContLang->getNsText( Namespace::getTalk( $this->mNamespace ) ) );
+ }
+
+ /**
+ * Could this title have a corresponding talk page?
+ * @return bool
+ */
+ function canTalk() {
+ return( Namespace::canTalk( $this->mNamespace ) );
+ }
+
/**
* Get the interwiki prefix (or null string)
* @return string
return $text;
}
+ /**
+ * Get the base name, i.e. the leftmost parts before the /
+ * @return string Base name
+ */
+ function getBaseText() {
+ global $wgNamespacesWithSubpages;
+ if( isset( $wgNamespacesWithSubpages[ $this->mNamespace ] ) && $wgNamespacesWithSubpages[ $this->mNamespace ] ) {
+ $parts = explode( '/', $this->getText() );
+ # Don't discard the real title if there's no subpage involved
+ if( count( $parts ) > 1 )
+ unset( $parts[ count( $parts ) - 1 ] );
+ return implode( '/', $parts );
+ } else {
+ return $this->getText();
+ }
+ }
+
/**
* Get the lowest-level subpage name, i.e. the rightmost part after /
* @return string Subpage name
*/
function getSubpageText() {
global $wgNamespacesWithSubpages;
- if( $wgNamespacesWithSubpages[ $this->mNamespace ] ) {
+ if( isset( $wgNamespacesWithSubpages[ $this->mNamespace ] ) && $wgNamespacesWithSubpages[ $this->mNamespace ] ) {
$parts = explode( '/', $this->mTextform );
return( $parts[ count( $parts ) - 1 ] );
} else {
}
$url .= $query;
}
- if ( '' != $this->mFragment ) {
- $url .= '#' . $this->mFragment;
- }
}
+
+ # Finally, add the fragment.
+ if ( '' != $this->mFragment ) {
+ $url .= '#' . $this->mFragment;
+ }
+
wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) );
return $url;
}
global $wgUser;
- $result = true;
- if ( !wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) ) ) {
+ $result = null;
+ wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) );
+ if ( $result !== null ) {
wfProfileOut( $fname );
return $result;
}
return false;
}
- # protect global styles and js
- if ( NS_MEDIAWIKI == $this->mNamespace
- && preg_match("/\\.(css|js)$/", $this->mTextform )
- && !$wgUser->isAllowed('editinterface') ) {
- wfProfileOut( $fname );
- return false;
- }
-
# protect css/js subpages of user pages
# XXX: this might be better using restrictions
# XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
function userCanRead() {
global $wgUser;
- $result = true;
- if ( !wfRunHooks( 'userCan', array( &$this, &$wgUser, "read", &$result ) ) ) {
+ $result = null;
+ wfRunHooks( 'userCan', array( &$this, &$wgUser, 'read', &$result ) );
+ if ( $result !== null ) {
return $result;
}
return false;
}
+ // Any remaining initial :s are illegal.
+ if ( $t !== '' && ':' == $t{0} ) {
+ return false;
+ }
+
# Fill fields
$this->mDbkeyform = $t;
$this->mUrlform = wfUrlencode( $t );
return 'nstab-special';
case NS_PROJECT:
case NS_PROJECT_TALK:
- return 'nstab-wp';
+ return 'nstab-project';
case NS_IMAGE:
case NS_IMAGE_TALK:
return 'nstab-image';