2 if ( ! defined( 'MEDIAWIKI' ) )
14 * The main skin class that provide methods and properties for all other skins.
15 * This base class is also the "Standard" skin.
18 class Skin
extends Linker
{
22 var $lastdate, $lastline;
23 var $rc_cache ; # Cache for Enhanced Recent Changes
24 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
26 var $mWatchLinkNum = 0; // Appended to end of watch link id's
29 /** Constructor, call parent constructor */
30 function Skin() { parent
::Linker(); }
33 * Fetch the set of available skins.
34 * @return array of strings
37 static function &getSkinNames() {
38 global $wgValidSkinNames;
39 static $skinsInitialised = false;
40 if ( !$skinsInitialised ) {
41 # Get a list of available skins
42 # Build using the regular expression '^(.*).php$'
43 # Array keys are all lower case, array value keep the case used by filename
45 wfProfileIn( __METHOD__
. '-init' );
46 global $wgStyleDirectory;
47 $skinDir = dir( $wgStyleDirectory );
49 # while code from www.php.net
50 while (false !== ($file = $skinDir->read())) {
51 // Skip non-PHP files, hidden files, and '.dep' includes
53 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
55 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
59 $skinsInitialised = true;
60 wfProfileOut( __METHOD__
. '-init' );
62 return $wgValidSkinNames;
66 * Normalize a skin preference value to a form that can be loaded.
67 * If a skin can't be found, it will fall back to the configured
68 * default (or the old 'Classic' skin if that's broken).
73 static function normalizeKey( $key ) {
74 global $wgDefaultSkin;
75 $skinNames = Skin
::getSkinNames();
78 // Don't return the default immediately;
79 // in a misconfiguration we need to fall back.
80 $key = $wgDefaultSkin;
83 if( isset( $skinNames[$key] ) ) {
87 // Older versions of the software used a numeric setting
88 // in the user preferences.
94 if( isset( $fallback[$key] ) ){
95 $key = $fallback[$key];
98 if( isset( $skinNames[$key] ) ) {
101 // The old built-in skin
107 * Factory method for loading a skin of a given type
108 * @param string $key 'monobook', 'standard', etc
112 static function &newFromKey( $key ) {
113 global $wgStyleDirectory;
115 $key = Skin
::normalizeKey( $key );
117 $skinNames = Skin
::getSkinNames();
118 $skinName = $skinNames[$key];
120 # Grab the skin class and initialise it.
121 // Preload base classes to work around APC/PHP5 bug
122 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
123 if( file_exists( $deps ) ) include_once( $deps );
124 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
126 # Check if we got if not failback to default skin
127 $className = 'Skin'.$skinName;
128 if( !class_exists( $className ) ) {
129 # DO NOT die if the class isn't found. This breaks maintenance
130 # scripts and can cause a user account to be unrecoverable
131 # except by SQL manipulation if a previously valid skin name
132 # is no longer valid.
133 wfDebug( "Skin class does not exist: $className\n" );
134 $className = 'SkinStandard';
135 require_once( "{$wgStyleDirectory}/Standard.php" );
137 $skin = new $className;
141 /** @return string path to the skin stylesheet */
142 function getStylesheet() {
143 return 'common/wikistandard.css';
146 /** @return string skin name */
147 function getSkinName() {
151 function qbSetting() {
152 global $wgOut, $wgUser;
154 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
155 $q = $wgUser->getOption( 'quickbar', 0 );
159 function initPage( &$out ) {
160 global $wgFavicon, $wgScriptPath, $wgSitename, $wgLanguageCode, $wgLanguageNames;
162 $fname = 'Skin::initPage';
163 wfProfileIn( $fname );
165 if( false !== $wgFavicon ) {
166 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
169 # OpenSearch description link
170 $out->addLink( array(
172 'type' => 'application/opensearchdescription+xml',
173 'href' => "$wgScriptPath/opensearch_desc.php",
174 'title' => "$wgSitename ({$wgLanguageNames[$wgLanguageCode]})",
177 $this->addMetadataLinks($out);
179 $this->mRevisionId
= $out->mRevisionId
;
181 $this->preloadExistence();
183 wfProfileOut( $fname );
187 * Preload the existence of three commonly-requested pages in a single query
189 function preloadExistence() {
190 global $wgUser, $wgTitle;
192 if ( $wgTitle->isTalkPage() ) {
193 $otherTab = $wgTitle->getSubjectPage();
195 $otherTab = $wgTitle->getTalkPage();
197 $lb = new LinkBatch( array(
198 $wgUser->getUserPage(),
199 $wgUser->getTalkPage(),
205 function addMetadataLinks( &$out ) {
206 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
207 global $wgRightsPage, $wgRightsUrl;
209 if( $out->isArticleRelated() ) {
210 # note: buggy CC software only reads first "meta" link
211 if( $wgEnableCreativeCommonsRdf ) {
212 $out->addMetadataLink( array(
213 'title' => 'Creative Commons',
214 'type' => 'application/rdf+xml',
215 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
217 if( $wgEnableDublinCoreRdf ) {
218 $out->addMetadataLink( array(
219 'title' => 'Dublin Core',
220 'type' => 'application/rdf+xml',
221 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
225 if( $wgRightsPage ) {
226 $copy = Title
::newFromText( $wgRightsPage );
228 $copyright = $copy->getLocalURL();
231 if( !$copyright && $wgRightsUrl ) {
232 $copyright = $wgRightsUrl;
235 $out->addLink( array(
236 'rel' => 'copyright',
237 'href' => $copyright ) );
241 function outputPage( &$out ) {
242 global $wgDebugComments;
244 wfProfileIn( 'Skin::outputPage' );
245 $this->initPage( $out );
247 $out->out( $out->headElement() );
249 $out->out( "\n<body" );
250 $ops = $this->getBodyOptions();
251 foreach ( $ops as $name => $val ) {
252 $out->out( " $name='$val'" );
255 if ( $wgDebugComments ) {
256 $out->out( "<!-- Wiki debugging output:\n" .
257 $out->mDebugtext
. "-->\n" );
260 $out->out( $this->beforeContent() );
262 $out->out( $out->mBodytext
. "\n" );
264 $out->out( $this->afterContent() );
266 $out->out( $this->bottomScripts() );
268 $out->out( $out->reportTime() );
270 $out->out( "\n</body></html>" );
273 static function makeVariablesScript( $data ) {
274 global $wgJsMimeType;
276 $r = "<script type= \"$wgJsMimeType\">/*<![CDATA[*/\n";
277 foreach ( $data as $name => $value ) {
278 $encValue = Xml
::encodeJsVar( $value );
279 $r .= "var $name = $encValue;\n";
281 $r .= "/*]]>*/</script>\n";
287 * Make a <script> tag containing global variables
288 * @param array $data Associative array containing one element:
289 * skinname => the skin name
290 * The odd calling convention is for backwards compatibility
292 static function makeGlobalVariablesScript( $data ) {
293 global $wgStylePath, $wgUser;
294 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
295 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
296 global $wgBreakFrames;
298 $ns = $wgTitle->getNamespace();
299 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ?
$wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
302 'skin' => $data['skinname'],
303 'stylepath' => $wgStylePath,
304 'wgArticlePath' => $wgArticlePath,
305 'wgScriptPath' => $wgScriptPath,
306 'wgServer' => $wgServer,
307 'wgCanonicalNamespace' => $nsname,
308 'wgCanonicalSpecialPageName' => SpecialPage
::resolveAlias( $wgTitle->getDBKey() ),
309 'wgNamespaceNumber' => $wgTitle->getNamespace(),
310 'wgPageName' => $wgTitle->getPrefixedDBKey(),
311 'wgTitle' => $wgTitle->getText(),
312 'wgArticleId' => $wgTitle->getArticleId(),
313 'wgIsArticle' => $wgOut->isArticle(),
314 'wgUserName' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
315 'wgUserLanguage' => $wgLang->getCode(),
316 'wgContentLanguage' => $wgContLang->getCode(),
317 'wgBreakFrames' => $wgBreakFrames,
318 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
321 return self
::makeVariablesScript( $vars );
324 function getHeadScripts() {
325 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType, $wgStyleVersion;
327 $r = self
::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
329 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n";
332 if ($wgUser->isLoggedIn()) {
333 $r .= "<script type=\"$wgJsMimeType\" src=\"".htmlspecialchars(self
::makeUrl('-','action=raw&smaxage=0&gen=js'))."\"><!-- site js --></script>\n";
335 $r .= "<script type=\"$wgJsMimeType\" src=\"".htmlspecialchars(self
::makeUrl('-','action=raw&gen=js'))."\"><!-- site js --></script>\n";
338 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
339 $userpage = $wgUser->getUserPage();
340 $userjs = htmlspecialchars( self
::makeUrl(
341 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
342 'action=raw&ctype='.$wgJsMimeType));
343 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
349 * To make it harder for someone to slip a user a fake
350 * user-JavaScript or user-CSS preview, a random token
351 * is associated with the login session. If it's not
352 * passed back with the preview request, we won't render
355 * @param string $action
359 function userCanPreview( $action ) {
360 global $wgTitle, $wgRequest, $wgUser;
362 if( $action != 'submit' )
364 if( !$wgRequest->wasPosted() )
366 if( !$wgTitle->userCanEditCssJsSubpage() )
368 return $wgUser->matchEditToken(
369 $wgRequest->getVal( 'wpEditToken' ) );
372 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
373 function getUserStylesheet() {
374 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
375 $sheet = $this->getStylesheet();
376 $s = "@import \"$wgStylePath/common/common.css?$wgStyleVersion\";\n";
377 $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
378 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
380 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
381 $s .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
382 '@import "' . self
::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
384 $s .= $this->doGetUserStyles();
389 * This returns MediaWiki:Common.js. For some bizarre reason, it does
390 * *not* return any custom user JS from user subpages. Huh?
394 function getUserJs() {
395 wfProfileIn( __METHOD__
);
398 $s = "/* generated javascript */\n";
399 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
400 $s .= "\n\n/* MediaWiki:Common.js */\n";
401 $commonJs = wfMsgForContent('common.js');
402 if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
406 global $wgUseAjax, $wgAjaxWatch;
407 if($wgUseAjax && $wgAjaxWatch) {
410 /* AJAX (un)watch (see /skins/common/ajaxwatch.js) */
412 watchMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watch', array() ) )."',
413 unwatchMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatch', array() ) )."',
414 watchingMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watching', array() ) )."',
415 unwatchingMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatching', array() ) )."'
419 wfProfileOut( __METHOD__
);
424 * Return html code that include User stylesheets
426 function getUserStyles() {
427 $s = "<style type='text/css'>\n";
428 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
429 $s .= $this->getUserStylesheet();
430 $s .= "/*]]>*/ /* */\n";
436 * Some styles that are set by user through the user settings interface.
438 function doGetUserStyles() {
439 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
443 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
444 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
445 $s .= $wgRequest->getText('wpTextbox1');
447 $userpage = $wgUser->getUserPage();
448 $s.= '@import "'.self
::makeUrl(
449 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
450 'action=raw&ctype=text/css').'";'."\n";
454 return $s . $this->reallyDoGetUserStyles();
457 function reallyDoGetUserStyles() {
460 if (($undopt = $wgUser->getOption("underline")) != 2) {
461 $underline = $undopt ?
'underline' : 'none';
462 $s .= "a { text-decoration: $underline; }\n";
464 if( $wgUser->getOption( 'highlightbroken' ) ) {
465 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
468 a.new, #quickbar a.new,
469 a.stub, #quickbar a.stub {
471 text-decoration: inherit;
473 a.new:after, #quickbar a.new:after {
476 text-decoration: $underline;
478 a.stub:after, #quickbar a.stub:after {
481 text-decoration: $underline;
485 if( $wgUser->getOption( 'justify' ) ) {
486 $s .= "#article, #bodyContent { text-align: justify; }\n";
488 if( !$wgUser->getOption( 'showtoc' ) ) {
489 $s .= "#toc { display: none; }\n";
491 if( !$wgUser->getOption( 'editsection' ) ) {
492 $s .= ".editsection { display: none; }\n";
497 function getBodyOptions() {
498 global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
500 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
502 if ( 0 != $wgTitle->getNamespace() ) {
503 $a = array( 'bgcolor' => '#ffffec' );
505 else $a = array( 'bgcolor' => '#FFFFFF' );
506 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
507 $wgTitle->userCanEdit() ) {
508 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
509 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
510 $a +
= array ('ondblclick' => $s);
513 $a['onload'] = $wgOut->getOnloadHandler();
514 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
515 if( $a['onload'] != '' ) {
518 $a['onload'] .= 'setupRightClickEdit()';
520 $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ?
"rtl" : "ltr").
521 ' '.Sanitizer
::escapeClass( 'page-'.$wgTitle->getPrefixedText() );
534 * This will be called immediately after the <body> tag. Split into
535 * two functions to make it easier to subclass.
537 function beforeContent() {
538 return $this->doBeforeContent();
541 function doBeforeContent() {
543 $fname = 'Skin::doBeforeContent';
544 wfProfileIn( $fname );
547 $qb = $this->qbSetting();
549 if( $langlinks = $this->otherLanguages() ) {
555 $borderhack = 'class="top"';
558 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
559 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
562 $left = ($qb == 1 ||
$qb == 3);
563 if($wgContLang->isRTL()) $left = !$left;
566 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
567 $this->logoText() . '</td>';
569 $s .= $this->getQuickbarCompensator( $rows );
571 $l = $wgContLang->isRTL() ?
'right' : 'left';
572 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
574 $s .= $this->topLinks() ;
575 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
577 $r = $wgContLang->isRTL() ?
"left" : "right";
578 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
579 $s .= $this->nameAndLogin();
580 $s .= "\n<br />" . $this->searchForm() . "</td>";
583 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
586 if ( $shove && !$left ) { # Right
587 $s .= $this->getQuickbarCompensator( $rows );
589 $s .= "</tr>\n</table>\n</div>\n";
590 $s .= "\n<div id='article'>\n";
592 $notice = wfGetSiteNotice();
594 $s .= "\n<div id='siteNotice'>$notice</div>\n";
596 $s .= $this->pageTitle();
597 $s .= $this->pageSubtitle() ;
598 $s .= $this->getCategories();
599 wfProfileOut( $fname );
604 function getCategoryLinks () {
605 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
608 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
611 $sep = wfMsgHtml( 'catseparator' );
613 // Use Unicode bidi embedding override characters,
614 // to make sure links don't smash each other up in ugly ways.
615 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
616 $embed = "<span dir='$dir'>";
618 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks
) . $pop;
620 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks
) );
621 $s = $this->makeLinkObj( Title
::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
624 # optional 'dmoz-like' category browser. Will be shown under the list
625 # of categories an article belong to
626 if($wgUseCategoryBrowser) {
627 $s .= '<br /><hr />';
629 # get a big array of the parents tree
630 $parenttree = $wgTitle->getParentCategoryTree();
631 # Skin object passed by reference cause it can not be
632 # accessed under the method subfunction drawCategoryBrowser
633 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
634 # Clean out bogus first entry and sort them
637 # Output one per line
638 $s .= implode("<br />\n", $tempout);
644 /** Render the array as a serie of links.
645 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
646 * @param &skin Object: skin passed by reference
647 * @return String separated by >, terminate with "\n"
649 function drawCategoryBrowser($tree, &$skin) {
651 foreach ($tree as $element => $parent) {
652 if (empty($parent)) {
653 # element start a new list
656 # grab the others elements
657 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
659 # add our current element to the list
660 $eltitle = Title
::NewFromText($element);
661 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
666 function getCategories() {
667 $catlinks=$this->getCategoryLinks();
668 if(!empty($catlinks)) {
669 return "<p class='catlinks'>{$catlinks}</p>";
673 function getQuickbarCompensator( $rows = 1 ) {
674 return "<td width='152' rowspan='{$rows}'> </td>";
678 * This gets called shortly before the \</body\> tag.
679 * @return String HTML to be put before \</body\>
681 function afterContent() {
682 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
683 return $printfooter . $this->doAfterContent();
687 * This gets called shortly before the \</body\> tag.
688 * @return String HTML-wrapped JS code to be put before \</body\>
690 function bottomScripts() {
691 global $wgJsMimeType;
692 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
695 /** @return string Retrievied from HTML text */
696 function printSource() {
698 $url = htmlspecialchars( $wgTitle->getFullURL() );
699 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
702 function printFooter() {
703 return "<p>" . $this->printSource() .
704 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
707 /** overloaded by derived classes */
708 function doAfterContent() { }
710 function pageTitleLinks() {
711 global $wgOut, $wgTitle, $wgUser, $wgRequest;
713 $oldid = $wgRequest->getVal( 'oldid' );
714 $diff = $wgRequest->getVal( 'diff' );
715 $action = $wgRequest->getText( 'action' );
717 $s = $this->printableLink();
718 $disclaimer = $this->disclaimerLink(); # may be empty
720 $s .= ' | ' . $disclaimer;
722 $privacy = $this->privacyLink(); # may be empty too
724 $s .= ' | ' . $privacy;
727 if ( $wgOut->isArticleRelated() ) {
728 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
729 $name = $wgTitle->getDBkey();
730 $image = new Image( $wgTitle );
731 if( $image->exists() ) {
732 $link = htmlspecialchars( $image->getURL() );
733 $style = $this->getInternalLinkAttributes( $link, $name );
734 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
738 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
739 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
740 wfMsg( 'currentrev' ) );
743 if ( $wgUser->getNewtalk() ) {
744 # do not show "You have new messages" text when we are viewing our
746 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
747 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
748 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
749 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
751 $wgOut->setSquidMaxage(0);
752 $wgOut->enableClientCache(false);
756 $undelete = $this->getUndeleteLink();
757 if( !empty( $undelete ) ) {
758 $s .= ' | '.$undelete;
763 function getUndeleteLink() {
764 global $wgUser, $wgTitle, $wgContLang, $action;
765 if( $wgUser->isAllowed( 'deletedhistory' ) &&
766 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
767 ($n = $wgTitle->isDeleted() ) )
769 if ( $wgUser->isAllowed( 'delete' ) ) {
770 $msg = 'thisisdeleted';
772 $msg = 'viewdeleted';
775 $this->makeKnownLinkObj(
776 SpecialPage
::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
777 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
782 function printableLink() {
783 global $wgOut, $wgFeedClasses, $wgRequest;
785 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
787 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
788 if( $wgOut->isSyndicated() ) {
789 foreach( $wgFeedClasses as $format => $class ) {
790 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
791 $s .= " | <a href=\"$feedurl\">{$format}</a>";
797 function pageTitle() {
799 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
803 function pageSubtitle() {
806 $sub = $wgOut->getSubtitle();
808 global $wgExtraSubtitle;
809 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
811 $subpages = $this->subPageSubtitle();
812 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
813 $s = "<p class='subtitle'>{$sub}</p>\n";
817 function subPageSubtitle() {
818 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
820 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
821 $ptext=$wgTitle->getPrefixedText();
822 if(preg_match('/\//',$ptext)) {
823 $links = explode('/',$ptext);
826 foreach($links as $link) {
828 if ($c<count($links)) {
829 $growinglink .= $link;
830 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
831 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
835 $subpages .= '< ';
837 $subpages .= $getlink;
846 function nameAndLogin() {
847 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
849 $lo = $wgContLang->specialPage( 'Userlogout' );
852 if ( $wgUser->isAnon() ) {
853 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
856 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
857 $wgLang->getNsText( NS_TALK
) );
859 $s .= $n . ' ('.$tl.')';
861 $s .= wfMsg('notloggedin');
864 $rt = $wgTitle->getPrefixedURL();
865 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
867 } else { $q = "returnto={$rt}"; }
869 $s .= "\n<br />" . $this->makeKnownLinkObj(
870 SpecialPage
::getTitleFor( 'Userlogin' ),
871 wfMsg( 'login' ), $q );
873 $n = $wgUser->getName();
874 $rt = $wgTitle->getPrefixedURL();
875 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
876 $wgLang->getNsText( NS_TALK
) );
880 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
881 $n ) . "{$tl}<br />" .
882 $this->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
883 "returnto={$rt}" ) . ' | ' .
884 $this->specialLink( 'preferences' );
886 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
892 function getSearchLink() {
893 $searchPage = SpecialPage
::getTitleFor( 'Search' );
894 return $searchPage->getLocalURL();
897 function escapeSearchLink() {
898 return htmlspecialchars( $this->getSearchLink() );
901 function searchForm() {
903 $search = $wgRequest->getText( 'search' );
905 $s = '<form name="search" class="inline" method="post" action="'
906 . $this->escapeSearchLink() . "\">\n"
907 . '<input type="text" name="search" size="19" value="'
908 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
909 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" /> '
910 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
915 function topLinks() {
919 $s = $this->mainPageLink() . $sep
920 . $this->specialLink( 'recentchanges' );
922 if ( $wgOut->isArticleRelated() ) {
923 $s .= $sep . $this->editThisPage()
924 . $sep . $this->historyLink();
926 # Many people don't like this dropdown box
927 #$s .= $sep . $this->specialPagesList();
929 $s .= $this->variantLinks();
931 $s .= $this->extensionTabLinks();
937 * Compatibility for extensions adding functionality through tabs.
938 * Eventually these old skins should be replaced with SkinTemplate-based
942 function extensionTabLinks() {
945 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
946 foreach( $tabs as $tab ) {
947 $s .= ' | ' . Xml
::element( 'a',
948 array( 'href' => $tab['href'] ),
955 * Language/charset variant links for classic-style skins
958 function variantLinks() {
960 /* show links to different language variants */
961 global $wgDisableLangConversion, $wgContLang, $wgTitle;
962 $variants = $wgContLang->getVariants();
963 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
964 foreach( $variants as $code ) {
965 $varname = $wgContLang->getVariantname( $code );
966 if( $varname == 'disable' )
968 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
974 function bottomLinks() {
975 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
979 if ( $wgOut->isArticleRelated() ) {
980 $s .= '<strong>' . $this->editThisPage() . '</strong>';
981 if ( $wgUser->isLoggedIn() ) {
982 $s .= $sep . $this->watchThisPage();
984 $s .= $sep . $this->talkLink()
985 . $sep . $this->historyLink()
986 . $sep . $this->whatLinksHere()
987 . $sep . $this->watchPageLinksLink();
989 if ($wgUseTrackbacks)
990 $s .= $sep . $this->trackbackLink();
992 if ( $wgTitle->getNamespace() == NS_USER
993 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
996 $id=User
::idFromName($wgTitle->getText());
997 $ip=User
::isIP($wgTitle->getText());
999 if($id ||
$ip) { # both anons and non-anons have contri list
1000 $s .= $sep . $this->userContribsLink();
1002 if( $this->showEmailUser( $id ) ) {
1003 $s .= $sep . $this->emailUserLink();
1006 if ( $wgTitle->getArticleId() ) {
1008 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1009 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1010 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1012 $s .= "<br />\n" . $this->otherLanguages();
1017 function pageStats() {
1018 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1019 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1021 $oldid = $wgRequest->getVal( 'oldid' );
1022 $diff = $wgRequest->getVal( 'diff' );
1023 if ( ! $wgOut->isArticle() ) { return ''; }
1024 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
1025 if ( 0 == $wgArticle->getID() ) { return ''; }
1028 if ( !$wgDisableCounters ) {
1029 $count = $wgLang->formatNum( $wgArticle->getCount() );
1031 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1035 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
1036 require_once('Credits.php');
1037 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1039 $s .= $this->lastModified();
1042 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
1043 $dbr =& wfGetDB( DB_SLAVE
);
1044 $watchlist = $dbr->tableName( 'watchlist' );
1045 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1046 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
1047 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1048 $res = $dbr->query( $sql, 'Skin::pageStats');
1049 $x = $dbr->fetchObject( $res );
1050 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
1053 return $s . ' ' . $this->getCopyright();
1056 function getCopyright( $type = 'detect' ) {
1057 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1059 if ( $type == 'detect' ) {
1060 $oldid = $wgRequest->getVal( 'oldid' );
1061 $diff = $wgRequest->getVal( 'diff' );
1063 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1070 if ( $type == 'history' ) {
1071 $msg = 'history_copyright';
1077 if( $wgRightsPage ) {
1078 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1079 } elseif( $wgRightsUrl ) {
1080 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1085 $out .= wfMsgForContent( $msg, $link );
1089 function getCopyrightIcon() {
1090 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1092 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1093 $out = $wgCopyrightIcon;
1094 } else if ( $wgRightsIcon ) {
1095 $icon = htmlspecialchars( $wgRightsIcon );
1096 if ( $wgRightsUrl ) {
1097 $url = htmlspecialchars( $wgRightsUrl );
1098 $out .= '<a href="'.$url.'">';
1100 $text = htmlspecialchars( $wgRightsText );
1101 $out .= "<img src=\"$icon\" alt='$text' />";
1102 if ( $wgRightsUrl ) {
1109 function getPoweredBy() {
1110 global $wgStylePath;
1111 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1112 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1116 function lastModified() {
1117 global $wgLang, $wgArticle, $wgLoadBalancer;
1119 $timestamp = $wgArticle->getTimestamp();
1121 $d = $wgLang->date( $timestamp, true );
1122 $t = $wgLang->time( $timestamp, true );
1123 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1127 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1128 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1133 function logoText( $align = '' ) {
1134 if ( '' != $align ) { $a = " align='{$align}'"; }
1137 $mp = wfMsg( 'mainpage' );
1138 $mptitle = Title
::newMainPage();
1139 $url = ( is_object($mptitle) ?
$mptitle->escapeLocalURL() : '' );
1141 $logourl = $this->getLogo();
1142 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1147 * show a drop-down box of special pages
1149 function specialPagesList() {
1150 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1151 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1152 foreach ( $pages as $name => $page ) {
1153 $pages[$name] = $page->getDescription();
1156 $go = wfMsg( 'go' );
1157 $sp = wfMsg( 'specialpages' );
1158 $spp = $wgContLang->specialPage( 'Specialpages' );
1160 $s = '<form id="specialpages" method="get" class="inline" ' .
1161 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1162 $s .= "<select name=\"wpDropdown\">\n";
1163 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1166 foreach ( $pages as $name => $desc ) {
1167 $p = $wgContLang->specialPage( $name );
1168 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1170 $s .= "</select>\n";
1171 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1176 function mainPageLink() {
1177 $s = $this->makeKnownLinkObj( Title
::newMainPage(), wfMsg( 'mainpage' ) );
1181 function copyrightLink() {
1182 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1183 wfMsg( 'copyrightpagename' ) );
1187 function privacyLink() {
1188 $privacy = wfMsg( 'privacy' );
1189 if ($privacy == '-') {
1192 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1196 function aboutLink() {
1197 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1198 wfMsg( 'aboutsite' ) );
1202 function disclaimerLink() {
1203 $disclaimers = wfMsg( 'disclaimers' );
1204 if ($disclaimers == '-') {
1207 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1212 function editThisPage() {
1213 global $wgOut, $wgTitle;
1215 if ( ! $wgOut->isArticleRelated() ) {
1216 $s = wfMsg( 'protectedpage' );
1218 if ( $wgTitle->userCanEdit() ) {
1219 $t = wfMsg( 'editthispage' );
1221 $t = wfMsg( 'viewsource' );
1224 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1230 * Return URL options for the 'edit page' link.
1231 * This may include an 'oldid' specifier, if the current page view is such.
1236 function editUrlOptions() {
1239 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1240 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1242 return "action=edit";
1246 function deleteThisPage() {
1247 global $wgUser, $wgTitle, $wgRequest;
1249 $diff = $wgRequest->getVal( 'diff' );
1250 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1251 $t = wfMsg( 'deletethispage' );
1253 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1260 function protectThisPage() {
1261 global $wgUser, $wgTitle, $wgRequest;
1263 $diff = $wgRequest->getVal( 'diff' );
1264 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1265 if ( $wgTitle->isProtected() ) {
1266 $t = wfMsg( 'unprotectthispage' );
1267 $q = 'action=unprotect';
1269 $t = wfMsg( 'protectthispage' );
1270 $q = 'action=protect';
1272 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1279 function watchThisPage() {
1280 global $wgOut, $wgTitle;
1281 ++
$this->mWatchLinkNum
;
1283 if ( $wgOut->isArticleRelated() ) {
1284 if ( $wgTitle->userIsWatching() ) {
1285 $t = wfMsg( 'unwatchthispage' );
1286 $q = 'action=unwatch';
1287 $id = "mw-unwatch-link".$this->mWatchLinkNum
;
1289 $t = wfMsg( 'watchthispage' );
1290 $q = 'action=watch';
1291 $id = 'mw-watch-link'.$this->mWatchLinkNum
;
1293 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1295 $s = wfMsg( 'notanarticle' );
1300 function moveThisPage() {
1303 if ( $wgTitle->userCanMove() ) {
1304 return $this->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Movepage' ),
1305 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1307 // no message if page is protected - would be redundant
1312 function historyLink() {
1315 return $this->makeKnownLinkObj( $wgTitle,
1316 wfMsg( 'history' ), 'action=history' );
1319 function whatLinksHere() {
1322 return $this->makeKnownLinkObj(
1323 SpecialPage
::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1324 wfMsg( 'whatlinkshere' ) );
1327 function userContribsLink() {
1330 return $this->makeKnownLinkObj(
1331 SpecialPage
::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1332 wfMsg( 'contributions' ) );
1335 function showEmailUser( $id ) {
1336 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1337 return $wgEnableEmail &&
1338 $wgEnableUserEmail &&
1339 $wgUser->isLoggedIn() && # show only to signed in users
1340 0 != $id; # we can only email to non-anons ..
1341 # '' != $id->getEmail() && # who must have an email address stored ..
1342 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1343 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1346 function emailUserLink() {
1349 return $this->makeKnownLinkObj(
1350 SpecialPage
::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1351 wfMsg( 'emailuser' ) );
1354 function watchPageLinksLink() {
1355 global $wgOut, $wgTitle;
1357 if ( ! $wgOut->isArticleRelated() ) {
1358 return '(' . wfMsg( 'notanarticle' ) . ')';
1360 return $this->makeKnownLinkObj(
1361 SpecialPage
::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1362 wfMsg( 'recentchangeslinked' ) );
1366 function trackbackLink() {
1369 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1370 . wfMsg('trackbacklink') . "</a>";
1373 function otherLanguages() {
1374 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1376 if ( $wgHideInterlanguageLinks ) {
1380 $a = $wgOut->getLanguageLinks();
1381 if ( 0 == count( $a ) ) {
1385 $s = wfMsg( 'otherlanguages' ) . ': ';
1387 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1388 foreach( $a as $l ) {
1389 if ( ! $first ) { $s .= ' | '; }
1392 $nt = Title
::newFromText( $l );
1393 $url = $nt->escapeFullURL();
1394 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1396 if ( '' == $text ) { $text = $l; }
1397 $style = $this->getExternalLinkAttributes( $l, $text );
1398 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1400 if($wgContLang->isRTL()) $s .= '</span>';
1404 function bugReportsLink() {
1405 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1406 wfMsg( 'bugreports' ) );
1410 function dateLink() {
1411 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1412 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1414 $id = $t1->getArticleID();
1417 $s = $this->makeBrokenLink( $t1->getText() );
1419 $s = $this->makeKnownLink( $t1->getText() );
1423 $id = $t2->getArticleID();
1426 $s .= $this->makeBrokenLink( $t2->getText() );
1428 $s .= $this->makeKnownLink( $t2->getText() );
1433 function talkLink() {
1436 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1437 # No discussion links for special pages
1441 if( $wgTitle->isTalkPage() ) {
1442 $link = $wgTitle->getSubjectPage();
1443 switch( $link->getNamespace() ) {
1445 $text = wfMsg( 'articlepage' );
1448 $text = wfMsg( 'userpage' );
1451 $text = wfMsg( 'projectpage' );
1454 $text = wfMsg( 'imagepage' );
1457 $text = wfMsg( 'mediawikipage' );
1460 $text = wfMsg( 'templatepage' );
1463 $text = wfMsg( 'viewhelppage' );
1466 $text = wfMsg( 'categorypage' );
1469 $text = wfMsg( 'articlepage' );
1472 $link = $wgTitle->getTalkPage();
1473 $text = wfMsg( 'talkpage' );
1476 $s = $this->makeLinkObj( $link, $text );
1481 function commentLink() {
1482 global $wgTitle, $wgOut;
1484 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1488 # __NEWSECTIONLINK___ changes behaviour here
1489 # If it's present, the link points to this page, otherwise
1490 # it points to the talk page
1491 if( $wgTitle->isTalkPage() ) {
1493 } elseif( $wgOut->showNewSectionLink() ) {
1496 $title =& $wgTitle->getTalkPage();
1499 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1502 /* these are used extensively in SkinTemplate, but also some other places */
1503 static function makeMainPageUrl( $urlaction = '' ) {
1504 $title = Title
::newMainPage();
1505 self
::checkTitle( $title, '' );
1506 return $title->getLocalURL( $urlaction );
1509 static function makeSpecialUrl( $name, $urlaction = '' ) {
1510 $title = SpecialPage
::getTitleFor( $name );
1511 return $title->getLocalURL( $urlaction );
1514 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1515 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1516 return $title->getLocalURL( $urlaction );
1519 static function makeI18nUrl( $name, $urlaction = '' ) {
1520 $title = Title
::newFromText( wfMsgForContent( $name ) );
1521 self
::checkTitle( $title, $name );
1522 return $title->getLocalURL( $urlaction );
1525 static function makeUrl( $name, $urlaction = '' ) {
1526 $title = Title
::newFromText( $name );
1527 self
::checkTitle( $title, $name );
1528 return $title->getLocalURL( $urlaction );
1531 # If url string starts with http, consider as external URL, else
1533 static function makeInternalOrExternalUrl( $name ) {
1534 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1537 return self
::makeUrl( $name );
1541 # this can be passed the NS number as defined in Language.php
1542 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1543 $title = Title
::makeTitleSafe( $namespace, $name );
1544 self
::checkTitle( $title, $name );
1545 return $title->getLocalURL( $urlaction );
1548 /* these return an array with the 'href' and boolean 'exists' */
1549 static function makeUrlDetails( $name, $urlaction = '' ) {
1550 $title = Title
::newFromText( $name );
1551 self
::checkTitle( $title, $name );
1553 'href' => $title->getLocalURL( $urlaction ),
1554 'exists' => $title->getArticleID() != 0 ?
true : false
1559 * Make URL details where the article exists (or at least it's convenient to think so)
1561 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1562 $title = Title
::newFromText( $name );
1563 self
::checkTitle( $title, $name );
1565 'href' => $title->getLocalURL( $urlaction ),
1570 # make sure we have some title to operate on
1571 static function checkTitle( &$title, $name ) {
1572 if( !is_object( $title ) ) {
1573 $title = Title
::newFromText( $name );
1574 if( !is_object( $title ) ) {
1575 $title = Title
::newFromText( '--error: link target missing--' );
1581 * Build an array that represents the sidebar(s), the navigation bar among them
1586 function buildSidebar() {
1587 global $parserMemc, $wgEnableSidebarCache;
1588 global $wgLang, $wgContLang;
1590 $fname = 'SkinTemplate::buildSidebar';
1592 wfProfileIn( $fname );
1594 $key = wfMemcKey( 'sidebar' );
1595 $cacheSidebar = $wgEnableSidebarCache &&
1596 ($wgLang->getCode() == $wgContLang->getCode());
1598 if ($cacheSidebar) {
1599 $cachedsidebar = $parserMemc->get( $key );
1600 if ($cachedsidebar!="") {
1601 wfProfileOut($fname);
1602 return $cachedsidebar;
1607 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1608 foreach ($lines as $line) {
1609 if (strpos($line, '*') !== 0)
1611 if (strpos($line, '**') !== 0) {
1612 $line = trim($line, '* ');
1615 if (strpos($line, '|') !== false) { // sanity check
1616 $line = explode( '|' , trim($line, '* '), 2 );
1617 $link = wfMsgForContent( $line[0] );
1620 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1622 if (wfEmptyMsg($line[0], $link))
1625 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1628 $title = Title
::newFromText( $link );
1630 $title = $title->fixSpecialName();
1631 $href = $title->getLocalURL();
1633 $href = 'INVALID-TITLE';
1637 $bar[$heading][] = array(
1640 'id' => 'n-' . strtr($line[1], ' ', '-'),
1643 } else { continue; }
1647 $parserMemc->set( $key, $bar, 86400 );
1648 wfProfileOut( $fname );