Document return values I needed
[mediawiki.git] / includes / Skin.php
blob8fd1d73c9556af100bca0b35d009cd9d5e96c681
1 <?php
2 /**
3 * @defgroup Skins Skins
4 */
6 if ( !defined( 'MEDIAWIKI' ) ) {
7 die( 1 );
10 /**
11 * The main skin class that provide methods and properties for all other skins.
12 * This base class is also the "Standard" skin.
14 * See docs/skin.txt for more information.
16 * @ingroup Skins
18 class Skin extends Linker {
19 /**#@+
20 * @private
22 var $mWatchLinkNum = 0; // Appended to end of watch link id's
23 // How many search boxes have we made? Avoid duplicate id's.
24 protected $searchboxes = '';
25 /**#@-*/
26 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
27 protected $skinname = 'standard';
28 // @todo Fixme: should be protected :-\
29 var $mTitle = null;
31 /** Constructor, call parent constructor */
32 function __construct() {
33 parent::__construct();
36 /**
37 * Fetch the set of available skins.
38 * @return array of strings
40 static function getSkinNames() {
41 global $wgValidSkinNames;
42 static $skinsInitialised = false;
44 if ( !$skinsInitialised ) {
45 # Get a list of available skins
46 # Build using the regular expression '^(.*).php$'
47 # Array keys are all lower case, array value keep the case used by filename
49 wfProfileIn( __METHOD__ . '-init' );
51 global $wgStyleDirectory;
53 $skinDir = dir( $wgStyleDirectory );
55 # while code from www.php.net
56 while ( false !== ( $file = $skinDir->read() ) ) {
57 // Skip non-PHP files, hidden files, and '.dep' includes
58 $matches = array();
60 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
61 $aSkin = $matches[1];
62 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
65 $skinDir->close();
66 $skinsInitialised = true;
67 wfProfileOut( __METHOD__ . '-init' );
69 return $wgValidSkinNames;
72 /**
73 * Fetch the list of usable skins in regards to $wgSkipSkins.
74 * Useful for Special:Preferences and other places where you
75 * only want to show skins users _can_ use.
76 * @return array of strings
78 public static function getUsableSkins() {
79 global $wgSkipSkins;
81 $usableSkins = self::getSkinNames();
83 foreach ( $wgSkipSkins as $skip ) {
84 unset( $usableSkins[$skip] );
87 return $usableSkins;
90 /**
91 * Normalize a skin preference value to a form that can be loaded.
92 * If a skin can't be found, it will fall back to the configured
93 * default (or the old 'Classic' skin if that's broken).
94 * @param $key String: 'monobook', 'standard', etc.
95 * @return string
97 static function normalizeKey( $key ) {
98 global $wgDefaultSkin;
100 $skinNames = Skin::getSkinNames();
102 if ( $key == '' ) {
103 // Don't return the default immediately;
104 // in a misconfiguration we need to fall back.
105 $key = $wgDefaultSkin;
108 if ( isset( $skinNames[$key] ) ) {
109 return $key;
112 // Older versions of the software used a numeric setting
113 // in the user preferences.
114 $fallback = array(
115 0 => $wgDefaultSkin,
116 1 => 'nostalgia',
117 2 => 'cologneblue'
120 if ( isset( $fallback[$key] ) ) {
121 $key = $fallback[$key];
124 if ( isset( $skinNames[$key] ) ) {
125 return $key;
126 } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
127 return $wgDefaultSkin;
128 } else {
129 return 'vector';
134 * Factory method for loading a skin of a given type
135 * @param $key String: 'monobook', 'standard', etc.
136 * @return Skin
138 static function &newFromKey( $key ) {
139 global $wgStyleDirectory;
141 $key = Skin::normalizeKey( $key );
143 $skinNames = Skin::getSkinNames();
144 $skinName = $skinNames[$key];
145 $className = 'Skin' . ucfirst( $key );
147 # Grab the skin class and initialise it.
148 if ( !class_exists( $className ) ) {
149 // Preload base classes to work around APC/PHP5 bug
150 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
152 if ( file_exists( $deps ) ) {
153 include_once( $deps );
155 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
157 # Check if we got if not failback to default skin
158 if ( !class_exists( $className ) ) {
159 # DO NOT die if the class isn't found. This breaks maintenance
160 # scripts and can cause a user account to be unrecoverable
161 # except by SQL manipulation if a previously valid skin name
162 # is no longer valid.
163 wfDebug( "Skin class does not exist: $className\n" );
164 $className = 'SkinVector';
165 require_once( "{$wgStyleDirectory}/Vector.php" );
168 $skin = new $className;
169 return $skin;
172 /** @return string path to the skin stylesheet */
173 function getStylesheet() {
174 return 'common/wikistandard.css';
177 /** @return string skin name */
178 public function getSkinName() {
179 return $this->skinname;
182 function qbSetting() {
183 global $wgOut, $wgUser;
185 if ( $wgOut->isQuickbarSuppressed() ) {
186 return 0;
189 $q = $wgUser->getOption( 'quickbar', 0 );
191 return $q;
194 function initPage( OutputPage $out ) {
195 global $wgFavicon, $wgAppleTouchIcon;
197 wfProfileIn( __METHOD__ );
199 # Generally the order of the favicon and apple-touch-icon links
200 # should not matter, but Konqueror (3.5.9 at least) incorrectly
201 # uses whichever one appears later in the HTML source. Make sure
202 # apple-touch-icon is specified first to avoid this.
203 if ( false !== $wgAppleTouchIcon ) {
204 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
207 if ( false !== $wgFavicon ) {
208 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
211 # OpenSearch description link
212 $out->addLink( array(
213 'rel' => 'search',
214 'type' => 'application/opensearchdescription+xml',
215 'href' => wfScript( 'opensearch_desc' ),
216 'title' => wfMsgForContent( 'opensearch-desc' ),
217 ) );
219 $this->addMetadataLinks( $out );
221 $this->mRevisionId = $out->mRevisionId;
223 $this->preloadExistence();
225 wfProfileOut( __METHOD__ );
229 * Preload the existence of three commonly-requested pages in a single query
231 function preloadExistence() {
232 global $wgUser;
234 // User/talk link
235 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
237 // Other tab link
238 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
239 // nothing
240 } elseif ( $this->mTitle->isTalkPage() ) {
241 $titles[] = $this->mTitle->getSubjectPage();
242 } else {
243 $titles[] = $this->mTitle->getTalkPage();
246 $lb = new LinkBatch( $titles );
247 $lb->setCaller( __METHOD__ );
248 $lb->execute();
252 * Adds metadata links (Creative Commons/Dublin Core/copyright) to the HTML
253 * output.
254 * @param $out Object: instance of OutputPage
256 function addMetadataLinks( OutputPage $out ) {
257 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
258 global $wgRightsPage, $wgRightsUrl;
260 if ( $out->isArticleRelated() ) {
261 # note: buggy CC software only reads first "meta" link
262 if ( $wgEnableCreativeCommonsRdf ) {
263 $out->addMetadataLink( array(
264 'title' => 'Creative Commons',
265 'type' => 'application/rdf+xml',
266 'href' => $this->mTitle->getLocalURL( 'action=creativecommons' ) )
270 if ( $wgEnableDublinCoreRdf ) {
271 $out->addMetadataLink( array(
272 'title' => 'Dublin Core',
273 'type' => 'application/rdf+xml',
274 'href' => $this->mTitle->getLocalURL( 'action=dublincore' ) )
278 $copyright = '';
279 if ( $wgRightsPage ) {
280 $copy = Title::newFromText( $wgRightsPage );
282 if ( $copy ) {
283 $copyright = $copy->getLocalURL();
287 if ( !$copyright && $wgRightsUrl ) {
288 $copyright = $wgRightsUrl;
291 if ( $copyright ) {
292 $out->addLink( array(
293 'rel' => 'copyright',
294 'href' => $copyright )
300 * Set some local variables
302 protected function setMembers() {
303 global $wgUser;
304 $this->mUser = $wgUser;
305 $this->userpage = $wgUser->getUserPage()->getPrefixedText();
306 $this->usercss = false;
310 * Set the title
311 * @param $t Title object to use
313 public function setTitle( $t ) {
314 $this->mTitle = $t;
317 /** Get the title */
318 public function getTitle() {
319 return $this->mTitle;
323 * Outputs the HTML generated by other functions.
324 * @param $out Object: instance of OutputPage
326 function outputPage( OutputPage $out ) {
327 global $wgDebugComments;
328 wfProfileIn( __METHOD__ );
330 $this->setMembers();
331 $this->initPage( $out );
333 // See self::afterContentHook() for documentation
334 $afterContent = $this->afterContentHook();
336 $out->out( $out->headElement( $this ) );
338 if ( $wgDebugComments ) {
339 $out->out( "<!-- Wiki debugging output:\n" .
340 $out->mDebugtext . "-->\n" );
343 $out->out( $this->beforeContent() );
345 $out->out( $out->mBodytext . "\n" );
347 $out->out( $this->afterContent() );
349 $out->out( $afterContent );
351 $out->out( $this->bottomScripts( $out ) );
353 $out->out( wfReportTime() );
355 $out->out( "\n</body></html>" );
356 wfProfileOut( __METHOD__ );
359 static function makeVariablesScript( $data ) {
360 if ( $data ) {
361 return Html::inlineScript(
362 ResourceLoader::makeLoaderConditionalScript( ResourceLoader::makeConfigSetScript( $data ) )
364 } else {
365 return '';
370 * Make a <script> tag containing global variables
371 * @param $skinName string Name of the skin
372 * The odd calling convention is for backwards compatibility
373 * @todo FIXME: Make this not depend on $wgTitle!
375 * Do not add things here which can be evaluated in ResourceLoaderStartupScript - in other words, without state.
376 * You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes.
378 static function makeGlobalVariablesScript( $skinName ) {
379 global $wgTitle, $wgUser, $wgRequest, $wgArticle, $wgOut, $wgRestrictionTypes, $wgUseAjax, $wgEnableMWSuggest;
381 $ns = $wgTitle->getNamespace();
382 $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
383 $vars = array(
384 'wgCanonicalNamespace' => $nsname,
385 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
386 SpecialPage::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
387 'wgNamespaceNumber' => $wgTitle->getNamespace(),
388 'wgPageName' => $wgTitle->getPrefixedDBKey(),
389 'wgTitle' => $wgTitle->getText(),
390 'wgAction' => $wgRequest->getText( 'action', 'view' ),
391 'wgArticleId' => $wgTitle->getArticleId(),
392 'wgIsArticle' => $wgOut->isArticle(),
393 'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(),
394 'wgUserGroups' => $wgUser->getEffectiveGroups(),
395 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
396 'wgCategories' => $wgOut->getCategories(),
398 foreach ( $wgRestrictionTypes as $type ) {
399 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
401 if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
402 $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
405 // Allow extensions to add their custom variables to the global JS variables
406 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
408 return self::makeVariablesScript( $vars );
412 * To make it harder for someone to slip a user a fake
413 * user-JavaScript or user-CSS preview, a random token
414 * is associated with the login session. If it's not
415 * passed back with the preview request, we won't render
416 * the code.
418 * @param $action String: 'edit', 'submit' etc.
419 * @return bool
421 public function userCanPreview( $action ) {
422 global $wgRequest, $wgUser;
424 if ( $action != 'submit' ) {
425 return false;
427 if ( !$wgRequest->wasPosted() ) {
428 return false;
430 if ( !$this->mTitle->userCanEditCssSubpage() ) {
431 return false;
433 if ( !$this->mTitle->userCanEditJsSubpage() ) {
434 return false;
437 return $wgUser->matchEditToken(
438 $wgRequest->getVal( 'wpEditToken' ) );
442 * Generated JavaScript action=raw&gen=js
443 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
444 * nated together. For some bizarre reason, it does *not* return any
445 * custom user JS from subpages. Huh?
447 * There's absolutely no reason to have separate Monobook/Common JSes.
448 * Any JS that cares can just check the skin variable generated at the
449 * top. For now Monobook.js will be maintained, but it should be consi-
450 * dered deprecated.
452 * @param $skinName String: If set, overrides the skin name
453 * @return string
455 public function generateUserJs( $skinName = null ) {
457 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
459 return '';
463 * Generate user stylesheet for action=raw&gen=css
465 public function generateUserStylesheet() {
467 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
469 return '';
473 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
474 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
476 protected function reallyGenerateUserStylesheet() {
478 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
480 return '';
484 * @private
486 function setupUserCss( OutputPage $out ) {
487 global $wgRequest;
488 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs, $wgSquidMaxage;
490 wfProfileIn( __METHOD__ );
492 $this->setupSkinUserCss( $out );
494 $siteargs = array(
495 'action' => 'raw',
496 'maxage' => $wgSquidMaxage,
499 // Add any extension CSS
500 foreach ( $out->getExtStyle() as $url ) {
501 $out->addStyle( $url );
504 // Per-site custom styles
505 if ( $wgUseSiteCss ) {
506 $out->addModuleStyles( 'site' );
509 // Per-user custom styles
510 if ( $wgAllowUserCss ) {
511 if ( $this->mTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
512 // @FIXME: properly escape the cdata!
513 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
514 } else {
515 $out->addModuleStyles( 'user' );
519 // Per-user preference styles
520 if ( $wgAllowUserCssPrefs ) {
521 $out->addModuleStyles( 'user.options' );
524 wfProfileOut( __METHOD__ );
528 * Get the query to generate a dynamic stylesheet
530 * @return array
532 public static function getDynamicStylesheetQuery() {
533 global $wgSquidMaxage;
535 return array(
536 'action' => 'raw',
537 'maxage' => $wgSquidMaxage,
538 'usemsgcache' => 'yes',
539 'ctype' => 'text/css',
540 'smaxage' => $wgSquidMaxage,
545 * Add skin specific stylesheets
546 * @param $out OutputPage
548 function setupSkinUserCss( OutputPage $out ) {
549 $out->addModuleStyles( 'mediawiki.legacy.shared' );
550 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
551 // TODO: When converting old skins to use ResourceLoader (or removing them) the following should be reconsidered
552 $out->addStyle( $this->getStylesheet() );
553 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
556 function getPageClasses( $title ) {
557 $numeric = 'ns-' . $title->getNamespace();
559 if ( $title->getNamespace() == NS_SPECIAL ) {
560 $type = 'ns-special';
561 } elseif ( $title->isTalkPage() ) {
562 $type = 'ns-talk';
563 } else {
564 $type = 'ns-subject';
567 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
569 return "$numeric $type $name";
573 * URL to the logo
575 function getLogo() {
576 global $wgLogo;
577 return $wgLogo;
581 * This will be called immediately after the <body> tag. Split into
582 * two functions to make it easier to subclass.
584 function beforeContent() {
585 return $this->doBeforeContent();
588 function doBeforeContent() {
589 global $wgContLang;
590 wfProfileIn( __METHOD__ );
592 $s = '';
593 $qb = $this->qbSetting();
595 $langlinks = $this->otherLanguages();
596 if ( $langlinks ) {
597 $rows = 2;
598 $borderhack = '';
599 } else {
600 $rows = 1;
601 $langlinks = false;
602 $borderhack = 'class="top"';
605 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
606 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
608 $shove = ( $qb != 0 );
609 $left = ( $qb == 1 || $qb == 3 );
611 if ( $wgContLang->isRTL() ) {
612 $left = !$left;
615 if ( !$shove ) {
616 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
617 $this->logoText() . '</td>';
618 } elseif ( $left ) {
619 $s .= $this->getQuickbarCompensator( $rows );
622 $l = $wgContLang->alignStart();
623 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
625 $s .= $this->topLinks();
626 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
628 $r = $wgContLang->alignEnd();
629 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
630 $s .= $this->nameAndLogin();
631 $s .= "\n<br />" . $this->searchForm() . '</td>';
633 if ( $langlinks ) {
634 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
637 if ( $shove && !$left ) { # Right
638 $s .= $this->getQuickbarCompensator( $rows );
641 $s .= "</tr>\n</table>\n</div>\n";
642 $s .= "\n<div id='article'>\n";
644 $notice = wfGetSiteNotice();
646 if ( $notice ) {
647 $s .= "\n<div id='siteNotice'>$notice</div>\n";
649 $s .= $this->pageTitle();
650 $s .= $this->pageSubtitle();
651 $s .= $this->getCategories();
653 wfProfileOut( __METHOD__ );
654 return $s;
657 function getCategoryLinks() {
658 global $wgOut, $wgUseCategoryBrowser;
659 global $wgContLang, $wgUser;
661 if ( count( $wgOut->mCategoryLinks ) == 0 ) {
662 return '';
665 # Separator
666 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
668 // Use Unicode bidi embedding override characters,
669 // to make sure links don't smash each other up in ugly ways.
670 $dir = $wgContLang->getDir();
671 $embed = "<span dir='$dir'>";
672 $pop = '</span>';
674 $allCats = $wgOut->getCategoryLinks();
675 $s = '';
676 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
678 if ( !empty( $allCats['normal'] ) ) {
679 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
681 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
682 $s .= '<div id="mw-normal-catlinks">' .
683 $this->link( Title::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
684 . $colon . $t . '</div>';
687 # Hidden categories
688 if ( isset( $allCats['hidden'] ) ) {
689 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
690 $class = 'mw-hidden-cats-user-shown';
691 } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
692 $class = 'mw-hidden-cats-ns-shown';
693 } else {
694 $class = 'mw-hidden-cats-hidden';
697 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
698 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
699 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
700 '</div>';
703 # optional 'dmoz-like' category browser. Will be shown under the list
704 # of categories an article belong to
705 if ( $wgUseCategoryBrowser ) {
706 $s .= '<br /><hr />';
708 # get a big array of the parents tree
709 $parenttree = $this->mTitle->getParentCategoryTree();
710 # Skin object passed by reference cause it can not be
711 # accessed under the method subfunction drawCategoryBrowser
712 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
713 # Clean out bogus first entry and sort them
714 unset( $tempout[0] );
715 asort( $tempout );
716 # Output one per line
717 $s .= implode( "<br />\n", $tempout );
720 return $s;
724 * Render the array as a serie of links.
725 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
726 * @param &skin Object: skin passed by reference
727 * @return String separated by &gt;, terminate with "\n"
729 function drawCategoryBrowser( $tree, &$skin ) {
730 $return = '';
732 foreach ( $tree as $element => $parent ) {
733 if ( empty( $parent ) ) {
734 # element start a new list
735 $return .= "\n";
736 } else {
737 # grab the others elements
738 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' &gt; ';
741 # add our current element to the list
742 $eltitle = Title::newFromText( $element );
743 $return .= $skin->link( $eltitle, $eltitle->getText() );
746 return $return;
749 function getCategories() {
750 $catlinks = $this->getCategoryLinks();
752 $classes = 'catlinks';
754 global $wgOut, $wgUser;
756 // Check what we're showing
757 $allCats = $wgOut->getCategoryLinks();
758 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
759 $this->mTitle->getNamespace() == NS_CATEGORY;
761 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
762 $classes .= ' catlinks-allhidden';
765 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
768 function getQuickbarCompensator( $rows = 1 ) {
769 return "<td width='152' rowspan='{$rows}'>&#160;</td>";
773 * This runs a hook to allow extensions placing their stuff after content
774 * and article metadata (e.g. categories).
775 * Note: This function has nothing to do with afterContent().
777 * This hook is placed here in order to allow using the same hook for all
778 * skins, both the SkinTemplate based ones and the older ones, which directly
779 * use this class to get their data.
781 * The output of this function gets processed in SkinTemplate::outputPage() for
782 * the SkinTemplate based skins, all other skins should directly echo it.
784 * Returns an empty string by default, if not changed by any hook function.
786 protected function afterContentHook() {
787 $data = '';
789 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
790 // adding just some spaces shouldn't toggle the output
791 // of the whole <div/>, so we use trim() here
792 if ( trim( $data ) != '' ) {
793 // Doing this here instead of in the skins to
794 // ensure that the div has the same ID in all
795 // skins
796 $data = "<div id='mw-data-after-content'>\n" .
797 "\t$data\n" .
798 "</div>\n";
800 } else {
801 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
804 return $data;
808 * Generate debug data HTML for displaying at the bottom of the main content
809 * area.
810 * @return String HTML containing debug data, if enabled (otherwise empty).
812 protected function generateDebugHTML() {
813 global $wgShowDebug, $wgOut;
815 if ( $wgShowDebug ) {
816 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext );
817 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
818 $listInternals . "</ul>\n";
821 return '';
824 private function formatDebugHTML( $debugText ) {
825 $lines = explode( "\n", $debugText );
826 $curIdent = 0;
827 $ret = '<li>';
829 foreach ( $lines as $line ) {
830 $m = array();
831 $display = ltrim( $line );
832 $ident = strlen( $line ) - strlen( $display );
833 $diff = $ident - $curIdent;
835 if ( $display == '' ) {
836 $display = "\xc2\xa0";
839 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
840 $ident = $curIdent;
841 $diff = 0;
842 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
843 } else {
844 $display = htmlspecialchars( $display );
847 if ( $diff < 0 ) {
848 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
849 } elseif ( $diff == 0 ) {
850 $ret .= "</li><li>\n";
851 } else {
852 $ret .= str_repeat( "<ul><li>\n", $diff );
854 $ret .= $display . "\n";
856 $curIdent = $ident;
859 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
861 return $ret;
865 * This gets called shortly before the </body> tag.
866 * @return String HTML to be put before </body>
868 function afterContent() {
869 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
870 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
874 * This gets called shortly before the </body> tag.
875 * @param $out OutputPage object
876 * @return String HTML-wrapped JS code to be put before </body>
878 function bottomScripts( $out ) {
879 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
880 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
882 return $bottomScriptText;
885 /** @return string Retrievied from HTML text */
886 function printSource() {
887 $url = htmlspecialchars( $this->mTitle->getFullURL() );
888 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
891 function printFooter() {
892 return "<p>" . $this->printSource() .
893 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
896 /** overloaded by derived classes */
897 function doAfterContent() {
898 return '</div></div>';
901 function pageTitleLinks() {
902 global $wgOut, $wgUser, $wgRequest, $wgLang;
904 $oldid = $wgRequest->getVal( 'oldid' );
905 $diff = $wgRequest->getVal( 'diff' );
906 $action = $wgRequest->getText( 'action' );
908 $s[] = $this->printableLink();
909 $disclaimer = $this->disclaimerLink(); # may be empty
911 if ( $disclaimer ) {
912 $s[] = $disclaimer;
915 $privacy = $this->privacyLink(); # may be empty too
917 if ( $privacy ) {
918 $s[] = $privacy;
921 if ( $wgOut->isArticleRelated() ) {
922 if ( $this->mTitle->getNamespace() == NS_FILE ) {
923 $name = $this->mTitle->getDBkey();
924 $image = wfFindFile( $this->mTitle );
926 if ( $image ) {
927 $link = htmlspecialchars( $image->getURL() );
928 $style = $this->getInternalLinkAttributes( $link, $name );
929 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
934 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
935 $s[] .= $this->link(
936 $this->mTitle,
937 wfMsg( 'currentrev' ),
938 array(),
939 array(),
940 array( 'known', 'noclasses' )
944 if ( $wgUser->getNewtalk() ) {
945 # do not show "You have new messages" text when we are viewing our
946 # own talk page
947 if ( !$this->mTitle->equals( $wgUser->getTalkPage() ) ) {
948 $tl = $this->link(
949 $wgUser->getTalkPage(),
950 wfMsgHtml( 'newmessageslink' ),
951 array(),
952 array( 'redirect' => 'no' ),
953 array( 'known', 'noclasses' )
956 $dl = $this->link(
957 $wgUser->getTalkPage(),
958 wfMsgHtml( 'newmessagesdifflink' ),
959 array(),
960 array( 'diff' => 'cur' ),
961 array( 'known', 'noclasses' )
963 $s[] = '<strong>' . wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
964 # disable caching
965 $wgOut->setSquidMaxage( 0 );
966 $wgOut->enableClientCache( false );
970 $undelete = $this->getUndeleteLink();
972 if ( !empty( $undelete ) ) {
973 $s[] = $undelete;
976 return $wgLang->pipeList( $s );
979 function getUndeleteLink() {
980 global $wgUser, $wgLang, $wgRequest;
982 $action = $wgRequest->getVal( 'action', 'view' );
984 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
985 ( $this->mTitle->getArticleId() == 0 || $action == 'history' ) ) {
986 $n = $this->mTitle->isDeleted();
988 if ( $n ) {
989 if ( $wgUser->isAllowed( 'undelete' ) ) {
990 $msg = 'thisisdeleted';
991 } else {
992 $msg = 'viewdeleted';
995 return wfMsg(
996 $msg,
997 $this->link(
998 SpecialPage::getTitleFor( 'Undelete', $this->mTitle->getPrefixedDBkey() ),
999 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1000 array(),
1001 array(),
1002 array( 'known', 'noclasses' )
1008 return '';
1011 function printableLink() {
1012 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1014 $s = array();
1016 if ( !$wgOut->isPrintable() ) {
1017 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1018 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1021 if ( $wgOut->isSyndicated() ) {
1022 foreach ( $wgFeedClasses as $format => $class ) {
1023 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1024 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1025 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1028 return $wgLang->pipeList( $s );
1032 * Gets the h1 element with the page title.
1033 * @return string
1035 function pageTitle() {
1036 global $wgOut;
1037 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1038 return $s;
1041 function pageSubtitle() {
1042 global $wgOut;
1044 $sub = $wgOut->getSubtitle();
1046 if ( $sub == '' ) {
1047 global $wgExtraSubtitle;
1048 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1051 $subpages = $this->subPageSubtitle();
1052 $sub .= !empty( $subpages ) ? "</p><p class='subpages'>$subpages" : '';
1053 $s = "<p class='subtitle'>{$sub}</p>\n";
1055 return $s;
1058 function subPageSubtitle() {
1059 $subpages = '';
1061 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this ) ) ) {
1062 return $subpages;
1065 global $wgOut;
1067 if ( $wgOut->isArticle() && MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
1068 $ptext = $this->mTitle->getPrefixedText();
1069 if ( preg_match( '/\//', $ptext ) ) {
1070 $links = explode( '/', $ptext );
1071 array_pop( $links );
1072 $c = 0;
1073 $growinglink = '';
1074 $display = '';
1076 foreach ( $links as $link ) {
1077 $growinglink .= $link;
1078 $display .= $link;
1079 $linkObj = Title::newFromText( $growinglink );
1081 if ( is_object( $linkObj ) && $linkObj->exists() ) {
1082 $getlink = $this->link(
1083 $linkObj,
1084 htmlspecialchars( $display ),
1085 array(),
1086 array(),
1087 array( 'known', 'noclasses' )
1090 $c++;
1092 if ( $c > 1 ) {
1093 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1094 } else {
1095 $subpages .= '&lt; ';
1098 $subpages .= $getlink;
1099 $display = '';
1100 } else {
1101 $display .= '/';
1103 $growinglink .= '/';
1108 return $subpages;
1112 * Returns true if the IP should be shown in the header
1114 function showIPinHeader() {
1115 global $wgShowIPinHeader;
1116 return $wgShowIPinHeader && session_id() != '';
1119 function nameAndLogin() {
1120 global $wgUser, $wgLang, $wgContLang;
1122 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1124 $ret = '';
1126 if ( $wgUser->isAnon() ) {
1127 if ( $this->showIPinHeader() ) {
1128 $name = wfGetIP();
1130 $talkLink = $this->link( $wgUser->getTalkPage(),
1131 $wgLang->getNsText( NS_TALK ) );
1133 $ret .= "$name ($talkLink)";
1134 } else {
1135 $ret .= wfMsg( 'notloggedin' );
1138 $returnTo = $this->mTitle->getPrefixedDBkey();
1139 $query = array();
1141 if ( $logoutPage != $returnTo ) {
1142 $query['returnto'] = $returnTo;
1145 $loginlink = $wgUser->isAllowed( 'createaccount' )
1146 ? 'nav-login-createaccount'
1147 : 'login';
1148 $ret .= "\n<br />" . $this->link(
1149 SpecialPage::getTitleFor( 'Userlogin' ),
1150 wfMsg( $loginlink ), array(), $query
1152 } else {
1153 $returnTo = $this->mTitle->getPrefixedDBkey();
1154 $talkLink = $this->link( $wgUser->getTalkPage(),
1155 $wgLang->getNsText( NS_TALK ) );
1157 $ret .= $this->link( $wgUser->getUserPage(),
1158 htmlspecialchars( $wgUser->getName() ) );
1159 $ret .= " ($talkLink)<br />";
1160 $ret .= $wgLang->pipeList( array(
1161 $this->link(
1162 SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1163 array(), array( 'returnto' => $returnTo )
1165 $this->specialLink( 'Preferences' ),
1166 ) );
1169 $ret = $wgLang->pipeList( array(
1170 $ret,
1171 $this->link(
1172 Title::newFromText( wfMsgForContent( 'helppage' ) ),
1173 wfMsg( 'help' )
1175 ) );
1177 return $ret;
1180 function getSearchLink() {
1181 $searchPage = SpecialPage::getTitleFor( 'Search' );
1182 return $searchPage->getLocalURL();
1185 function escapeSearchLink() {
1186 return htmlspecialchars( $this->getSearchLink() );
1189 function searchForm() {
1190 global $wgRequest, $wgUseTwoButtonsSearchForm;
1192 $search = $wgRequest->getText( 'search' );
1194 $s = '<form id="searchform' . $this->searchboxes . '" name="search" class="inline" method="post" action="'
1195 . $this->escapeSearchLink() . "\">\n"
1196 . '<input type="text" id="searchInput' . $this->searchboxes . '" name="search" size="19" value="'
1197 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1198 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1200 if ( $wgUseTwoButtonsSearchForm ) {
1201 $s .= '&#160;<input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1202 } else {
1203 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1206 $s .= '</form>';
1208 // Ensure unique id's for search boxes made after the first
1209 $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
1211 return $s;
1214 function topLinks() {
1215 global $wgOut;
1217 $s = array(
1218 $this->mainPageLink(),
1219 $this->specialLink( 'Recentchanges' )
1222 if ( $wgOut->isArticleRelated() ) {
1223 $s[] = $this->editThisPage();
1224 $s[] = $this->historyLink();
1227 # Many people don't like this dropdown box
1228 # $s[] = $this->specialPagesList();
1230 if ( $this->variantLinks() ) {
1231 $s[] = $this->variantLinks();
1234 if ( $this->extensionTabLinks() ) {
1235 $s[] = $this->extensionTabLinks();
1238 // @todo FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1239 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1243 * Compatibility for extensions adding functionality through tabs.
1244 * Eventually these old skins should be replaced with SkinTemplate-based
1245 * versions, sigh...
1246 * @return string
1248 function extensionTabLinks() {
1249 $tabs = array();
1250 $out = '';
1251 $s = array();
1252 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1253 foreach ( $tabs as $tab ) {
1254 $s[] = Xml::element( 'a',
1255 array( 'href' => $tab['href'] ),
1256 $tab['text'] );
1259 if ( count( $s ) ) {
1260 global $wgLang;
1262 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1263 $out .= $wgLang->pipeList( $s );
1266 return $out;
1270 * Language/charset variant links for classic-style skins
1271 * @return string
1273 function variantLinks() {
1274 $s = '';
1276 /* show links to different language variants */
1277 global $wgDisableLangConversion, $wgLang, $wgContLang;
1279 $variants = $wgContLang->getVariants();
1281 if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1282 foreach ( $variants as $code ) {
1283 $varname = $wgContLang->getVariantname( $code );
1285 if ( $varname == 'disable' ) {
1286 continue;
1288 $s = $wgLang->pipeList( array(
1290 '<a href="' . $this->mTitle->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1291 ) );
1295 return $s;
1298 function bottomLinks() {
1299 global $wgOut, $wgUser, $wgUseTrackbacks;
1300 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1302 $s = '';
1303 if ( $wgOut->isArticleRelated() ) {
1304 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1306 if ( $wgUser->isLoggedIn() ) {
1307 $element[] = $this->watchThisPage();
1310 $element[] = $this->talkLink();
1311 $element[] = $this->historyLink();
1312 $element[] = $this->whatLinksHere();
1313 $element[] = $this->watchPageLinksLink();
1315 if ( $wgUseTrackbacks ) {
1316 $element[] = $this->trackbackLink();
1319 if (
1320 $this->mTitle->getNamespace() == NS_USER ||
1321 $this->mTitle->getNamespace() == NS_USER_TALK
1323 $id = User::idFromName( $this->mTitle->getText() );
1324 $ip = User::isIP( $this->mTitle->getText() );
1326 # Both anons and non-anons have contributions list
1327 if ( $id || $ip ) {
1328 $element[] = $this->userContribsLink();
1331 if ( $this->showEmailUser( $id ) ) {
1332 $element[] = $this->emailUserLink();
1336 $s = implode( $element, $sep );
1338 if ( $this->mTitle->getArticleId() ) {
1339 $s .= "\n<br />";
1341 // Delete/protect/move links for privileged users
1342 if ( $wgUser->isAllowed( 'delete' ) ) {
1343 $s .= $this->deleteThisPage();
1346 if ( $wgUser->isAllowed( 'protect' ) ) {
1347 $s .= $sep . $this->protectThisPage();
1350 if ( $wgUser->isAllowed( 'move' ) ) {
1351 $s .= $sep . $this->moveThisPage();
1355 $s .= "<br />\n" . $this->otherLanguages();
1358 return $s;
1361 function pageStats() {
1362 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1363 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1365 $oldid = $wgRequest->getVal( 'oldid' );
1366 $diff = $wgRequest->getVal( 'diff' );
1368 if ( !$wgOut->isArticle() ) {
1369 return '';
1372 if ( !$wgArticle instanceof Article ) {
1373 return '';
1376 if ( isset( $oldid ) || isset( $diff ) ) {
1377 return '';
1380 if ( 0 == $wgArticle->getID() ) {
1381 return '';
1384 $s = '';
1386 if ( !$wgDisableCounters ) {
1387 $count = $wgLang->formatNum( $wgArticle->getCount() );
1389 if ( $count ) {
1390 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1394 if ( $wgMaxCredits != 0 ) {
1395 $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1396 } else {
1397 $s .= $this->lastModified();
1400 if ( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1401 $dbr = wfGetDB( DB_SLAVE );
1402 $res = $dbr->select(
1403 'watchlist',
1404 array( 'COUNT(*) AS n' ),
1405 array(
1406 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ),
1407 'wl_namespace' => $this->mTitle->getNamespace()
1409 __METHOD__
1411 $x = $dbr->fetchObject( $res );
1413 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1414 array( 'parseinline' ), $wgLang->formatNum( $x->n )
1418 return $s . ' ' . $this->getCopyright();
1421 function getCopyright( $type = 'detect' ) {
1422 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1424 if ( $type == 'detect' ) {
1425 $diff = $wgRequest->getVal( 'diff' );
1426 $isCur = $wgArticle && $wgArticle->isCurrent();
1428 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1429 $type = 'history';
1430 } else {
1431 $type = 'normal';
1435 if ( $type == 'history' ) {
1436 $msg = 'history_copyright';
1437 } else {
1438 $msg = 'copyright';
1441 $out = '';
1443 if ( $wgRightsPage ) {
1444 $title = Title::newFromText( $wgRightsPage );
1445 $link = $this->linkKnown( $title, $wgRightsText );
1446 } elseif ( $wgRightsUrl ) {
1447 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1448 } elseif ( $wgRightsText ) {
1449 $link = $wgRightsText;
1450 } else {
1451 # Give up now
1452 return $out;
1455 // Allow for site and per-namespace customization of copyright notice.
1456 $forContent = true;
1458 if ( isset( $wgArticle ) ) {
1459 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link, &$forContent ) );
1462 if ( $forContent ) {
1463 $out .= wfMsgForContent( $msg, $link );
1464 } else {
1465 $out .= wfMsg( $msg, $link );
1468 return $out;
1471 function getCopyrightIcon() {
1472 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1474 $out = '';
1476 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1477 $out = $wgCopyrightIcon;
1478 } elseif ( $wgRightsIcon ) {
1479 $icon = htmlspecialchars( $wgRightsIcon );
1481 if ( $wgRightsUrl ) {
1482 $url = htmlspecialchars( $wgRightsUrl );
1483 $out .= '<a href="' . $url . '">';
1486 $text = htmlspecialchars( $wgRightsText );
1487 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1489 if ( $wgRightsUrl ) {
1490 $out .= '</a>';
1494 return $out;
1498 * Gets the powered by MediaWiki icon.
1499 * @return string
1501 function getPoweredBy() {
1502 global $wgStylePath;
1504 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1505 $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1507 return $img;
1510 function lastModified() {
1511 global $wgLang, $wgArticle;
1513 if ( $this->mRevisionId && $this->mRevisionId != $wgArticle->getLatest() ) {
1514 $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
1515 } else {
1516 $timestamp = $wgArticle->getTimestamp();
1519 if ( $timestamp ) {
1520 $d = $wgLang->date( $timestamp, true );
1521 $t = $wgLang->time( $timestamp, true );
1522 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1523 } else {
1524 $s = '';
1527 if ( wfGetLB()->getLaggedSlaveMode() ) {
1528 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1531 return $s;
1534 function logoText( $align = '' ) {
1535 if ( $align != '' ) {
1536 $a = " align='{$align}'";
1537 } else {
1538 $a = '';
1541 $mp = wfMsg( 'mainpage' );
1542 $mptitle = Title::newMainPage();
1543 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
1545 $logourl = $this->getLogo();
1546 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1548 return $s;
1552 * Show a drop-down box of special pages
1554 function specialPagesList() {
1555 global $wgContLang, $wgServer, $wgRedirectScript;
1557 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1559 foreach ( $pages as $name => $page ) {
1560 $pages[$name] = $page->getDescription();
1563 $go = wfMsg( 'go' );
1564 $sp = wfMsg( 'specialpages' );
1565 $spp = $wgContLang->specialPage( 'Specialpages' );
1567 $s = '<form id="specialpages" method="get" ' .
1568 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1569 $s .= "<select name=\"wpDropdown\">\n";
1570 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1573 foreach ( $pages as $name => $desc ) {
1574 $p = $wgContLang->specialPage( $name );
1575 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1578 $s .= "</select>\n";
1579 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1580 $s .= "</form>\n";
1582 return $s;
1586 * Gets the link to the wiki's main page.
1587 * @return string
1589 function mainPageLink() {
1590 $s = $this->link(
1591 Title::newMainPage(),
1592 wfMsg( 'mainpage' ),
1593 array(),
1594 array(),
1595 array( 'known', 'noclasses' )
1598 return $s;
1601 private function footerLink( $desc, $page ) {
1602 // if the link description has been set to "-" in the default language,
1603 if ( wfMsgForContent( $desc ) == '-' ) {
1604 // then it is disabled, for all languages.
1605 return '';
1606 } else {
1607 // Otherwise, we display the link for the user, described in their
1608 // language (which may or may not be the same as the default language),
1609 // but we make the link target be the one site-wide page.
1610 $title = Title::newFromText( wfMsgForContent( $page ) );
1612 return $this->linkKnown(
1613 $title,
1614 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1620 * Gets the link to the wiki's privacy policy page.
1622 function privacyLink() {
1623 return $this->footerLink( 'privacy', 'privacypage' );
1627 * Gets the link to the wiki's about page.
1629 function aboutLink() {
1630 return $this->footerLink( 'aboutsite', 'aboutpage' );
1634 * Gets the link to the wiki's general disclaimers page.
1636 function disclaimerLink() {
1637 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1640 function editThisPage() {
1641 global $wgOut;
1643 if ( !$wgOut->isArticleRelated() ) {
1644 $s = wfMsg( 'protectedpage' );
1645 } else {
1646 if ( $this->mTitle->quickUserCan( 'edit' ) && $this->mTitle->exists() ) {
1647 $t = wfMsg( 'editthispage' );
1648 } elseif ( $this->mTitle->quickUserCan( 'create' ) && !$this->mTitle->exists() ) {
1649 $t = wfMsg( 'create-this-page' );
1650 } else {
1651 $t = wfMsg( 'viewsource' );
1654 $s = $this->link(
1655 $this->mTitle,
1657 array(),
1658 $this->editUrlOptions(),
1659 array( 'known', 'noclasses' )
1663 return $s;
1667 * Return URL options for the 'edit page' link.
1668 * This may include an 'oldid' specifier, if the current page view is such.
1670 * @return array
1671 * @private
1673 function editUrlOptions() {
1674 global $wgArticle;
1676 $options = array( 'action' => 'edit' );
1678 if ( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1679 $options['oldid'] = intval( $this->mRevisionId );
1682 return $options;
1685 function deleteThisPage() {
1686 global $wgUser, $wgRequest;
1688 $diff = $wgRequest->getVal( 'diff' );
1690 if ( $this->mTitle->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1691 $t = wfMsg( 'deletethispage' );
1693 $s = $this->link(
1694 $this->mTitle,
1696 array(),
1697 array( 'action' => 'delete' ),
1698 array( 'known', 'noclasses' )
1700 } else {
1701 $s = '';
1704 return $s;
1707 function protectThisPage() {
1708 global $wgUser, $wgRequest;
1710 $diff = $wgRequest->getVal( 'diff' );
1712 if ( $this->mTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
1713 if ( $this->mTitle->isProtected() ) {
1714 $text = wfMsg( 'unprotectthispage' );
1715 $query = array( 'action' => 'unprotect' );
1716 } else {
1717 $text = wfMsg( 'protectthispage' );
1718 $query = array( 'action' => 'protect' );
1721 $s = $this->link(
1722 $this->mTitle,
1723 $text,
1724 array(),
1725 $query,
1726 array( 'known', 'noclasses' )
1728 } else {
1729 $s = '';
1732 return $s;
1735 function watchThisPage() {
1736 global $wgOut;
1737 ++$this->mWatchLinkNum;
1739 if ( $wgOut->isArticleRelated() ) {
1740 if ( $this->mTitle->userIsWatching() ) {
1741 $text = wfMsg( 'unwatchthispage' );
1742 $query = array( 'action' => 'unwatch' );
1743 $id = 'mw-unwatch-link' . $this->mWatchLinkNum;
1744 } else {
1745 $text = wfMsg( 'watchthispage' );
1746 $query = array( 'action' => 'watch' );
1747 $id = 'mw-watch-link' . $this->mWatchLinkNum;
1750 $s = $this->link(
1751 $this->mTitle,
1752 $text,
1753 array( 'id' => $id ),
1754 $query,
1755 array( 'known', 'noclasses' )
1757 } else {
1758 $s = wfMsg( 'notanarticle' );
1761 return $s;
1764 function moveThisPage() {
1765 if ( $this->mTitle->quickUserCan( 'move' ) ) {
1766 return $this->link(
1767 SpecialPage::getTitleFor( 'Movepage' ),
1768 wfMsg( 'movethispage' ),
1769 array(),
1770 array( 'target' => $this->mTitle->getPrefixedDBkey() ),
1771 array( 'known', 'noclasses' )
1773 } else {
1774 // no message if page is protected - would be redundant
1775 return '';
1779 function historyLink() {
1780 return $this->link(
1781 $this->mTitle,
1782 wfMsgHtml( 'history' ),
1783 array( 'rel' => 'archives' ),
1784 array( 'action' => 'history' )
1788 function whatLinksHere() {
1789 return $this->link(
1790 SpecialPage::getTitleFor( 'Whatlinkshere', $this->mTitle->getPrefixedDBkey() ),
1791 wfMsgHtml( 'whatlinkshere' ),
1792 array(),
1793 array(),
1794 array( 'known', 'noclasses' )
1798 function userContribsLink() {
1799 return $this->link(
1800 SpecialPage::getTitleFor( 'Contributions', $this->mTitle->getDBkey() ),
1801 wfMsgHtml( 'contributions' ),
1802 array(),
1803 array(),
1804 array( 'known', 'noclasses' )
1808 function showEmailUser( $id ) {
1809 global $wgUser;
1810 $targetUser = User::newFromId( $id );
1811 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1812 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1815 function emailUserLink() {
1816 return $this->link(
1817 SpecialPage::getTitleFor( 'Emailuser', $this->mTitle->getDBkey() ),
1818 wfMsg( 'emailuser' ),
1819 array(),
1820 array(),
1821 array( 'known', 'noclasses' )
1825 function watchPageLinksLink() {
1826 global $wgOut;
1828 if ( !$wgOut->isArticleRelated() ) {
1829 return '(' . wfMsg( 'notanarticle' ) . ')';
1830 } else {
1831 return $this->link(
1832 SpecialPage::getTitleFor( 'Recentchangeslinked', $this->mTitle->getPrefixedDBkey() ),
1833 wfMsg( 'recentchangeslinked-toolbox' ),
1834 array(),
1835 array(),
1836 array( 'known', 'noclasses' )
1841 function trackbackLink() {
1842 return '<a href="' . $this->mTitle->trackbackURL() . '">'
1843 . wfMsg( 'trackbacklink' ) . '</a>';
1846 function otherLanguages() {
1847 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1849 if ( $wgHideInterlanguageLinks ) {
1850 return '';
1853 $a = $wgOut->getLanguageLinks();
1855 if ( 0 == count( $a ) ) {
1856 return '';
1859 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1860 $first = true;
1862 if ( $wgContLang->isRTL() ) {
1863 $s .= '<span dir="LTR">';
1866 foreach ( $a as $l ) {
1867 if ( !$first ) {
1868 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1871 $first = false;
1873 $nt = Title::newFromText( $l );
1874 $url = $nt->escapeFullURL();
1875 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1876 $title = htmlspecialchars( $nt->getText() );
1878 if ( $text == '' ) {
1879 $text = $l;
1882 $style = $this->getExternalLinkAttributes();
1883 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
1886 if ( $wgContLang->isRTL() ) {
1887 $s .= '</span>';
1890 return $s;
1893 function talkLink() {
1894 if ( NS_SPECIAL == $this->mTitle->getNamespace() ) {
1895 # No discussion links for special pages
1896 return '';
1899 $linkOptions = array();
1901 if ( $this->mTitle->isTalkPage() ) {
1902 $link = $this->mTitle->getSubjectPage();
1903 switch( $link->getNamespace() ) {
1904 case NS_MAIN:
1905 $text = wfMsg( 'articlepage' );
1906 break;
1907 case NS_USER:
1908 $text = wfMsg( 'userpage' );
1909 break;
1910 case NS_PROJECT:
1911 $text = wfMsg( 'projectpage' );
1912 break;
1913 case NS_FILE:
1914 $text = wfMsg( 'imagepage' );
1915 # Make link known if image exists, even if the desc. page doesn't.
1916 if ( wfFindFile( $link ) )
1917 $linkOptions[] = 'known';
1918 break;
1919 case NS_MEDIAWIKI:
1920 $text = wfMsg( 'mediawikipage' );
1921 break;
1922 case NS_TEMPLATE:
1923 $text = wfMsg( 'templatepage' );
1924 break;
1925 case NS_HELP:
1926 $text = wfMsg( 'viewhelppage' );
1927 break;
1928 case NS_CATEGORY:
1929 $text = wfMsg( 'categorypage' );
1930 break;
1931 default:
1932 $text = wfMsg( 'articlepage' );
1934 } else {
1935 $link = $this->mTitle->getTalkPage();
1936 $text = wfMsg( 'talkpage' );
1939 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1941 return $s;
1944 function commentLink() {
1945 global $wgOut;
1947 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
1948 return '';
1951 # __NEWSECTIONLINK___ changes behaviour here
1952 # If it is present, the link points to this page, otherwise
1953 # it points to the talk page
1954 if ( $this->mTitle->isTalkPage() ) {
1955 $title = $this->mTitle;
1956 } elseif ( $wgOut->showNewSectionLink() ) {
1957 $title = $this->mTitle;
1958 } else {
1959 $title = $this->mTitle->getTalkPage();
1962 return $this->link(
1963 $title,
1964 wfMsg( 'postcomment' ),
1965 array(),
1966 array(
1967 'action' => 'edit',
1968 'section' => 'new'
1970 array( 'known', 'noclasses' )
1974 function getUploadLink() {
1975 global $wgUploadNavigationUrl;
1977 if ( $wgUploadNavigationUrl ) {
1978 # Using an empty class attribute to avoid automatic setting of "external" class
1979 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '' ) );
1980 } else {
1981 return $this->link(
1982 SpecialPage::getTitleFor( 'Upload' ),
1983 wfMsgHtml( 'upload' ),
1984 array(),
1985 array(),
1986 array( 'known', 'noclasses' )
1991 /* these are used extensively in SkinTemplate, but also some other places */
1992 static function makeMainPageUrl( $urlaction = '' ) {
1993 $title = Title::newMainPage();
1994 self::checkTitle( $title, '' );
1996 return $title->getLocalURL( $urlaction );
1999 static function makeSpecialUrl( $name, $urlaction = '' ) {
2000 $title = SpecialPage::getTitleFor( $name );
2001 return $title->getLocalURL( $urlaction );
2004 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2005 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
2006 return $title->getLocalURL( $urlaction );
2009 static function makeI18nUrl( $name, $urlaction = '' ) {
2010 $title = Title::newFromText( wfMsgForContent( $name ) );
2011 self::checkTitle( $title, $name );
2012 return $title->getLocalURL( $urlaction );
2015 static function makeUrl( $name, $urlaction = '' ) {
2016 $title = Title::newFromText( $name );
2017 self::checkTitle( $title, $name );
2019 return $title->getLocalURL( $urlaction );
2023 * If url string starts with http, consider as external URL, else
2024 * internal
2026 static function makeInternalOrExternalUrl( $name ) {
2027 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2028 return $name;
2029 } else {
2030 return self::makeUrl( $name );
2034 # this can be passed the NS number as defined in Language.php
2035 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
2036 $title = Title::makeTitleSafe( $namespace, $name );
2037 self::checkTitle( $title, $name );
2039 return $title->getLocalURL( $urlaction );
2042 /* these return an array with the 'href' and boolean 'exists' */
2043 static function makeUrlDetails( $name, $urlaction = '' ) {
2044 $title = Title::newFromText( $name );
2045 self::checkTitle( $title, $name );
2047 return array(
2048 'href' => $title->getLocalURL( $urlaction ),
2049 'exists' => $title->getArticleID() != 0,
2054 * Make URL details where the article exists (or at least it's convenient to think so)
2056 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2057 $title = Title::newFromText( $name );
2058 self::checkTitle( $title, $name );
2060 return array(
2061 'href' => $title->getLocalURL( $urlaction ),
2062 'exists' => true
2066 # make sure we have some title to operate on
2067 static function checkTitle( &$title, $name ) {
2068 if ( !is_object( $title ) ) {
2069 $title = Title::newFromText( $name );
2070 if ( !is_object( $title ) ) {
2071 $title = Title::newFromText( '--error: link target missing--' );
2077 * Build an array that represents the sidebar(s), the navigation bar among them
2079 * @return array
2081 function buildSidebar() {
2082 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2083 global $wgLang;
2084 wfProfileIn( __METHOD__ );
2086 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2088 if ( $wgEnableSidebarCache ) {
2089 $cachedsidebar = $parserMemc->get( $key );
2090 if ( $cachedsidebar ) {
2091 wfProfileOut( __METHOD__ );
2092 return $cachedsidebar;
2096 $bar = array();
2097 $this->addToSidebar( $bar, 'sidebar' );
2099 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2100 if ( $wgEnableSidebarCache ) {
2101 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2104 wfProfileOut( __METHOD__ );
2105 return $bar;
2108 * Add content from a sidebar system message
2109 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2111 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2113 * @param &$bar array
2114 * @param $message String
2116 function addToSidebar( &$bar, $message ) {
2117 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2121 * Add content from plain text
2122 * @since 1.17
2123 * @param &$bar array
2124 * @param $text string
2126 function addToSidebarPlain( &$bar, $text ) {
2127 $lines = explode( "\n", $text );
2128 $wikiBar = array(); # We need to handle the wikitext on a different variable, to avoid trying to do an array operation on text, which would be a fatal error.
2130 $heading = '';
2132 foreach ( $lines as $line ) {
2133 if ( strpos( $line, '*' ) !== 0 ) {
2134 continue;
2137 if ( strpos( $line, '**' ) !== 0 ) {
2138 $heading = trim( $line, '* ' );
2139 if ( !array_key_exists( $heading, $bar ) ) {
2140 $bar[$heading] = array();
2142 } else {
2143 $line = trim( $line, '* ' );
2145 if ( strpos( $line, '|' ) !== false ) { // sanity check
2146 $line = array_map( 'trim', explode( '|', $line, 2 ) );
2147 $link = wfMsgForContent( $line[0] );
2149 if ( $link == '-' ) {
2150 continue;
2153 $text = wfMsgExt( $line[1], 'parsemag' );
2155 if ( wfEmptyMsg( $line[1], $text ) ) {
2156 $text = $line[1];
2159 if ( wfEmptyMsg( $line[0], $link ) ) {
2160 $link = $line[0];
2163 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2164 $href = $link;
2165 } else {
2166 $title = Title::newFromText( $link );
2168 if ( $title ) {
2169 $title = $title->fixSpecialName();
2170 $href = $title->getLocalURL();
2171 } else {
2172 $href = 'INVALID-TITLE';
2176 $bar[$heading][] = array(
2177 'text' => $text,
2178 'href' => $href,
2179 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2180 'active' => false
2182 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
2183 global $wgParser, $wgTitle;
2185 $line = substr( $line, 2, strlen( $line ) - 4 );
2187 if ( is_null( $wgParser->mOptions ) ) {
2188 $wgParser->mOptions = new ParserOptions();
2191 $wgParser->mOptions->setEditSection( false );
2192 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $wgParser->mOptions )->getText();
2193 } else {
2194 continue;
2199 if ( count( $wikiBar ) > 0 ) {
2200 $bar = array_merge( $bar, $wikiBar );
2203 return $bar;
2207 * Should we include common/wikiprintable.css? Skins that have their own
2208 * print stylesheet should override this and return false. (This is an
2209 * ugly hack to get Monobook to play nicely with
2210 * OutputPage::headElement().)
2212 * @return bool
2214 public function commonPrintStylesheet() {
2215 return true;
2219 * Gets new talk page messages for the current user.
2220 * @return MediaWiki message or if no new talk page messages, nothing
2222 function getNewtalks() {
2223 global $wgUser, $wgOut;
2225 $newtalks = $wgUser->getNewMessageLinks();
2226 $ntl = '';
2228 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2229 $userTitle = $this->mUser->getUserPage();
2230 $userTalkTitle = $userTitle->getTalkPage();
2232 if ( !$userTalkTitle->equals( $this->mTitle ) ) {
2233 $newMessagesLink = $this->link(
2234 $userTalkTitle,
2235 wfMsgHtml( 'newmessageslink' ),
2236 array(),
2237 array( 'redirect' => 'no' ),
2238 array( 'known', 'noclasses' )
2241 $newMessagesDiffLink = $this->link(
2242 $userTalkTitle,
2243 wfMsgHtml( 'newmessagesdifflink' ),
2244 array(),
2245 array( 'diff' => 'cur' ),
2246 array( 'known', 'noclasses' )
2249 $ntl = wfMsg(
2250 'youhavenewmessages',
2251 $newMessagesLink,
2252 $newMessagesDiffLink
2254 # Disable Squid cache
2255 $wgOut->setSquidMaxage( 0 );
2257 } elseif ( count( $newtalks ) ) {
2258 // _>" " for BC <= 1.16
2259 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2260 $msgs = array();
2262 foreach ( $newtalks as $newtalk ) {
2263 $msgs[] = Xml::element(
2264 'a',
2265 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2268 $parts = implode( $sep, $msgs );
2269 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2270 $wgOut->setSquidMaxage( 0 );
2273 return $ntl;