rm unused code
[mediawiki.git] / includes / Skin.php
blobeb8ebf97a5f5206a5fa86dbf617048106e049596
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 * This will be called by OutputPage::headElement when it is creating the
574 * <body> tag, skins can override it if they have a need to add in any
575 * body attributes or classes of their own.
577 function addToBodyAttributes( $out, &$bodyAttrs ) {
578 // does nothing by default
582 * URL to the logo
584 function getLogo() {
585 global $wgLogo;
586 return $wgLogo;
590 * This will be called immediately after the <body> tag. Split into
591 * two functions to make it easier to subclass.
593 function beforeContent() {
594 return $this->doBeforeContent();
597 function doBeforeContent() {
598 global $wgContLang;
599 wfProfileIn( __METHOD__ );
601 $s = '';
602 $qb = $this->qbSetting();
604 $langlinks = $this->otherLanguages();
605 if ( $langlinks ) {
606 $rows = 2;
607 $borderhack = '';
608 } else {
609 $rows = 1;
610 $langlinks = false;
611 $borderhack = 'class="top"';
614 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
615 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
617 $shove = ( $qb != 0 );
618 $left = ( $qb == 1 || $qb == 3 );
620 if ( $wgContLang->isRTL() ) {
621 $left = !$left;
624 if ( !$shove ) {
625 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
626 $this->logoText() . '</td>';
627 } elseif ( $left ) {
628 $s .= $this->getQuickbarCompensator( $rows );
631 $l = $wgContLang->alignStart();
632 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
634 $s .= $this->topLinks();
635 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
637 $r = $wgContLang->alignEnd();
638 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
639 $s .= $this->nameAndLogin();
640 $s .= "\n<br />" . $this->searchForm() . '</td>';
642 if ( $langlinks ) {
643 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
646 if ( $shove && !$left ) { # Right
647 $s .= $this->getQuickbarCompensator( $rows );
650 $s .= "</tr>\n</table>\n</div>\n";
651 $s .= "\n<div id='article'>\n";
653 $notice = wfGetSiteNotice();
655 if ( $notice ) {
656 $s .= "\n<div id='siteNotice'>$notice</div>\n";
658 $s .= $this->pageTitle();
659 $s .= $this->pageSubtitle();
660 $s .= $this->getCategories();
662 wfProfileOut( __METHOD__ );
663 return $s;
666 function getCategoryLinks() {
667 global $wgOut, $wgUseCategoryBrowser;
668 global $wgContLang, $wgUser;
670 if ( count( $wgOut->mCategoryLinks ) == 0 ) {
671 return '';
674 # Separator
675 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
677 // Use Unicode bidi embedding override characters,
678 // to make sure links don't smash each other up in ugly ways.
679 $dir = $wgContLang->getDir();
680 $embed = "<span dir='$dir'>";
681 $pop = '</span>';
683 $allCats = $wgOut->getCategoryLinks();
684 $s = '';
685 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
687 if ( !empty( $allCats['normal'] ) ) {
688 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
690 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
691 $s .= '<div id="mw-normal-catlinks">' .
692 $this->link( Title::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
693 . $colon . $t . '</div>';
696 # Hidden categories
697 if ( isset( $allCats['hidden'] ) ) {
698 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
699 $class = 'mw-hidden-cats-user-shown';
700 } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
701 $class = 'mw-hidden-cats-ns-shown';
702 } else {
703 $class = 'mw-hidden-cats-hidden';
706 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
707 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
708 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
709 '</div>';
712 # optional 'dmoz-like' category browser. Will be shown under the list
713 # of categories an article belong to
714 if ( $wgUseCategoryBrowser ) {
715 $s .= '<br /><hr />';
717 # get a big array of the parents tree
718 $parenttree = $this->mTitle->getParentCategoryTree();
719 # Skin object passed by reference cause it can not be
720 # accessed under the method subfunction drawCategoryBrowser
721 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
722 # Clean out bogus first entry and sort them
723 unset( $tempout[0] );
724 asort( $tempout );
725 # Output one per line
726 $s .= implode( "<br />\n", $tempout );
729 return $s;
733 * Render the array as a serie of links.
734 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
735 * @param &skin Object: skin passed by reference
736 * @return String separated by &gt;, terminate with "\n"
738 function drawCategoryBrowser( $tree, &$skin ) {
739 $return = '';
741 foreach ( $tree as $element => $parent ) {
742 if ( empty( $parent ) ) {
743 # element start a new list
744 $return .= "\n";
745 } else {
746 # grab the others elements
747 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' &gt; ';
750 # add our current element to the list
751 $eltitle = Title::newFromText( $element );
752 $return .= $skin->link( $eltitle, $eltitle->getText() );
755 return $return;
758 function getCategories() {
759 $catlinks = $this->getCategoryLinks();
761 $classes = 'catlinks';
763 global $wgOut, $wgUser;
765 // Check what we're showing
766 $allCats = $wgOut->getCategoryLinks();
767 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
768 $this->mTitle->getNamespace() == NS_CATEGORY;
770 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
771 $classes .= ' catlinks-allhidden';
774 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
777 function getQuickbarCompensator( $rows = 1 ) {
778 return "<td width='152' rowspan='{$rows}'>&#160;</td>";
782 * This runs a hook to allow extensions placing their stuff after content
783 * and article metadata (e.g. categories).
784 * Note: This function has nothing to do with afterContent().
786 * This hook is placed here in order to allow using the same hook for all
787 * skins, both the SkinTemplate based ones and the older ones, which directly
788 * use this class to get their data.
790 * The output of this function gets processed in SkinTemplate::outputPage() for
791 * the SkinTemplate based skins, all other skins should directly echo it.
793 * Returns an empty string by default, if not changed by any hook function.
795 protected function afterContentHook() {
796 $data = '';
798 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
799 // adding just some spaces shouldn't toggle the output
800 // of the whole <div/>, so we use trim() here
801 if ( trim( $data ) != '' ) {
802 // Doing this here instead of in the skins to
803 // ensure that the div has the same ID in all
804 // skins
805 $data = "<div id='mw-data-after-content'>\n" .
806 "\t$data\n" .
807 "</div>\n";
809 } else {
810 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
813 return $data;
817 * Generate debug data HTML for displaying at the bottom of the main content
818 * area.
819 * @return String HTML containing debug data, if enabled (otherwise empty).
821 protected function generateDebugHTML() {
822 global $wgShowDebug, $wgOut;
824 if ( $wgShowDebug ) {
825 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext );
826 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
827 $listInternals . "</ul>\n";
830 return '';
833 private function formatDebugHTML( $debugText ) {
834 $lines = explode( "\n", $debugText );
835 $curIdent = 0;
836 $ret = '<li>';
838 foreach ( $lines as $line ) {
839 $display = ltrim( $line );
840 $ident = strlen( $line ) - strlen( $display );
841 $diff = $ident - $curIdent;
843 if ( $display == '' ) {
844 $display = "\xc2\xa0";
847 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
848 $ident = $curIdent;
849 $diff = 0;
850 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
851 } else {
852 $display = htmlspecialchars( $display );
855 if ( $diff < 0 ) {
856 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
857 } elseif ( $diff == 0 ) {
858 $ret .= "</li><li>\n";
859 } else {
860 $ret .= str_repeat( "<ul><li>\n", $diff );
862 $ret .= $display . "\n";
864 $curIdent = $ident;
867 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
869 return $ret;
873 * This gets called shortly before the </body> tag.
874 * @return String HTML to be put before </body>
876 function afterContent() {
877 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
878 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
882 * This gets called shortly before the </body> tag.
883 * @param $out OutputPage object
884 * @return String HTML-wrapped JS code to be put before </body>
886 function bottomScripts( $out ) {
887 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
888 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
890 return $bottomScriptText;
893 /** @return string Retrievied from HTML text */
894 function printSource() {
895 $url = htmlspecialchars( $this->mTitle->getFullURL() );
896 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
899 function printFooter() {
900 return "<p>" . $this->printSource() .
901 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
904 /** overloaded by derived classes */
905 function doAfterContent() {
906 return '</div></div>';
909 function pageTitleLinks() {
910 global $wgOut, $wgUser, $wgRequest, $wgLang;
912 $oldid = $wgRequest->getVal( 'oldid' );
913 $diff = $wgRequest->getVal( 'diff' );
914 $action = $wgRequest->getText( 'action' );
916 $s[] = $this->printableLink();
917 $disclaimer = $this->disclaimerLink(); # may be empty
919 if ( $disclaimer ) {
920 $s[] = $disclaimer;
923 $privacy = $this->privacyLink(); # may be empty too
925 if ( $privacy ) {
926 $s[] = $privacy;
929 if ( $wgOut->isArticleRelated() ) {
930 if ( $this->mTitle->getNamespace() == NS_FILE ) {
931 $name = $this->mTitle->getDBkey();
932 $image = wfFindFile( $this->mTitle );
934 if ( $image ) {
935 $link = htmlspecialchars( $image->getURL() );
936 $style = $this->getInternalLinkAttributes( $link, $name );
937 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
942 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
943 $s[] .= $this->link(
944 $this->mTitle,
945 wfMsg( 'currentrev' ),
946 array(),
947 array(),
948 array( 'known', 'noclasses' )
952 if ( $wgUser->getNewtalk() ) {
953 # do not show "You have new messages" text when we are viewing our
954 # own talk page
955 if ( !$this->mTitle->equals( $wgUser->getTalkPage() ) ) {
956 $tl = $this->link(
957 $wgUser->getTalkPage(),
958 wfMsgHtml( 'newmessageslink' ),
959 array(),
960 array( 'redirect' => 'no' ),
961 array( 'known', 'noclasses' )
964 $dl = $this->link(
965 $wgUser->getTalkPage(),
966 wfMsgHtml( 'newmessagesdifflink' ),
967 array(),
968 array( 'diff' => 'cur' ),
969 array( 'known', 'noclasses' )
971 $s[] = '<strong>' . wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
972 # disable caching
973 $wgOut->setSquidMaxage( 0 );
974 $wgOut->enableClientCache( false );
978 $undelete = $this->getUndeleteLink();
980 if ( !empty( $undelete ) ) {
981 $s[] = $undelete;
984 return $wgLang->pipeList( $s );
987 function getUndeleteLink() {
988 global $wgUser, $wgLang, $wgRequest;
990 $action = $wgRequest->getVal( 'action', 'view' );
992 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
993 ( $this->mTitle->getArticleId() == 0 || $action == 'history' ) ) {
994 $n = $this->mTitle->isDeleted();
996 if ( $n ) {
997 if ( $wgUser->isAllowed( 'undelete' ) ) {
998 $msg = 'thisisdeleted';
999 } else {
1000 $msg = 'viewdeleted';
1003 return wfMsg(
1004 $msg,
1005 $this->link(
1006 SpecialPage::getTitleFor( 'Undelete', $this->mTitle->getPrefixedDBkey() ),
1007 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1008 array(),
1009 array(),
1010 array( 'known', 'noclasses' )
1016 return '';
1019 function printableLink() {
1020 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1022 $s = array();
1024 if ( !$wgOut->isPrintable() ) {
1025 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1026 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1029 if ( $wgOut->isSyndicated() ) {
1030 foreach ( $wgFeedClasses as $format => $class ) {
1031 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1032 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1033 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1036 return $wgLang->pipeList( $s );
1040 * Gets the h1 element with the page title.
1041 * @return string
1043 function pageTitle() {
1044 global $wgOut;
1045 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1046 return $s;
1049 function pageSubtitle() {
1050 global $wgOut;
1052 $sub = $wgOut->getSubtitle();
1054 if ( $sub == '' ) {
1055 global $wgExtraSubtitle;
1056 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1059 $subpages = $this->subPageSubtitle();
1060 $sub .= !empty( $subpages ) ? "</p><p class='subpages'>$subpages" : '';
1061 $s = "<p class='subtitle'>{$sub}</p>\n";
1063 return $s;
1066 function subPageSubtitle() {
1067 $subpages = '';
1069 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this ) ) ) {
1070 return $subpages;
1073 global $wgOut;
1075 if ( $wgOut->isArticle() && MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
1076 $ptext = $this->mTitle->getPrefixedText();
1077 if ( preg_match( '/\//', $ptext ) ) {
1078 $links = explode( '/', $ptext );
1079 array_pop( $links );
1080 $c = 0;
1081 $growinglink = '';
1082 $display = '';
1084 foreach ( $links as $link ) {
1085 $growinglink .= $link;
1086 $display .= $link;
1087 $linkObj = Title::newFromText( $growinglink );
1089 if ( is_object( $linkObj ) && $linkObj->exists() ) {
1090 $getlink = $this->link(
1091 $linkObj,
1092 htmlspecialchars( $display ),
1093 array(),
1094 array(),
1095 array( 'known', 'noclasses' )
1098 $c++;
1100 if ( $c > 1 ) {
1101 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1102 } else {
1103 $subpages .= '&lt; ';
1106 $subpages .= $getlink;
1107 $display = '';
1108 } else {
1109 $display .= '/';
1111 $growinglink .= '/';
1116 return $subpages;
1120 * Returns true if the IP should be shown in the header
1122 function showIPinHeader() {
1123 global $wgShowIPinHeader;
1124 return $wgShowIPinHeader && session_id() != '';
1127 function nameAndLogin() {
1128 global $wgUser, $wgLang, $wgContLang;
1130 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1132 $ret = '';
1134 if ( $wgUser->isAnon() ) {
1135 if ( $this->showIPinHeader() ) {
1136 $name = wfGetIP();
1138 $talkLink = $this->link( $wgUser->getTalkPage(),
1139 $wgLang->getNsText( NS_TALK ) );
1141 $ret .= "$name ($talkLink)";
1142 } else {
1143 $ret .= wfMsg( 'notloggedin' );
1146 $returnTo = $this->mTitle->getPrefixedDBkey();
1147 $query = array();
1149 if ( $logoutPage != $returnTo ) {
1150 $query['returnto'] = $returnTo;
1153 $loginlink = $wgUser->isAllowed( 'createaccount' )
1154 ? 'nav-login-createaccount'
1155 : 'login';
1156 $ret .= "\n<br />" . $this->link(
1157 SpecialPage::getTitleFor( 'Userlogin' ),
1158 wfMsg( $loginlink ), array(), $query
1160 } else {
1161 $returnTo = $this->mTitle->getPrefixedDBkey();
1162 $talkLink = $this->link( $wgUser->getTalkPage(),
1163 $wgLang->getNsText( NS_TALK ) );
1165 $ret .= $this->link( $wgUser->getUserPage(),
1166 htmlspecialchars( $wgUser->getName() ) );
1167 $ret .= " ($talkLink)<br />";
1168 $ret .= $wgLang->pipeList( array(
1169 $this->link(
1170 SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1171 array(), array( 'returnto' => $returnTo )
1173 $this->specialLink( 'Preferences' ),
1174 ) );
1177 $ret = $wgLang->pipeList( array(
1178 $ret,
1179 $this->link(
1180 Title::newFromText( wfMsgForContent( 'helppage' ) ),
1181 wfMsg( 'help' )
1183 ) );
1185 return $ret;
1188 function getSearchLink() {
1189 $searchPage = SpecialPage::getTitleFor( 'Search' );
1190 return $searchPage->getLocalURL();
1193 function escapeSearchLink() {
1194 return htmlspecialchars( $this->getSearchLink() );
1197 function searchForm() {
1198 global $wgRequest, $wgUseTwoButtonsSearchForm;
1200 $search = $wgRequest->getText( 'search' );
1202 $s = '<form id="searchform' . $this->searchboxes . '" name="search" class="inline" method="post" action="'
1203 . $this->escapeSearchLink() . "\">\n"
1204 . '<input type="text" id="searchInput' . $this->searchboxes . '" name="search" size="19" value="'
1205 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1206 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1208 if ( $wgUseTwoButtonsSearchForm ) {
1209 $s .= '&#160;<input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1210 } else {
1211 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1214 $s .= '</form>';
1216 // Ensure unique id's for search boxes made after the first
1217 $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
1219 return $s;
1222 function topLinks() {
1223 global $wgOut;
1225 $s = array(
1226 $this->mainPageLink(),
1227 $this->specialLink( 'Recentchanges' )
1230 if ( $wgOut->isArticleRelated() ) {
1231 $s[] = $this->editThisPage();
1232 $s[] = $this->historyLink();
1235 # Many people don't like this dropdown box
1236 # $s[] = $this->specialPagesList();
1238 if ( $this->variantLinks() ) {
1239 $s[] = $this->variantLinks();
1242 if ( $this->extensionTabLinks() ) {
1243 $s[] = $this->extensionTabLinks();
1246 // @todo FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1247 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1251 * Compatibility for extensions adding functionality through tabs.
1252 * Eventually these old skins should be replaced with SkinTemplate-based
1253 * versions, sigh...
1254 * @return string
1256 function extensionTabLinks() {
1257 $tabs = array();
1258 $out = '';
1259 $s = array();
1260 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1261 foreach ( $tabs as $tab ) {
1262 $s[] = Xml::element( 'a',
1263 array( 'href' => $tab['href'] ),
1264 $tab['text'] );
1267 if ( count( $s ) ) {
1268 global $wgLang;
1270 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1271 $out .= $wgLang->pipeList( $s );
1274 return $out;
1278 * Language/charset variant links for classic-style skins
1279 * @return string
1281 function variantLinks() {
1282 $s = '';
1284 /* show links to different language variants */
1285 global $wgDisableLangConversion, $wgLang, $wgContLang;
1287 $variants = $wgContLang->getVariants();
1289 if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1290 foreach ( $variants as $code ) {
1291 $varname = $wgContLang->getVariantname( $code );
1293 if ( $varname == 'disable' ) {
1294 continue;
1296 $s = $wgLang->pipeList( array(
1298 '<a href="' . $this->mTitle->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1299 ) );
1303 return $s;
1306 function bottomLinks() {
1307 global $wgOut, $wgUser, $wgUseTrackbacks;
1308 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1310 $s = '';
1311 if ( $wgOut->isArticleRelated() ) {
1312 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1314 if ( $wgUser->isLoggedIn() ) {
1315 $element[] = $this->watchThisPage();
1318 $element[] = $this->talkLink();
1319 $element[] = $this->historyLink();
1320 $element[] = $this->whatLinksHere();
1321 $element[] = $this->watchPageLinksLink();
1323 if ( $wgUseTrackbacks ) {
1324 $element[] = $this->trackbackLink();
1327 if (
1328 $this->mTitle->getNamespace() == NS_USER ||
1329 $this->mTitle->getNamespace() == NS_USER_TALK
1331 $id = User::idFromName( $this->mTitle->getText() );
1332 $ip = User::isIP( $this->mTitle->getText() );
1334 # Both anons and non-anons have contributions list
1335 if ( $id || $ip ) {
1336 $element[] = $this->userContribsLink();
1339 if ( $this->showEmailUser( $id ) ) {
1340 $element[] = $this->emailUserLink();
1344 $s = implode( $element, $sep );
1346 if ( $this->mTitle->getArticleId() ) {
1347 $s .= "\n<br />";
1349 // Delete/protect/move links for privileged users
1350 if ( $wgUser->isAllowed( 'delete' ) ) {
1351 $s .= $this->deleteThisPage();
1354 if ( $wgUser->isAllowed( 'protect' ) ) {
1355 $s .= $sep . $this->protectThisPage();
1358 if ( $wgUser->isAllowed( 'move' ) ) {
1359 $s .= $sep . $this->moveThisPage();
1363 $s .= "<br />\n" . $this->otherLanguages();
1366 return $s;
1369 function pageStats() {
1370 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1371 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1373 $oldid = $wgRequest->getVal( 'oldid' );
1374 $diff = $wgRequest->getVal( 'diff' );
1376 if ( !$wgOut->isArticle() ) {
1377 return '';
1380 if ( !$wgArticle instanceof Article ) {
1381 return '';
1384 if ( isset( $oldid ) || isset( $diff ) ) {
1385 return '';
1388 if ( 0 == $wgArticle->getID() ) {
1389 return '';
1392 $s = '';
1394 if ( !$wgDisableCounters ) {
1395 $count = $wgLang->formatNum( $wgArticle->getCount() );
1397 if ( $count ) {
1398 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1402 if ( $wgMaxCredits != 0 ) {
1403 $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1404 } else {
1405 $s .= $this->lastModified();
1408 if ( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1409 $dbr = wfGetDB( DB_SLAVE );
1410 $res = $dbr->select(
1411 'watchlist',
1412 array( 'COUNT(*) AS n' ),
1413 array(
1414 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ),
1415 'wl_namespace' => $this->mTitle->getNamespace()
1417 __METHOD__
1419 $x = $dbr->fetchObject( $res );
1421 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1422 array( 'parseinline' ), $wgLang->formatNum( $x->n )
1426 return $s . ' ' . $this->getCopyright();
1429 function getCopyright( $type = 'detect' ) {
1430 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1432 if ( $type == 'detect' ) {
1433 $diff = $wgRequest->getVal( 'diff' );
1434 $isCur = $wgArticle && $wgArticle->isCurrent();
1436 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1437 $type = 'history';
1438 } else {
1439 $type = 'normal';
1443 if ( $type == 'history' ) {
1444 $msg = 'history_copyright';
1445 } else {
1446 $msg = 'copyright';
1449 $out = '';
1451 if ( $wgRightsPage ) {
1452 $title = Title::newFromText( $wgRightsPage );
1453 $link = $this->linkKnown( $title, $wgRightsText );
1454 } elseif ( $wgRightsUrl ) {
1455 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1456 } elseif ( $wgRightsText ) {
1457 $link = $wgRightsText;
1458 } else {
1459 # Give up now
1460 return $out;
1463 // Allow for site and per-namespace customization of copyright notice.
1464 $forContent = true;
1466 if ( isset( $wgArticle ) ) {
1467 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link, &$forContent ) );
1470 if ( $forContent ) {
1471 $out .= wfMsgForContent( $msg, $link );
1472 } else {
1473 $out .= wfMsg( $msg, $link );
1476 return $out;
1479 function getCopyrightIcon() {
1480 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1482 $out = '';
1484 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1485 $out = $wgCopyrightIcon;
1486 } elseif ( $wgRightsIcon ) {
1487 $icon = htmlspecialchars( $wgRightsIcon );
1489 if ( $wgRightsUrl ) {
1490 $url = htmlspecialchars( $wgRightsUrl );
1491 $out .= '<a href="' . $url . '">';
1494 $text = htmlspecialchars( $wgRightsText );
1495 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1497 if ( $wgRightsUrl ) {
1498 $out .= '</a>';
1502 return $out;
1506 * Gets the powered by MediaWiki icon.
1507 * @return string
1509 function getPoweredBy() {
1510 global $wgStylePath;
1512 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1513 $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1515 return $img;
1518 function lastModified() {
1519 global $wgLang, $wgArticle;
1521 if ( $this->mRevisionId && $this->mRevisionId != $wgArticle->getLatest() ) {
1522 $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
1523 } else {
1524 $timestamp = $wgArticle->getTimestamp();
1527 if ( $timestamp ) {
1528 $d = $wgLang->date( $timestamp, true );
1529 $t = $wgLang->time( $timestamp, true );
1530 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1531 } else {
1532 $s = '';
1535 if ( wfGetLB()->getLaggedSlaveMode() ) {
1536 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1539 return $s;
1542 function logoText( $align = '' ) {
1543 if ( $align != '' ) {
1544 $a = " align='{$align}'";
1545 } else {
1546 $a = '';
1549 $mp = wfMsg( 'mainpage' );
1550 $mptitle = Title::newMainPage();
1551 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
1553 $logourl = $this->getLogo();
1554 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1556 return $s;
1560 * Show a drop-down box of special pages
1562 function specialPagesList() {
1563 global $wgContLang, $wgServer, $wgRedirectScript;
1565 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1567 foreach ( $pages as $name => $page ) {
1568 $pages[$name] = $page->getDescription();
1571 $go = wfMsg( 'go' );
1572 $sp = wfMsg( 'specialpages' );
1573 $spp = $wgContLang->specialPage( 'Specialpages' );
1575 $s = '<form id="specialpages" method="get" ' .
1576 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1577 $s .= "<select name=\"wpDropdown\">\n";
1578 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1581 foreach ( $pages as $name => $desc ) {
1582 $p = $wgContLang->specialPage( $name );
1583 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1586 $s .= "</select>\n";
1587 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1588 $s .= "</form>\n";
1590 return $s;
1594 * Gets the link to the wiki's main page.
1595 * @return string
1597 function mainPageLink() {
1598 $s = $this->link(
1599 Title::newMainPage(),
1600 wfMsg( 'mainpage' ),
1601 array(),
1602 array(),
1603 array( 'known', 'noclasses' )
1606 return $s;
1609 private function footerLink( $desc, $page ) {
1610 // if the link description has been set to "-" in the default language,
1611 if ( wfMsgForContent( $desc ) == '-' ) {
1612 // then it is disabled, for all languages.
1613 return '';
1614 } else {
1615 // Otherwise, we display the link for the user, described in their
1616 // language (which may or may not be the same as the default language),
1617 // but we make the link target be the one site-wide page.
1618 $title = Title::newFromText( wfMsgForContent( $page ) );
1620 return $this->linkKnown(
1621 $title,
1622 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1628 * Gets the link to the wiki's privacy policy page.
1630 function privacyLink() {
1631 return $this->footerLink( 'privacy', 'privacypage' );
1635 * Gets the link to the wiki's about page.
1637 function aboutLink() {
1638 return $this->footerLink( 'aboutsite', 'aboutpage' );
1642 * Gets the link to the wiki's general disclaimers page.
1644 function disclaimerLink() {
1645 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1648 function editThisPage() {
1649 global $wgOut;
1651 if ( !$wgOut->isArticleRelated() ) {
1652 $s = wfMsg( 'protectedpage' );
1653 } else {
1654 if ( $this->mTitle->quickUserCan( 'edit' ) && $this->mTitle->exists() ) {
1655 $t = wfMsg( 'editthispage' );
1656 } elseif ( $this->mTitle->quickUserCan( 'create' ) && !$this->mTitle->exists() ) {
1657 $t = wfMsg( 'create-this-page' );
1658 } else {
1659 $t = wfMsg( 'viewsource' );
1662 $s = $this->link(
1663 $this->mTitle,
1665 array(),
1666 $this->editUrlOptions(),
1667 array( 'known', 'noclasses' )
1671 return $s;
1675 * Return URL options for the 'edit page' link.
1676 * This may include an 'oldid' specifier, if the current page view is such.
1678 * @return array
1679 * @private
1681 function editUrlOptions() {
1682 global $wgArticle;
1684 $options = array( 'action' => 'edit' );
1686 if ( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1687 $options['oldid'] = intval( $this->mRevisionId );
1690 return $options;
1693 function deleteThisPage() {
1694 global $wgUser, $wgRequest;
1696 $diff = $wgRequest->getVal( 'diff' );
1698 if ( $this->mTitle->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1699 $t = wfMsg( 'deletethispage' );
1701 $s = $this->link(
1702 $this->mTitle,
1704 array(),
1705 array( 'action' => 'delete' ),
1706 array( 'known', 'noclasses' )
1708 } else {
1709 $s = '';
1712 return $s;
1715 function protectThisPage() {
1716 global $wgUser, $wgRequest;
1718 $diff = $wgRequest->getVal( 'diff' );
1720 if ( $this->mTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
1721 if ( $this->mTitle->isProtected() ) {
1722 $text = wfMsg( 'unprotectthispage' );
1723 $query = array( 'action' => 'unprotect' );
1724 } else {
1725 $text = wfMsg( 'protectthispage' );
1726 $query = array( 'action' => 'protect' );
1729 $s = $this->link(
1730 $this->mTitle,
1731 $text,
1732 array(),
1733 $query,
1734 array( 'known', 'noclasses' )
1736 } else {
1737 $s = '';
1740 return $s;
1743 function watchThisPage() {
1744 global $wgOut;
1745 ++$this->mWatchLinkNum;
1747 if ( $wgOut->isArticleRelated() ) {
1748 if ( $this->mTitle->userIsWatching() ) {
1749 $text = wfMsg( 'unwatchthispage' );
1750 $query = array( 'action' => 'unwatch' );
1751 $id = 'mw-unwatch-link' . $this->mWatchLinkNum;
1752 } else {
1753 $text = wfMsg( 'watchthispage' );
1754 $query = array( 'action' => 'watch' );
1755 $id = 'mw-watch-link' . $this->mWatchLinkNum;
1758 $s = $this->link(
1759 $this->mTitle,
1760 $text,
1761 array( 'id' => $id ),
1762 $query,
1763 array( 'known', 'noclasses' )
1765 } else {
1766 $s = wfMsg( 'notanarticle' );
1769 return $s;
1772 function moveThisPage() {
1773 if ( $this->mTitle->quickUserCan( 'move' ) ) {
1774 return $this->link(
1775 SpecialPage::getTitleFor( 'Movepage' ),
1776 wfMsg( 'movethispage' ),
1777 array(),
1778 array( 'target' => $this->mTitle->getPrefixedDBkey() ),
1779 array( 'known', 'noclasses' )
1781 } else {
1782 // no message if page is protected - would be redundant
1783 return '';
1787 function historyLink() {
1788 return $this->link(
1789 $this->mTitle,
1790 wfMsgHtml( 'history' ),
1791 array( 'rel' => 'archives' ),
1792 array( 'action' => 'history' )
1796 function whatLinksHere() {
1797 return $this->link(
1798 SpecialPage::getTitleFor( 'Whatlinkshere', $this->mTitle->getPrefixedDBkey() ),
1799 wfMsgHtml( 'whatlinkshere' ),
1800 array(),
1801 array(),
1802 array( 'known', 'noclasses' )
1806 function userContribsLink() {
1807 return $this->link(
1808 SpecialPage::getTitleFor( 'Contributions', $this->mTitle->getDBkey() ),
1809 wfMsgHtml( 'contributions' ),
1810 array(),
1811 array(),
1812 array( 'known', 'noclasses' )
1816 function showEmailUser( $id ) {
1817 global $wgUser;
1818 $targetUser = User::newFromId( $id );
1819 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1820 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1823 function emailUserLink() {
1824 return $this->link(
1825 SpecialPage::getTitleFor( 'Emailuser', $this->mTitle->getDBkey() ),
1826 wfMsg( 'emailuser' ),
1827 array(),
1828 array(),
1829 array( 'known', 'noclasses' )
1833 function watchPageLinksLink() {
1834 global $wgOut;
1836 if ( !$wgOut->isArticleRelated() ) {
1837 return '(' . wfMsg( 'notanarticle' ) . ')';
1838 } else {
1839 return $this->link(
1840 SpecialPage::getTitleFor( 'Recentchangeslinked', $this->mTitle->getPrefixedDBkey() ),
1841 wfMsg( 'recentchangeslinked-toolbox' ),
1842 array(),
1843 array(),
1844 array( 'known', 'noclasses' )
1849 function trackbackLink() {
1850 return '<a href="' . $this->mTitle->trackbackURL() . '">'
1851 . wfMsg( 'trackbacklink' ) . '</a>';
1854 function otherLanguages() {
1855 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1857 if ( $wgHideInterlanguageLinks ) {
1858 return '';
1861 $a = $wgOut->getLanguageLinks();
1863 if ( 0 == count( $a ) ) {
1864 return '';
1867 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1868 $first = true;
1870 if ( $wgContLang->isRTL() ) {
1871 $s .= '<span dir="LTR">';
1874 foreach ( $a as $l ) {
1875 if ( !$first ) {
1876 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1879 $first = false;
1881 $nt = Title::newFromText( $l );
1882 $url = $nt->escapeFullURL();
1883 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1884 $title = htmlspecialchars( $nt->getText() );
1886 if ( $text == '' ) {
1887 $text = $l;
1890 $style = $this->getExternalLinkAttributes();
1891 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
1894 if ( $wgContLang->isRTL() ) {
1895 $s .= '</span>';
1898 return $s;
1901 function talkLink() {
1902 if ( NS_SPECIAL == $this->mTitle->getNamespace() ) {
1903 # No discussion links for special pages
1904 return '';
1907 $linkOptions = array();
1909 if ( $this->mTitle->isTalkPage() ) {
1910 $link = $this->mTitle->getSubjectPage();
1911 switch( $link->getNamespace() ) {
1912 case NS_MAIN:
1913 $text = wfMsg( 'articlepage' );
1914 break;
1915 case NS_USER:
1916 $text = wfMsg( 'userpage' );
1917 break;
1918 case NS_PROJECT:
1919 $text = wfMsg( 'projectpage' );
1920 break;
1921 case NS_FILE:
1922 $text = wfMsg( 'imagepage' );
1923 # Make link known if image exists, even if the desc. page doesn't.
1924 if ( wfFindFile( $link ) )
1925 $linkOptions[] = 'known';
1926 break;
1927 case NS_MEDIAWIKI:
1928 $text = wfMsg( 'mediawikipage' );
1929 break;
1930 case NS_TEMPLATE:
1931 $text = wfMsg( 'templatepage' );
1932 break;
1933 case NS_HELP:
1934 $text = wfMsg( 'viewhelppage' );
1935 break;
1936 case NS_CATEGORY:
1937 $text = wfMsg( 'categorypage' );
1938 break;
1939 default:
1940 $text = wfMsg( 'articlepage' );
1942 } else {
1943 $link = $this->mTitle->getTalkPage();
1944 $text = wfMsg( 'talkpage' );
1947 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1949 return $s;
1952 function commentLink() {
1953 global $wgOut;
1955 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
1956 return '';
1959 # __NEWSECTIONLINK___ changes behaviour here
1960 # If it is present, the link points to this page, otherwise
1961 # it points to the talk page
1962 if ( $this->mTitle->isTalkPage() ) {
1963 $title = $this->mTitle;
1964 } elseif ( $wgOut->showNewSectionLink() ) {
1965 $title = $this->mTitle;
1966 } else {
1967 $title = $this->mTitle->getTalkPage();
1970 return $this->link(
1971 $title,
1972 wfMsg( 'postcomment' ),
1973 array(),
1974 array(
1975 'action' => 'edit',
1976 'section' => 'new'
1978 array( 'known', 'noclasses' )
1982 function getUploadLink() {
1983 global $wgUploadNavigationUrl;
1985 if ( $wgUploadNavigationUrl ) {
1986 # Using an empty class attribute to avoid automatic setting of "external" class
1987 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '' ) );
1988 } else {
1989 return $this->link(
1990 SpecialPage::getTitleFor( 'Upload' ),
1991 wfMsgHtml( 'upload' ),
1992 array(),
1993 array(),
1994 array( 'known', 'noclasses' )
1999 /* these are used extensively in SkinTemplate, but also some other places */
2000 static function makeMainPageUrl( $urlaction = '' ) {
2001 $title = Title::newMainPage();
2002 self::checkTitle( $title, '' );
2004 return $title->getLocalURL( $urlaction );
2007 static function makeSpecialUrl( $name, $urlaction = '' ) {
2008 $title = SpecialPage::getTitleFor( $name );
2009 return $title->getLocalURL( $urlaction );
2012 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2013 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
2014 return $title->getLocalURL( $urlaction );
2017 static function makeI18nUrl( $name, $urlaction = '' ) {
2018 $title = Title::newFromText( wfMsgForContent( $name ) );
2019 self::checkTitle( $title, $name );
2020 return $title->getLocalURL( $urlaction );
2023 static function makeUrl( $name, $urlaction = '' ) {
2024 $title = Title::newFromText( $name );
2025 self::checkTitle( $title, $name );
2027 return $title->getLocalURL( $urlaction );
2031 * If url string starts with http, consider as external URL, else
2032 * internal
2034 static function makeInternalOrExternalUrl( $name ) {
2035 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2036 return $name;
2037 } else {
2038 return self::makeUrl( $name );
2042 # this can be passed the NS number as defined in Language.php
2043 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
2044 $title = Title::makeTitleSafe( $namespace, $name );
2045 self::checkTitle( $title, $name );
2047 return $title->getLocalURL( $urlaction );
2050 /* these return an array with the 'href' and boolean 'exists' */
2051 static function makeUrlDetails( $name, $urlaction = '' ) {
2052 $title = Title::newFromText( $name );
2053 self::checkTitle( $title, $name );
2055 return array(
2056 'href' => $title->getLocalURL( $urlaction ),
2057 'exists' => $title->getArticleID() != 0,
2062 * Make URL details where the article exists (or at least it's convenient to think so)
2064 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2065 $title = Title::newFromText( $name );
2066 self::checkTitle( $title, $name );
2068 return array(
2069 'href' => $title->getLocalURL( $urlaction ),
2070 'exists' => true
2074 # make sure we have some title to operate on
2075 static function checkTitle( &$title, $name ) {
2076 if ( !is_object( $title ) ) {
2077 $title = Title::newFromText( $name );
2078 if ( !is_object( $title ) ) {
2079 $title = Title::newFromText( '--error: link target missing--' );
2085 * Build an array that represents the sidebar(s), the navigation bar among them
2087 * @return array
2089 function buildSidebar() {
2090 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2091 global $wgLang;
2092 wfProfileIn( __METHOD__ );
2094 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2096 if ( $wgEnableSidebarCache ) {
2097 $cachedsidebar = $parserMemc->get( $key );
2098 if ( $cachedsidebar ) {
2099 wfProfileOut( __METHOD__ );
2100 return $cachedsidebar;
2104 $bar = array();
2105 $this->addToSidebar( $bar, 'sidebar' );
2107 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2108 if ( $wgEnableSidebarCache ) {
2109 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2112 wfProfileOut( __METHOD__ );
2113 return $bar;
2116 * Add content from a sidebar system message
2117 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2119 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2121 * @param &$bar array
2122 * @param $message String
2124 function addToSidebar( &$bar, $message ) {
2125 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2129 * Add content from plain text
2130 * @since 1.17
2131 * @param &$bar array
2132 * @param $text string
2134 function addToSidebarPlain( &$bar, $text ) {
2135 $lines = explode( "\n", $text );
2136 $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.
2138 $heading = '';
2140 foreach ( $lines as $line ) {
2141 if ( strpos( $line, '*' ) !== 0 ) {
2142 continue;
2145 if ( strpos( $line, '**' ) !== 0 ) {
2146 $heading = trim( $line, '* ' );
2147 if ( !array_key_exists( $heading, $bar ) ) {
2148 $bar[$heading] = array();
2150 } else {
2151 $line = trim( $line, '* ' );
2153 if ( strpos( $line, '|' ) !== false ) { // sanity check
2154 $line = array_map( 'trim', explode( '|', $line, 2 ) );
2155 $link = wfMsgForContent( $line[0] );
2157 if ( $link == '-' ) {
2158 continue;
2161 $text = wfMsgExt( $line[1], 'parsemag' );
2163 if ( wfEmptyMsg( $line[1], $text ) ) {
2164 $text = $line[1];
2167 if ( wfEmptyMsg( $line[0], $link ) ) {
2168 $link = $line[0];
2171 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2172 $href = $link;
2173 } else {
2174 $title = Title::newFromText( $link );
2176 if ( $title ) {
2177 $title = $title->fixSpecialName();
2178 $href = $title->getLocalURL();
2179 } else {
2180 $href = 'INVALID-TITLE';
2184 $bar[$heading][] = array(
2185 'text' => $text,
2186 'href' => $href,
2187 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2188 'active' => false
2190 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
2191 global $wgParser, $wgTitle;
2193 $line = substr( $line, 2, strlen( $line ) - 4 );
2195 $options = new ParserOptions();
2196 $options->setEditSection( false );
2197 $options->setInterfaceMessage( true );
2198 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $options )->getText();
2199 } else {
2200 continue;
2205 if ( count( $wikiBar ) > 0 ) {
2206 $bar = array_merge( $bar, $wikiBar );
2209 return $bar;
2213 * Should we include common/wikiprintable.css? Skins that have their own
2214 * print stylesheet should override this and return false. (This is an
2215 * ugly hack to get Monobook to play nicely with
2216 * OutputPage::headElement().)
2218 * @return bool
2220 public function commonPrintStylesheet() {
2221 return true;
2225 * Gets new talk page messages for the current user.
2226 * @return MediaWiki message or if no new talk page messages, nothing
2228 function getNewtalks() {
2229 global $wgUser, $wgOut;
2231 $newtalks = $wgUser->getNewMessageLinks();
2232 $ntl = '';
2234 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2235 $userTitle = $this->mUser->getUserPage();
2236 $userTalkTitle = $userTitle->getTalkPage();
2238 if ( !$userTalkTitle->equals( $this->mTitle ) ) {
2239 $newMessagesLink = $this->link(
2240 $userTalkTitle,
2241 wfMsgHtml( 'newmessageslink' ),
2242 array(),
2243 array( 'redirect' => 'no' ),
2244 array( 'known', 'noclasses' )
2247 $newMessagesDiffLink = $this->link(
2248 $userTalkTitle,
2249 wfMsgHtml( 'newmessagesdifflink' ),
2250 array(),
2251 array( 'diff' => 'cur' ),
2252 array( 'known', 'noclasses' )
2255 $ntl = wfMsg(
2256 'youhavenewmessages',
2257 $newMessagesLink,
2258 $newMessagesDiffLink
2260 # Disable Squid cache
2261 $wgOut->setSquidMaxage( 0 );
2263 } elseif ( count( $newtalks ) ) {
2264 // _>" " for BC <= 1.16
2265 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2266 $msgs = array();
2268 foreach ( $newtalks as $newtalk ) {
2269 $msgs[] = Xml::element(
2270 'a',
2271 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2274 $parts = implode( $sep, $msgs );
2275 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2276 $wgOut->setSquidMaxage( 0 );
2279 return $ntl;