# $t = $t->getText() ;
$t = $x->l_from ;
$y = explode ( ":" , $t , 2 ) ;
- if ( count ( $y ) == 2 && $y[0] == $cat )
- {
+ if ( count ( $y ) == 2 && $y[0] == $cat ) {
array_push ( $children , $sk->makeLink ( $t , $y[1] ) ) ;
+ } else {
+ array_push ( $articles , $sk->makeLink ( $t ) ) ;
}
- else array_push ( $articles , $sk->makeLink ( $t ) ) ;
}
wfFreeResult ( $res ) ;
wfProfileOut( "$fname-setup" );
foreach ( $a as $line ) {
- wfProfileIn( "$fname-loop" );
if ( preg_match( $e1, $line, $m ) ) { # page with alternate text
$text = $m[2];
else { # Invalid form; output directly
$s .= "[[" . $line ;
- wfProfileOut( "$fname-loop" );
+ wfProfileOut( "$fname-loop1" );
continue;
}
if(substr($m[1],0,1)=="/") { # subpage
} else { # no subpage
$link = $m[1];
}
-
+
if ( preg_match( "/^((?:i|x|[a-z]{2,3})(?:-[a-z0-9]+)?|[A-Za-z\\x80-\\xff]+):(.*)\$/", $link, $m ) ) {
$pre = strtolower( $m[1] );
$suf = trim($m[2]);
$s .= $sk->makeMediaLink( $name,
wfImageUrl( $name ), $text );
$s .= $trail;
- } else if ( isset($wgUseCategoryMagic) && $wgUseCategoryMagic && $pre == wfMsg ( "category" ) ) {
- $l = $sk->makeLink ( $pre.":".ucfirst($m[2]) , ucfirst ( $m[2] ) ) ;
- array_push ( $this->mCategoryLinks , $l ) ;
- $s .= $trail ;
+ } else if ( isset($wgUseCategoryMagic) && $wgUseCategoryMagic && $pre == wfMsg ( "category" ) ) {
+ $l = $sk->makeLink ( $pre.":".ucfirst( $m[2] ), ucfirst ( $m[2] ) ) ;
+ array_push ( $this->mCategoryLinks , $l ) ;
+ $s .= $trail ;
} else {
$l = $wgLang->getLanguageName( $pre );
- if ( "" == $l or !$wgInterwikiMagic or
- Namespace::isTalk( $wgTitle->getNamespace() ) ) {
- if ( "" == $text ) { $text = $link; }
+ if ( "" == $l or !$wgInterwikiMagic or Namespace::isTalk( $wgTitle->getNamespace() ) ) {
+ if ( "" == $text ) {
+ $text = $link;
+ }
$s .= $sk->makeLink( $link, $text, "", $trail );
} else if ( $pre != $wgLanguageCode ) {
array_push( $this->mLanguageLinks, "$pre:$suf" );
# $s .= "<a name=\"{$link}\">{$text}</a>{$trail}";
} else {
if ( "" == $text ) { $text = $link; }
+ # Hotspot:
$s .= $sk->makeLink( $link, $text, "", $trail );
}
- wfProfileOut( "$fname-loop" );
}
wfProfileOut( $fname );
return $s;
$link = str_replace( "_", " ", $link );
$link = wfEscapeHTML( $link );
- if ( $wgOut->isPrintable() ) { $r = " class='printable'"; }
- else if ( $broken == "stub" ) { $r = " class='stub'"; }
- else if ( $broken == "yes" ) { $r = " class='new'"; }
- else { $r = " class='internal'"; }
+ if ( $wgOut->isPrintable() ) {
+ $r = " class='printable'";
+ } else if ( $broken == "stub" ) {
+ $r = " class='stub'";
+ } else if ( $broken == "yes" ) {
+ $r = " class='new'";
+ } else {
+ $r = " class='internal'";
+ }
if ( 1 == $wgUser->getOption( "hover" ) ) {
$r .= " title=\"{$link}\"";
}
return $r;
}
+
+ function getInternalLinkAttributesObj( &$nt, $text, $broken = false )
+ {
+ global $wgUser, $wgOut;
+ $link = $nt->getEscapedText();
+
+ if ( $wgOut->isPrintable() ) {
+ $r = " class='printable'";
+ } else if ( $broken == "stub" ) {
+ $r = " class='stub'";
+ } else if ( $broken == "yes" ) {
+ $r = " class='new'";
+ } else {
+ $r = " class='internal'";
+ }
+ if ( 1 == $wgUser->getOption( "hover" ) ) {
+ $r .= ' title ="' . $nt->getEscapedText() . '"';
+ }
+ return $r;
+ }
+
function getLogo()
{
global $wgLogo;
$c++;
if ($c<count($links)) {
$growinglink.=$link;
- $getlink=$this->makeLink($growinglink,$link);
+ $getlink=$this->makeLink( $growingLink, $link);
if(preg_match("/class='new'/i",$getlink)) { break; } # this is a hack, but it saves time
if ($c>1) {
$sub .= " | ";
if ($nstext = $wgLang->getNsText($tns) ) { # add namespace if necessary
$link = $nstext . ":" . $link ;
}
- $s .= $this->makeLink($link, $text );
+
+ $s .= $this->makeLink( $link, $text );
} elseif( $wgTitle->getNamespace() != Namespace::getSpecial() ) {
# we just throw in a "New page" text to tell the user that he's in edit mode,
# and to avoid messing with the separator that is prepended to the next item
# Note: This function MUST call getArticleID() on the link,
# otherwise the cache won't get updated properly. See LINKCACHE.DOC.
#
- function makeLink( $title, $text= "", $query = "", $trail = "" )
- {
- global $wgOut, $wgUser;
+ function makeLink( $title, $text = "", $query = "", $trail = "" ) {
+ return $this->makeLinkObj( Title::newFromText( $title ), $text, $query, $trail );
+ }
- $nt = Title::newFromText( $title );
+ function makeKnownLink( $title, $text = "", $query = "", $trail = "" ) {
+ return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail );
+ }
+ function makeBrokenLink( $title, $text = "", $query = "", $trail = "" ) {
+ return $this->makeBrokenLinkObj( Title::newFromText( $title ), $text, $query, $trail );
+ }
+
+ function makeStubLink( $title, $text = "", $query = "", $trail = "" ) {
+ return $this->makeStubLinkObj( Title::newFromText( $title ), $text, $query, $trail );
+ }
+
+ # Pass a title object, not a title string
+ function makeLinkObj( &$nt, $text= "", $query = "", $trail = "" )
+ {
+ global $wgOut, $wgUser;
+ $fname = "Skin::makeLinkObj";
+ wfProfileIn( $fname );
if ( $nt->isExternal() ) {
$u = $nt->getFullURL();
if ( "" == $text ) { $text = $nt->getPrefixedText(); }
$trail = $m[2];
}
}
- return "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>{$trail}";
- }
- if ( 0 == $nt->getNamespace() && "" == $nt->getText() ) {
- return $this->makeKnownLink( $title, $text, $query, $trail );
- }
- if ( ( -1 == $nt->getNamespace() ) ||
+ $retVal = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>{$trail}";
+ } elseif ( 0 == $nt->getNamespace() && "" == $nt->getText() ) {
+ $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail );
+ } elseif ( ( -1 == $nt->getNamespace() ) ||
( Namespace::getImage() == $nt->getNamespace() ) ) {
- return $this->makeKnownLink( $title, $text, $query, $trail );
- }
- $aid = $nt->getArticleID() ;
- if ( 0 == $aid ) {
- return $this->makeBrokenLink( $title, $text, $query, $trail );
+ $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail );
} else {
- $threshold = $wgUser->getOption("stubthreshold") ;
- if ( $threshold > 0 ) {
- $res = wfQuery ( "SELECT HIGH_PRIORITY length(cur_text) AS x, cur_namespace, cur_is_redirect FROM cur WHERE cur_id='{$aid}'", DB_READ ) ;
-
- if ( wfNumRows( $res ) > 0 ) {
- $s = wfFetchObject( $res );
- $size = $s->x;
- if ( $s->cur_is_redirect OR $s->cur_namespace != 0 )
+ $aid = $nt->getArticleID() ;
+ if ( 0 == $aid ) {
+ $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
+ } else {
+ $threshold = $wgUser->getOption("stubthreshold") ;
+ if ( $threshold > 0 ) {
+ $res = wfQuery ( "SELECT HIGH_PRIORITY length(cur_text) AS x, cur_namespace, cur_is_redirect FROM cur WHERE cur_id='{$aid}'", DB_READ ) ;
+
+ if ( wfNumRows( $res ) > 0 ) {
+ $s = wfFetchObject( $res );
+ $size = $s->x;
+ if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) {
+ $size = $threshold*2 ; # Really big
+ }
+ wfFreeResult( $res );
+ } else {
$size = $threshold*2 ; # Really big
- wfFreeResult( $res );
- } else $size = $threshold*2 ; # Really big
- } else $size = 1 ;
-
- if ( $size < $threshold )
- return $this->makeStubLink( $title, $text, $query, $trail );
- return $this->makeKnownLink( $title, $text, $query, $trail );
+ }
+ } else {
+ $size = 1 ;
+ }
+ if ( $size < $threshold ) {
+ $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail );
+ } else {
+ $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail );
+ }
+ }
}
+ wfProfileOut( $fname );
+ return $retVal;
}
- function makeKnownLink( $title, $text = "", $query = "", $trail = "" )
+ # Pass a title object, not a title string
+ function makeKnownLinkObj( &$nt, $text = "", $query = "", $trail = "" )
{
global $wgOut, $wgTitle;
- $nt = Title::newFromText( $title );
+ $fname = "Skin::makeKnownLinkObj";
+ wfProfileIn( $fname );
+
$link = $nt->getPrefixedURL();
if ( "" == $link ) {
$u .= "#" . wfEscapeHTML( $nt->getFragment() );
}
if ( "" == $text ) { $text = $nt->getPrefixedText(); }
- $style = $this->getInternalLinkAttributes( $link, $text );
+ $style = $this->getInternalLinkAttributesObj( $nt, $text );
$inside = "";
if ( "" != $trail ) {
}
}
$r = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>{$trail}";
+ wfProfileOut( $fname );
return $r;
}
-
- function makeBrokenLink( $title, $text = "", $query = "", $trail = "" )
+
+ # Pass a title object, not a title string
+ function makeBrokenLinkObj( &$nt, $text = "", $query = "", $trail = "" )
{
global $wgOut, $wgUser;
+
+ $fname = "Skin::makeBrokenLinkObj";
+ wfProfileIn( $fname );
- $nt = Title::newFromText( $title );
$link = $nt->getPrefixedURL();
if ( "" == $query ) { $q = "action=edit"; }
$u = wfLocalUrlE( $link, $q );
if ( "" == $text ) { $text = $nt->getPrefixedText(); }
- $style = $this->getInternalLinkAttributes( $link, $text, "yes" );
+ $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
$inside = "";
if ( "" != $trail ) {
} else {
$s = "{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$trail}";
}
+
+ wfProfileOut( $fname );
return $s;
}
+
+ # Pass a title object, not a title string
+ function makeStubLinkObj( &$nt, $text = "", $query = "", $trail = "" )
+ {
+ global $wgOut, $wgUser;
- function makeStubLink( $title, $text = "", $query = "", $trail = "" )
- {
- global $wgOut, $wgUser;
-
- $nt = Title::newFromText( $title );
- $link = $nt->getPrefixedURL();
+ $link = $nt->getPrefixedURL();
- $u = wfLocalUrlE( $link, $query );
+ $u = wfLocalUrlE( $link, $query );
- if ( "" == $text ) { $text = $nt->getPrefixedText(); }
- $style = $this->getInternalLinkAttributes( $link, $text, "stub" );
+ if ( "" == $text ) { $text = $nt->getPrefixedText(); }
+ $style = $this->getInternalLinkAttributesObj( $nt, $text, "stub" );
- $inside = "";
- if ( "" != $trail ) {
- if ( preg_match( wfMsg("linktrail"), $trail, $m ) ) {
- $inside = $m[1];
- $trail = $m[2];
- }
- }
- if ( $wgOut->isPrintable() ||
- ( 1 == $wgUser->getOption( "highlightbroken" ) ) ) {
- $s = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>{$trail}";
- } else {
- $s = "{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
- }
- return $s;
- }
+ $inside = "";
+ if ( "" != $trail ) {
+ if ( preg_match( wfMsg("linktrail"), $trail, $m ) ) {
+ $inside = $m[1];
+ $trail = $m[2];
+ }
+ }
+ if ( $wgOut->isPrintable() ||
+ ( 1 == $wgUser->getOption( "highlightbroken" ) ) ) {
+ $s = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>{$trail}";
+ } else {
+ $s = "{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
+ }
+ return $s;
+ }
function fnamePart( $url )
{
if ( 0 == $u ) {
$ul = $this->makeKnownLink( $wgLang->specialPage( "Contributions" ),
$ut, "target=" . $ut );
- } else { $ul = $this->makeLink( $wgLang->getNsText(
- Namespace::getUser() ) . ":{$ut}", $ut ); }
+ } else {
+ $ul = $this->makeLink( $wgLang->getNsText(
+ Namespace::getUser() ) . ":{$ut}", $ut ); }
$s = "<li>";
if ( $oid ) {
if ( 0 == $u ) {
$ul = $this->makeKnownLink( $wgLang->specialPage( "Contributions" ),
$ut, "target=" . $ut );
- } else { $ul = $this->makeLink( $wgLang->getNsText(
- Namespace::getUser() ) . ":{$ut}", $ut ); }
+ } else {
+ $ul = $this->makeLink( $wgLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
+ }
$utns=$wgLang->getNsText(Namespace::getTalk(Namespace::getUser()));
$talkname=$wgLang->getNsText(Namespace::getTalk(0)); # use the shorter name
/* private */ var $mTextform, $mUrlform, $mDbkeyform;
/* private */ var $mNamespace, $mInterwiki, $mFragment;
/* private */ var $mArticleID, $mRestrictions, $mRestrictionsLoaded;
+ /* private */ var $mPrefixedText;
/* private */ function Title()
{
$this->mNamespace = 0;
$this->mRestrictionsLoaded = false;
$this->mRestrictions = array();
+ $this->mPrefixedText = false;
}
# Static factory methods
function getPrefixedText()
{
- $s = $this->prefix( $this->mTextform );
- $s = str_replace( "_", " ", $s );
- return $s;
+ if ( !$this->mPrefixedText ) {
+ $s = $this->prefix( $this->mTextform );
+ $s = str_replace( "_", " ", $s );
+ $this->mPrefixedText = $s;
+ }
+ return $this->mPrefixedText;
}
function getPrefixedURL()
return $s;
}
+
+ # For the title field in <a> tags
+ function getEscapedText()
+ {
+ return wfEscapeHTML( $this->getPrefixedText() );
+ }
function isExternal() { return ( "" != $this->mInterwiki ); }
global $wgLinkCache;
if ( -1 != $this->mArticleID ) { return $this->mArticleID; }
- $this->mArticleID = $wgLinkCache->addLink(
- $this->getPrefixedDBkey() );
+ $this->mArticleID = $wgLinkCache->addLinkObj( $this );
return $this->mArticleID;
}
# and uses undersocres, but not otherwise munged. This function
# removes illegal characters, splits off the winterwiki and
# namespace prefixes, sets the other forms, and canonicalizes
- # everything. This one function is really at the core of
- # Wiki--don't mess with it unless you're really sure you know
- # what you're doing.
+ # everything.
#
/* private */ function secureAndSplit()
{
$fname = "Title::secureAndSplit";
wfProfileIn( $fname );
- $validNamespaces = $wgLang->getNamespaces();
- unset( $validNamespaces[0] );
+ static $imgpre = false;
+ static $rxTc = false;
+
+ # Initialisation
+ if ( $imgpre === false ) {
+ $imgpre = ":" . $wgLang->getNsText( Namespace::getImage() ) . ":";
+ $rxTc = "/[^" . Title::legalChars() . "]/";
+ }
+
$this->mInterwiki = $this->mFragment = "";
$this->mNamespace = 0;
$t = preg_replace( "/[\\s_]+/", "_", $this->mDbkeyform );
- if ( "_" == $t{0} ) { $t = substr( $t, 1 ); }
+ if ( "_" == $t{0} ) {
+ $t = substr( $t, 1 );
+ }
$l = strlen( $t );
- if ( $l && ( "_" == $t{$l-1} ) ) { $t = substr( $t, 0, $l-1 ); }
+ if ( $l && ( "_" == $t{$l-1} ) ) {
+ $t = substr( $t, 0, $l-1 );
+ }
if ( "" == $t ) {
wfProfileOut( $fname );
return false;
$this->mDbkeyform = $t;
$done = false;
- $imgpre = ":" . $wgLang->getNsText( Namespace::getImage() ) . ":";
if ( 0 == strncasecmp( $imgpre, $t, strlen( $imgpre ) ) ) {
$t = substr( $t, 1 );
}
$t = $m[2];
$this->mInterwiki = $p;
- if ( preg_match( "/^([A-Za-z0-9_\\x80-\\xff]+):(.*)$/",
- $t, $m ) ) {
- $p = strtolower( $m[1] );
- } else {
+ if ( !preg_match( "/^([A-Za-z0-9_\\x80-\\xff]+):(.*)$/", $t, $m ) ) {
$done = true;
- }
- if($this->mInterwiki != $wgLocalInterwiki)
+ } elseif($this->mInterwiki != $wgLocalInterwiki) {
$done = true;
+ }
}
}
$r = $t;
}
# Strip illegal characters.
#
- $tc = Title::legalChars();
- $t = preg_replace( "/[^{$tc}]/", "", $r );
+ $t = preg_replace( $rxTc, "", $r );
if( $this->mInterwiki == "") $t = $wgLang->ucfirst( $t );
$this->mDbkeyform = $t;