3 * @defgroup Skins Skins
6 if ( !defined( 'MEDIAWIKI' ) ) {
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.
18 class Skin
extends Linker
{
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 = '';
26 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
27 protected $skinname = 'standard';
28 // @todo Fixme: should be protected :-\
31 /** Constructor, call parent constructor */
32 function __construct() {
33 parent
::__construct();
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
60 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
62 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
66 $skinsInitialised = true;
67 wfProfileOut( __METHOD__
. '-init' );
69 return $wgValidSkinNames;
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() {
81 $usableSkins = self
::getSkinNames();
83 foreach ( $wgSkipSkins as $skip ) {
84 unset( $usableSkins[$skip] );
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.
97 static function normalizeKey( $key ) {
98 global $wgDefaultSkin;
100 $skinNames = Skin
::getSkinNames();
103 // Don't return the default immediately;
104 // in a misconfiguration we need to fall back.
105 $key = $wgDefaultSkin;
108 if ( isset( $skinNames[$key] ) ) {
112 // Older versions of the software used a numeric setting
113 // in the user preferences.
120 if ( isset( $fallback[$key] ) ) {
121 $key = $fallback[$key];
124 if ( isset( $skinNames[$key] ) ) {
126 } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
127 return $wgDefaultSkin;
134 * Factory method for loading a skin of a given type
135 * @param $key String: 'monobook', 'standard', etc.
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;
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() ) {
189 $q = $wgUser->getOption( 'quickbar', 0 );
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(
214 'type' => 'application/opensearchdescription+xml',
215 'href' => wfScript( 'opensearch_desc' ),
216 'title' => wfMsgForContent( 'opensearch-desc' ),
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() {
235 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
238 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
240 } elseif ( $this->mTitle
->isTalkPage() ) {
241 $titles[] = $this->mTitle
->getSubjectPage();
243 $titles[] = $this->mTitle
->getTalkPage();
246 $lb = new LinkBatch( $titles );
251 * Adds metadata links (Creative Commons/Dublin Core/copyright) to the HTML
253 * @param $out Object: instance of OutputPage
255 function addMetadataLinks( OutputPage
$out ) {
256 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
257 global $wgRightsPage, $wgRightsUrl;
259 if ( $out->isArticleRelated() ) {
260 # note: buggy CC software only reads first "meta" link
261 if ( $wgEnableCreativeCommonsRdf ) {
262 $out->addMetadataLink( array(
263 'title' => 'Creative Commons',
264 'type' => 'application/rdf+xml',
265 'href' => $this->mTitle
->getLocalURL( 'action=creativecommons' ) )
269 if ( $wgEnableDublinCoreRdf ) {
270 $out->addMetadataLink( array(
271 'title' => 'Dublin Core',
272 'type' => 'application/rdf+xml',
273 'href' => $this->mTitle
->getLocalURL( 'action=dublincore' ) )
278 if ( $wgRightsPage ) {
279 $copy = Title
::newFromText( $wgRightsPage );
282 $copyright = $copy->getLocalURL();
286 if ( !$copyright && $wgRightsUrl ) {
287 $copyright = $wgRightsUrl;
291 $out->addLink( array(
292 'rel' => 'copyright',
293 'href' => $copyright )
299 * Set some local variables
301 protected function setMembers() {
303 $this->mUser
= $wgUser;
304 $this->userpage
= $wgUser->getUserPage()->getPrefixedText();
305 $this->usercss
= false;
310 * @param $t Title object to use
312 public function setTitle( $t ) {
317 public function getTitle() {
318 return $this->mTitle
;
322 * Outputs the HTML generated by other functions.
323 * @param $out Object: instance of OutputPage
325 function outputPage( OutputPage
$out ) {
326 global $wgDebugComments;
327 wfProfileIn( __METHOD__
);
330 $this->initPage( $out );
332 // See self::afterContentHook() for documentation
333 $afterContent = $this->afterContentHook();
335 $out->out( $out->headElement( $this ) );
337 if ( $wgDebugComments ) {
338 $out->out( "<!-- Wiki debugging output:\n" .
339 $out->mDebugtext
. "-->\n" );
342 $out->out( $this->beforeContent() );
344 $out->out( $out->mBodytext
. "\n" );
346 $out->out( $this->afterContent() );
348 $out->out( $afterContent );
350 $out->out( $this->bottomScripts( $out ) );
352 $out->out( wfReportTime() );
354 $out->out( "\n</body></html>" );
355 wfProfileOut( __METHOD__
);
358 static function makeVariablesScript( $data ) {
360 return Html
::inlineScript( 'mediaWiki.config.set(' . FormatJson
::encode( $data ) . ');' );
367 * Make a <script> tag containing global variables
368 * @param $skinName string Name of the skin
369 * The odd calling convention is for backwards compatibility
370 * @todo FIXME: Make this not depend on $wgTitle!
372 * Do not add things here which can be evaluated in ResourceLoaderStartupScript - in other words, without state.
373 * You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes.
375 static function makeGlobalVariablesScript( $skinName ) {
376 global $wgTitle, $wgUser, $wgRequest, $wgArticle, $wgOut, $wgRestrictionTypes;
378 $ns = $wgTitle->getNamespace();
379 $nsname = MWNamespace
::exists( $ns ) ? MWNamespace
::getCanonicalName( $ns ) : $wgTitle->getNsText();
381 'wgCanonicalNamespace' => $nsname,
382 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
383 SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
384 'wgNamespaceNumber' => $wgTitle->getNamespace(),
385 'wgPageName' => $wgTitle->getPrefixedDBKey(),
386 'wgTitle' => $wgTitle->getText(),
387 'wgAction' => $wgRequest->getText( 'action', 'view' ),
388 'wgArticleId' => $wgTitle->getArticleId(),
389 'wgIsArticle' => $wgOut->isArticle(),
390 'wgUserName' => $wgUser->isAnon() ?
null : $wgUser->getName(),
391 'wgUserGroups' => $wgUser->getEffectiveGroups(),
392 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
393 'wgCategories' => $wgOut->getCategories(),
395 foreach ( $wgRestrictionTypes as $type ) {
396 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
399 // Allow extensions to add their custom variables to the global JS variables
400 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
402 return self
::makeVariablesScript( $vars );
406 * To make it harder for someone to slip a user a fake
407 * user-JavaScript or user-CSS preview, a random token
408 * is associated with the login session. If it's not
409 * passed back with the preview request, we won't render
412 * @param $action String: 'edit', 'submit' etc.
415 public function userCanPreview( $action ) {
416 global $wgRequest, $wgUser;
418 if ( $action != 'submit' ) {
421 if ( !$wgRequest->wasPosted() ) {
424 if ( !$this->mTitle
->userCanEditCssSubpage() ) {
427 if ( !$this->mTitle
->userCanEditJsSubpage() ) {
431 return $wgUser->matchEditToken(
432 $wgRequest->getVal( 'wpEditToken' ) );
436 * Generated JavaScript action=raw&gen=js
437 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
438 * nated together. For some bizarre reason, it does *not* return any
439 * custom user JS from subpages. Huh?
441 * There's absolutely no reason to have separate Monobook/Common JSes.
442 * Any JS that cares can just check the skin variable generated at the
443 * top. For now Monobook.js will be maintained, but it should be consi-
446 * @param $skinName String: If set, overrides the skin name
449 public function generateUserJs( $skinName = null ) {
451 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
457 * Generate user stylesheet for action=raw&gen=css
459 public function generateUserStylesheet() {
461 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
467 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
468 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
470 protected function reallyGenerateUserStylesheet() {
472 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
480 function setupUserCss( OutputPage
$out ) {
481 global $wgRequest, $wgUser;
482 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs, $wgSquidMaxage;
484 wfProfileIn( __METHOD__
);
486 $this->setupSkinUserCss( $out );
490 'maxage' => $wgSquidMaxage,
493 // Add any extension CSS
494 foreach ( $out->getExtStyle() as $url ) {
495 $out->addStyle( $url );
498 // Per-site custom styles
499 if ( $wgUseSiteCss ) {
500 $out->addModuleStyles( 'site' );
503 // Per-user custom styles
504 if ( $wgAllowUserCss ) {
505 if ( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
506 // @FIXME: properly escape the cdata!
507 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
509 $out->addModuleStyles( 'user' );
513 // Per-user preference styles
514 if ( $wgAllowUserCssPrefs ) {
515 $out->addModuleStyles( 'user.preferences' );
518 wfProfileOut( __METHOD__
);
522 * Get the query to generate a dynamic stylesheet
526 public static function getDynamicStylesheetQuery() {
527 global $wgSquidMaxage;
531 'maxage' => $wgSquidMaxage,
532 'usemsgcache' => 'yes',
533 'ctype' => 'text/css',
534 'smaxage' => $wgSquidMaxage,
539 * Add skin specific stylesheets
540 * @param $out OutputPage
542 function setupSkinUserCss( OutputPage
$out ) {
543 $out->addModuleStyles( 'mediawiki.legacy.shared' );
544 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
545 // TODO: When converting old skins to use ResourceLoader (or removing them) the following should be reconsidered
546 $out->addStyle( $this->getStylesheet() );
547 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
550 function getPageClasses( $title ) {
551 $numeric = 'ns-' . $title->getNamespace();
553 if ( $title->getNamespace() == NS_SPECIAL
) {
554 $type = 'ns-special';
555 } elseif ( $title->isTalkPage() ) {
558 $type = 'ns-subject';
561 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
563 return "$numeric $type $name";
575 * This will be called immediately after the <body> tag. Split into
576 * two functions to make it easier to subclass.
578 function beforeContent() {
579 return $this->doBeforeContent();
582 function doBeforeContent() {
584 wfProfileIn( __METHOD__
);
587 $qb = $this->qbSetting();
589 $langlinks = $this->otherLanguages();
596 $borderhack = 'class="top"';
599 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
600 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
602 $shove = ( $qb != 0 );
603 $left = ( $qb == 1 ||
$qb == 3 );
605 if ( $wgContLang->isRTL() ) {
610 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
611 $this->logoText() . '</td>';
613 $s .= $this->getQuickbarCompensator( $rows );
616 $l = $wgContLang->alignStart();
617 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
619 $s .= $this->topLinks();
620 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
622 $r = $wgContLang->alignEnd();
623 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
624 $s .= $this->nameAndLogin();
625 $s .= "\n<br />" . $this->searchForm() . '</td>';
628 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
631 if ( $shove && !$left ) { # Right
632 $s .= $this->getQuickbarCompensator( $rows );
635 $s .= "</tr>\n</table>\n</div>\n";
636 $s .= "\n<div id='article'>\n";
638 $notice = wfGetSiteNotice();
641 $s .= "\n<div id='siteNotice'>$notice</div>\n";
643 $s .= $this->pageTitle();
644 $s .= $this->pageSubtitle();
645 $s .= $this->getCategories();
647 wfProfileOut( __METHOD__
);
651 function getCategoryLinks() {
652 global $wgOut, $wgUseCategoryBrowser;
653 global $wgContLang, $wgUser;
655 if ( count( $wgOut->mCategoryLinks
) == 0 ) {
660 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
662 // Use Unicode bidi embedding override characters,
663 // to make sure links don't smash each other up in ugly ways.
664 $dir = $wgContLang->getDir();
665 $embed = "<span dir='$dir'>";
668 $allCats = $wgOut->getCategoryLinks();
670 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
672 if ( !empty( $allCats['normal'] ) ) {
673 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
675 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
676 $s .= '<div id="mw-normal-catlinks">' .
677 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
678 . $colon . $t . '</div>';
682 if ( isset( $allCats['hidden'] ) ) {
683 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
684 $class = 'mw-hidden-cats-user-shown';
685 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
686 $class = 'mw-hidden-cats-ns-shown';
688 $class = 'mw-hidden-cats-hidden';
691 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
692 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
693 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
697 # optional 'dmoz-like' category browser. Will be shown under the list
698 # of categories an article belong to
699 if ( $wgUseCategoryBrowser ) {
700 $s .= '<br /><hr />';
702 # get a big array of the parents tree
703 $parenttree = $this->mTitle
->getParentCategoryTree();
704 # Skin object passed by reference cause it can not be
705 # accessed under the method subfunction drawCategoryBrowser
706 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
707 # Clean out bogus first entry and sort them
708 unset( $tempout[0] );
710 # Output one per line
711 $s .= implode( "<br />\n", $tempout );
718 * Render the array as a serie of links.
719 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
720 * @param &skin Object: skin passed by reference
721 * @return String separated by >, terminate with "\n"
723 function drawCategoryBrowser( $tree, &$skin ) {
726 foreach ( $tree as $element => $parent ) {
727 if ( empty( $parent ) ) {
728 # element start a new list
731 # grab the others elements
732 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' > ';
735 # add our current element to the list
736 $eltitle = Title
::newFromText( $element );
737 $return .= $skin->link( $eltitle, $eltitle->getText() );
743 function getCategories() {
744 $catlinks = $this->getCategoryLinks();
746 $classes = 'catlinks';
748 global $wgOut, $wgUser;
750 // Check what we're showing
751 $allCats = $wgOut->getCategoryLinks();
752 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
753 $this->mTitle
->getNamespace() == NS_CATEGORY
;
755 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
756 $classes .= ' catlinks-allhidden';
759 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
762 function getQuickbarCompensator( $rows = 1 ) {
763 return "<td width='152' rowspan='{$rows}'> </td>";
767 * This runs a hook to allow extensions placing their stuff after content
768 * and article metadata (e.g. categories).
769 * Note: This function has nothing to do with afterContent().
771 * This hook is placed here in order to allow using the same hook for all
772 * skins, both the SkinTemplate based ones and the older ones, which directly
773 * use this class to get their data.
775 * The output of this function gets processed in SkinTemplate::outputPage() for
776 * the SkinTemplate based skins, all other skins should directly echo it.
778 * Returns an empty string by default, if not changed by any hook function.
780 protected function afterContentHook() {
783 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
784 // adding just some spaces shouldn't toggle the output
785 // of the whole <div/>, so we use trim() here
786 if ( trim( $data ) != '' ) {
787 // Doing this here instead of in the skins to
788 // ensure that the div has the same ID in all
790 $data = "<div id='mw-data-after-content'>\n" .
795 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
802 * Generate debug data HTML for displaying at the bottom of the main content
804 * @return String HTML containing debug data, if enabled (otherwise empty).
806 protected function generateDebugHTML() {
807 global $wgShowDebug, $wgOut;
809 if ( $wgShowDebug ) {
810 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext
);
811 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
812 $listInternals . "</ul>\n";
818 private function formatDebugHTML( $debugText ) {
819 $lines = explode( "\n", $debugText );
823 foreach ( $lines as $line ) {
825 $display = ltrim( $line );
826 $ident = strlen( $line ) - strlen( $display );
827 $diff = $ident - $curIdent;
829 if ( $display == '' ) {
830 $display = "\xc2\xa0";
833 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
836 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
838 $display = htmlspecialchars( $display );
842 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
843 } elseif ( $diff == 0 ) {
844 $ret .= "</li><li>\n";
846 $ret .= str_repeat( "<ul><li>\n", $diff );
848 $ret .= $display . "\n";
853 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
859 * This gets called shortly before the </body> tag.
860 * @return String HTML to be put before </body>
862 function afterContent() {
863 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
864 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
868 * This gets called shortly before the </body> tag.
869 * @param $out OutputPage object
870 * @return String HTML-wrapped JS code to be put before </body>
872 function bottomScripts( $out ) {
873 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
874 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
876 return $bottomScriptText;
879 /** @return string Retrievied from HTML text */
880 function printSource() {
881 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
882 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
885 function printFooter() {
886 return "<p>" . $this->printSource() .
887 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
890 /** overloaded by derived classes */
891 function doAfterContent() {
892 return '</div></div>';
895 function pageTitleLinks() {
896 global $wgOut, $wgUser, $wgRequest, $wgLang;
898 $oldid = $wgRequest->getVal( 'oldid' );
899 $diff = $wgRequest->getVal( 'diff' );
900 $action = $wgRequest->getText( 'action' );
902 $s[] = $this->printableLink();
903 $disclaimer = $this->disclaimerLink(); # may be empty
909 $privacy = $this->privacyLink(); # may be empty too
915 if ( $wgOut->isArticleRelated() ) {
916 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
917 $name = $this->mTitle
->getDBkey();
918 $image = wfFindFile( $this->mTitle
);
921 $link = htmlspecialchars( $image->getURL() );
922 $style = $this->getInternalLinkAttributes( $link, $name );
923 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
928 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
931 wfMsg( 'currentrev' ),
934 array( 'known', 'noclasses' )
938 if ( $wgUser->getNewtalk() ) {
939 # do not show "You have new messages" text when we are viewing our
941 if ( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
943 $wgUser->getTalkPage(),
944 wfMsgHtml( 'newmessageslink' ),
946 array( 'redirect' => 'no' ),
947 array( 'known', 'noclasses' )
951 $wgUser->getTalkPage(),
952 wfMsgHtml( 'newmessagesdifflink' ),
954 array( 'diff' => 'cur' ),
955 array( 'known', 'noclasses' )
957 $s[] = '<strong>' . wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
959 $wgOut->setSquidMaxage( 0 );
960 $wgOut->enableClientCache( false );
964 $undelete = $this->getUndeleteLink();
966 if ( !empty( $undelete ) ) {
970 return $wgLang->pipeList( $s );
973 function getUndeleteLink() {
974 global $wgUser, $wgLang, $wgRequest;
976 $action = $wgRequest->getVal( 'action', 'view' );
978 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
979 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
980 $n = $this->mTitle
->isDeleted();
983 if ( $wgUser->isAllowed( 'undelete' ) ) {
984 $msg = 'thisisdeleted';
986 $msg = 'viewdeleted';
992 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
993 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
996 array( 'known', 'noclasses' )
1005 function printableLink() {
1006 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1010 if ( !$wgOut->isPrintable() ) {
1011 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1012 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1015 if ( $wgOut->isSyndicated() ) {
1016 foreach ( $wgFeedClasses as $format => $class ) {
1017 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1018 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1019 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1022 return $wgLang->pipeList( $s );
1026 * Gets the h1 element with the page title.
1029 function pageTitle() {
1031 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1035 function pageSubtitle() {
1038 $sub = $wgOut->getSubtitle();
1041 global $wgExtraSubtitle;
1042 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1045 $subpages = $this->subPageSubtitle();
1046 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1047 $s = "<p class='subtitle'>{$sub}</p>\n";
1052 function subPageSubtitle() {
1055 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) ) {
1061 if ( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1062 $ptext = $this->mTitle
->getPrefixedText();
1063 if ( preg_match( '/\//', $ptext ) ) {
1064 $links = explode( '/', $ptext );
1065 array_pop( $links );
1070 foreach ( $links as $link ) {
1071 $growinglink .= $link;
1073 $linkObj = Title
::newFromText( $growinglink );
1075 if ( is_object( $linkObj ) && $linkObj->exists() ) {
1076 $getlink = $this->link(
1078 htmlspecialchars( $display ),
1081 array( 'known', 'noclasses' )
1087 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1089 $subpages .= '< ';
1092 $subpages .= $getlink;
1097 $growinglink .= '/';
1106 * Returns true if the IP should be shown in the header
1108 function showIPinHeader() {
1109 global $wgShowIPinHeader;
1110 return $wgShowIPinHeader && session_id() != '';
1113 function nameAndLogin() {
1114 global $wgUser, $wgLang, $wgContLang;
1116 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1120 if ( $wgUser->isAnon() ) {
1121 if ( $this->showIPinHeader() ) {
1124 $talkLink = $this->link( $wgUser->getTalkPage(),
1125 $wgLang->getNsText( NS_TALK
) );
1127 $ret .= "$name ($talkLink)";
1129 $ret .= wfMsg( 'notloggedin' );
1132 $returnTo = $this->mTitle
->getPrefixedDBkey();
1135 if ( $logoutPage != $returnTo ) {
1136 $query['returnto'] = $returnTo;
1139 $loginlink = $wgUser->isAllowed( 'createaccount' )
1140 ?
'nav-login-createaccount'
1142 $ret .= "\n<br />" . $this->link(
1143 SpecialPage
::getTitleFor( 'Userlogin' ),
1144 wfMsg( $loginlink ), array(), $query
1147 $returnTo = $this->mTitle
->getPrefixedDBkey();
1148 $talkLink = $this->link( $wgUser->getTalkPage(),
1149 $wgLang->getNsText( NS_TALK
) );
1151 $ret .= $this->link( $wgUser->getUserPage(),
1152 htmlspecialchars( $wgUser->getName() ) );
1153 $ret .= " ($talkLink)<br />";
1154 $ret .= $wgLang->pipeList( array(
1156 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1157 array(), array( 'returnto' => $returnTo )
1159 $this->specialLink( 'preferences' ),
1163 $ret = $wgLang->pipeList( array(
1166 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1174 function getSearchLink() {
1175 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1176 return $searchPage->getLocalURL();
1179 function escapeSearchLink() {
1180 return htmlspecialchars( $this->getSearchLink() );
1183 function searchForm() {
1184 global $wgRequest, $wgUseTwoButtonsSearchForm;
1186 $search = $wgRequest->getText( 'search' );
1188 $s = '<form id="searchform' . $this->searchboxes
. '" name="search" class="inline" method="post" action="'
1189 . $this->escapeSearchLink() . "\">\n"
1190 . '<input type="text" id="searchInput' . $this->searchboxes
. '" name="search" size="19" value="'
1191 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1192 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1194 if ( $wgUseTwoButtonsSearchForm ) {
1195 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1197 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1202 // Ensure unique id's for search boxes made after the first
1203 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1208 function topLinks() {
1212 $this->mainPageLink(),
1213 $this->specialLink( 'recentchanges' )
1216 if ( $wgOut->isArticleRelated() ) {
1217 $s[] = $this->editThisPage();
1218 $s[] = $this->historyLink();
1221 # Many people don't like this dropdown box
1222 # $s[] = $this->specialPagesList();
1224 if ( $this->variantLinks() ) {
1225 $s[] = $this->variantLinks();
1228 if ( $this->extensionTabLinks() ) {
1229 $s[] = $this->extensionTabLinks();
1232 // @todo FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1233 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1237 * Compatibility for extensions adding functionality through tabs.
1238 * Eventually these old skins should be replaced with SkinTemplate-based
1242 function extensionTabLinks() {
1246 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1247 foreach ( $tabs as $tab ) {
1248 $s[] = Xml
::element( 'a',
1249 array( 'href' => $tab['href'] ),
1253 if ( count( $s ) ) {
1256 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1257 $out .= $wgLang->pipeList( $s );
1264 * Language/charset variant links for classic-style skins
1267 function variantLinks() {
1270 /* show links to different language variants */
1271 global $wgDisableLangConversion, $wgLang, $wgContLang;
1273 $variants = $wgContLang->getVariants();
1275 if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1276 foreach ( $variants as $code ) {
1277 $varname = $wgContLang->getVariantname( $code );
1279 if ( $varname == 'disable' ) {
1282 $s = $wgLang->pipeList( array(
1284 '<a href="' . $this->mTitle
->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1292 function bottomLinks() {
1293 global $wgOut, $wgUser, $wgUseTrackbacks;
1294 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1297 if ( $wgOut->isArticleRelated() ) {
1298 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1300 if ( $wgUser->isLoggedIn() ) {
1301 $element[] = $this->watchThisPage();
1304 $element[] = $this->talkLink();
1305 $element[] = $this->historyLink();
1306 $element[] = $this->whatLinksHere();
1307 $element[] = $this->watchPageLinksLink();
1309 if ( $wgUseTrackbacks ) {
1310 $element[] = $this->trackbackLink();
1314 $this->mTitle
->getNamespace() == NS_USER ||
1315 $this->mTitle
->getNamespace() == NS_USER_TALK
1317 $id = User
::idFromName( $this->mTitle
->getText() );
1318 $ip = User
::isIP( $this->mTitle
->getText() );
1320 # Both anons and non-anons have contributions list
1322 $element[] = $this->userContribsLink();
1325 if ( $this->showEmailUser( $id ) ) {
1326 $element[] = $this->emailUserLink();
1330 $s = implode( $element, $sep );
1332 if ( $this->mTitle
->getArticleId() ) {
1335 // Delete/protect/move links for privileged users
1336 if ( $wgUser->isAllowed( 'delete' ) ) {
1337 $s .= $this->deleteThisPage();
1340 if ( $wgUser->isAllowed( 'protect' ) ) {
1341 $s .= $sep . $this->protectThisPage();
1344 if ( $wgUser->isAllowed( 'move' ) ) {
1345 $s .= $sep . $this->moveThisPage();
1349 $s .= "<br />\n" . $this->otherLanguages();
1355 function pageStats() {
1356 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1357 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1359 $oldid = $wgRequest->getVal( 'oldid' );
1360 $diff = $wgRequest->getVal( 'diff' );
1362 if ( !$wgOut->isArticle() ) {
1366 if ( !$wgArticle instanceof Article
) {
1370 if ( isset( $oldid ) ||
isset( $diff ) ) {
1374 if ( 0 == $wgArticle->getID() ) {
1380 if ( !$wgDisableCounters ) {
1381 $count = $wgLang->formatNum( $wgArticle->getCount() );
1384 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1388 if ( $wgMaxCredits != 0 ) {
1389 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1391 $s .= $this->lastModified();
1394 if ( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1395 $dbr = wfGetDB( DB_SLAVE
);
1396 $res = $dbr->select(
1398 array( 'COUNT(*) AS n' ),
1400 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ),
1401 'wl_namespace' => $this->mTitle
->getNamespace()
1405 $x = $dbr->fetchObject( $res );
1407 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1408 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1412 return $s . ' ' . $this->getCopyright();
1415 function getCopyright( $type = 'detect' ) {
1416 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1418 if ( $type == 'detect' ) {
1419 $diff = $wgRequest->getVal( 'diff' );
1420 $isCur = $wgArticle && $wgArticle->isCurrent();
1422 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1429 if ( $type == 'history' ) {
1430 $msg = 'history_copyright';
1437 if ( $wgRightsPage ) {
1438 $title = Title
::newFromText( $wgRightsPage );
1439 $link = $this->linkKnown( $title, $wgRightsText );
1440 } elseif ( $wgRightsUrl ) {
1441 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1442 } elseif ( $wgRightsText ) {
1443 $link = $wgRightsText;
1449 // Allow for site and per-namespace customization of copyright notice.
1452 if ( isset( $wgArticle ) ) {
1453 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link, &$forContent ) );
1456 if ( $forContent ) {
1457 $out .= wfMsgForContent( $msg, $link );
1459 $out .= wfMsg( $msg, $link );
1465 function getCopyrightIcon() {
1466 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1470 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1471 $out = $wgCopyrightIcon;
1472 } elseif ( $wgRightsIcon ) {
1473 $icon = htmlspecialchars( $wgRightsIcon );
1475 if ( $wgRightsUrl ) {
1476 $url = htmlspecialchars( $wgRightsUrl );
1477 $out .= '<a href="' . $url . '">';
1480 $text = htmlspecialchars( $wgRightsText );
1481 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1483 if ( $wgRightsUrl ) {
1492 * Gets the powered by MediaWiki icon.
1495 function getPoweredBy() {
1496 global $wgStylePath;
1498 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1499 $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1504 function lastModified() {
1505 global $wgLang, $wgArticle;
1507 if ( $this->mRevisionId
&& $this->mRevisionId
!= $wgArticle->getLatest() ) {
1508 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1510 $timestamp = $wgArticle->getTimestamp();
1514 $d = $wgLang->date( $timestamp, true );
1515 $t = $wgLang->time( $timestamp, true );
1516 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1521 if ( wfGetLB()->getLaggedSlaveMode() ) {
1522 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1528 function logoText( $align = '' ) {
1529 if ( $align != '' ) {
1530 $a = " align='{$align}'";
1535 $mp = wfMsg( 'mainpage' );
1536 $mptitle = Title
::newMainPage();
1537 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1539 $logourl = $this->getLogo();
1540 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1546 * Show a drop-down box of special pages
1548 function specialPagesList() {
1549 global $wgContLang, $wgServer, $wgRedirectScript;
1551 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1553 foreach ( $pages as $name => $page ) {
1554 $pages[$name] = $page->getDescription();
1557 $go = wfMsg( 'go' );
1558 $sp = wfMsg( 'specialpages' );
1559 $spp = $wgContLang->specialPage( 'Specialpages' );
1561 $s = '<form id="specialpages" method="get" ' .
1562 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1563 $s .= "<select name=\"wpDropdown\">\n";
1564 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1567 foreach ( $pages as $name => $desc ) {
1568 $p = $wgContLang->specialPage( $name );
1569 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1572 $s .= "</select>\n";
1573 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1580 * Gets the link to the wiki's main page.
1583 function mainPageLink() {
1585 Title
::newMainPage(),
1586 wfMsg( 'mainpage' ),
1589 array( 'known', 'noclasses' )
1595 private function footerLink( $desc, $page ) {
1596 // if the link description has been set to "-" in the default language,
1597 if ( wfMsgForContent( $desc ) == '-' ) {
1598 // then it is disabled, for all languages.
1601 // Otherwise, we display the link for the user, described in their
1602 // language (which may or may not be the same as the default language),
1603 // but we make the link target be the one site-wide page.
1604 $title = Title
::newFromText( wfMsgForContent( $page ) );
1606 return $this->linkKnown(
1608 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1614 * Gets the link to the wiki's privacy policy page.
1616 function privacyLink() {
1617 return $this->footerLink( 'privacy', 'privacypage' );
1621 * Gets the link to the wiki's about page.
1623 function aboutLink() {
1624 return $this->footerLink( 'aboutsite', 'aboutpage' );
1628 * Gets the link to the wiki's general disclaimers page.
1630 function disclaimerLink() {
1631 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1634 function editThisPage() {
1637 if ( !$wgOut->isArticleRelated() ) {
1638 $s = wfMsg( 'protectedpage' );
1640 if ( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1641 $t = wfMsg( 'editthispage' );
1642 } elseif ( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1643 $t = wfMsg( 'create-this-page' );
1645 $t = wfMsg( 'viewsource' );
1652 $this->editUrlOptions(),
1653 array( 'known', 'noclasses' )
1661 * Return URL options for the 'edit page' link.
1662 * This may include an 'oldid' specifier, if the current page view is such.
1667 function editUrlOptions() {
1670 $options = array( 'action' => 'edit' );
1672 if ( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1673 $options['oldid'] = intval( $this->mRevisionId
);
1679 function deleteThisPage() {
1680 global $wgUser, $wgRequest;
1682 $diff = $wgRequest->getVal( 'diff' );
1684 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1685 $t = wfMsg( 'deletethispage' );
1691 array( 'action' => 'delete' ),
1692 array( 'known', 'noclasses' )
1701 function protectThisPage() {
1702 global $wgUser, $wgRequest;
1704 $diff = $wgRequest->getVal( 'diff' );
1706 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
1707 if ( $this->mTitle
->isProtected() ) {
1708 $text = wfMsg( 'unprotectthispage' );
1709 $query = array( 'action' => 'unprotect' );
1711 $text = wfMsg( 'protectthispage' );
1712 $query = array( 'action' => 'protect' );
1720 array( 'known', 'noclasses' )
1729 function watchThisPage() {
1731 ++
$this->mWatchLinkNum
;
1733 if ( $wgOut->isArticleRelated() ) {
1734 if ( $this->mTitle
->userIsWatching() ) {
1735 $text = wfMsg( 'unwatchthispage' );
1736 $query = array( 'action' => 'unwatch' );
1737 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1739 $text = wfMsg( 'watchthispage' );
1740 $query = array( 'action' => 'watch' );
1741 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1747 array( 'id' => $id ),
1749 array( 'known', 'noclasses' )
1752 $s = wfMsg( 'notanarticle' );
1758 function moveThisPage() {
1759 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1761 SpecialPage
::getTitleFor( 'Movepage' ),
1762 wfMsg( 'movethispage' ),
1764 array( 'target' => $this->mTitle
->getPrefixedDBkey() ),
1765 array( 'known', 'noclasses' )
1768 // no message if page is protected - would be redundant
1773 function historyLink() {
1776 wfMsgHtml( 'history' ),
1777 array( 'rel' => 'archives' ),
1778 array( 'action' => 'history' )
1782 function whatLinksHere() {
1784 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1785 wfMsgHtml( 'whatlinkshere' ),
1788 array( 'known', 'noclasses' )
1792 function userContribsLink() {
1794 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1795 wfMsgHtml( 'contributions' ),
1798 array( 'known', 'noclasses' )
1802 function showEmailUser( $id ) {
1804 $targetUser = User
::newFromId( $id );
1805 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1806 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1809 function emailUserLink() {
1811 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1812 wfMsg( 'emailuser' ),
1815 array( 'known', 'noclasses' )
1819 function watchPageLinksLink() {
1822 if ( !$wgOut->isArticleRelated() ) {
1823 return '(' . wfMsg( 'notanarticle' ) . ')';
1826 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1827 wfMsg( 'recentchangeslinked-toolbox' ),
1830 array( 'known', 'noclasses' )
1835 function trackbackLink() {
1836 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1837 . wfMsg( 'trackbacklink' ) . '</a>';
1840 function otherLanguages() {
1841 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1843 if ( $wgHideInterlanguageLinks ) {
1847 $a = $wgOut->getLanguageLinks();
1849 if ( 0 == count( $a ) ) {
1853 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1856 if ( $wgContLang->isRTL() ) {
1857 $s .= '<span dir="LTR">';
1860 foreach ( $a as $l ) {
1862 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1867 $nt = Title
::newFromText( $l );
1868 $url = $nt->escapeFullURL();
1869 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1870 $title = htmlspecialchars( $nt->getText() );
1872 if ( $text == '' ) {
1876 $style = $this->getExternalLinkAttributes();
1877 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
1880 if ( $wgContLang->isRTL() ) {
1887 function talkLink() {
1888 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
1889 # No discussion links for special pages
1893 $linkOptions = array();
1895 if ( $this->mTitle
->isTalkPage() ) {
1896 $link = $this->mTitle
->getSubjectPage();
1897 switch( $link->getNamespace() ) {
1899 $text = wfMsg( 'articlepage' );
1902 $text = wfMsg( 'userpage' );
1905 $text = wfMsg( 'projectpage' );
1908 $text = wfMsg( 'imagepage' );
1909 # Make link known if image exists, even if the desc. page doesn't.
1910 if ( wfFindFile( $link ) )
1911 $linkOptions[] = 'known';
1914 $text = wfMsg( 'mediawikipage' );
1917 $text = wfMsg( 'templatepage' );
1920 $text = wfMsg( 'viewhelppage' );
1923 $text = wfMsg( 'categorypage' );
1926 $text = wfMsg( 'articlepage' );
1929 $link = $this->mTitle
->getTalkPage();
1930 $text = wfMsg( 'talkpage' );
1933 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1938 function commentLink() {
1941 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
1945 # __NEWSECTIONLINK___ changes behaviour here
1946 # If it is present, the link points to this page, otherwise
1947 # it points to the talk page
1948 if ( $this->mTitle
->isTalkPage() ) {
1949 $title = $this->mTitle
;
1950 } elseif ( $wgOut->showNewSectionLink() ) {
1951 $title = $this->mTitle
;
1953 $title = $this->mTitle
->getTalkPage();
1958 wfMsg( 'postcomment' ),
1964 array( 'known', 'noclasses' )
1968 function getUploadLink() {
1969 global $wgUploadNavigationUrl;
1971 if ( $wgUploadNavigationUrl ) {
1972 # Using an empty class attribute to avoid automatic setting of "external" class
1973 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '' ) );
1976 SpecialPage
::getTitleFor( 'Upload' ),
1977 wfMsgHtml( 'upload' ),
1980 array( 'known', 'noclasses' )
1985 /* these are used extensively in SkinTemplate, but also some other places */
1986 static function makeMainPageUrl( $urlaction = '' ) {
1987 $title = Title
::newMainPage();
1988 self
::checkTitle( $title, '' );
1990 return $title->getLocalURL( $urlaction );
1993 static function makeSpecialUrl( $name, $urlaction = '' ) {
1994 $title = SpecialPage
::getTitleFor( $name );
1995 return $title->getLocalURL( $urlaction );
1998 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1999 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
2000 return $title->getLocalURL( $urlaction );
2003 static function makeI18nUrl( $name, $urlaction = '' ) {
2004 $title = Title
::newFromText( wfMsgForContent( $name ) );
2005 self
::checkTitle( $title, $name );
2006 return $title->getLocalURL( $urlaction );
2009 static function makeUrl( $name, $urlaction = '' ) {
2010 $title = Title
::newFromText( $name );
2011 self
::checkTitle( $title, $name );
2013 return $title->getLocalURL( $urlaction );
2017 * If url string starts with http, consider as external URL, else
2020 static function makeInternalOrExternalUrl( $name ) {
2021 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2024 return self
::makeUrl( $name );
2028 # this can be passed the NS number as defined in Language.php
2029 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
2030 $title = Title
::makeTitleSafe( $namespace, $name );
2031 self
::checkTitle( $title, $name );
2033 return $title->getLocalURL( $urlaction );
2036 /* these return an array with the 'href' and boolean 'exists' */
2037 static function makeUrlDetails( $name, $urlaction = '' ) {
2038 $title = Title
::newFromText( $name );
2039 self
::checkTitle( $title, $name );
2042 'href' => $title->getLocalURL( $urlaction ),
2043 'exists' => $title->getArticleID() != 0 ?
true : false
2048 * Make URL details where the article exists (or at least it's convenient to think so)
2050 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2051 $title = Title
::newFromText( $name );
2052 self
::checkTitle( $title, $name );
2055 'href' => $title->getLocalURL( $urlaction ),
2060 # make sure we have some title to operate on
2061 static function checkTitle( &$title, $name ) {
2062 if ( !is_object( $title ) ) {
2063 $title = Title
::newFromText( $name );
2064 if ( !is_object( $title ) ) {
2065 $title = Title
::newFromText( '--error: link target missing--' );
2071 * Build an array that represents the sidebar(s), the navigation bar among them
2075 function buildSidebar() {
2076 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2078 wfProfileIn( __METHOD__
);
2080 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2082 if ( $wgEnableSidebarCache ) {
2083 $cachedsidebar = $parserMemc->get( $key );
2084 if ( $cachedsidebar ) {
2085 wfProfileOut( __METHOD__
);
2086 return $cachedsidebar;
2091 $this->addToSidebar( $bar, 'sidebar' );
2093 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2094 if ( $wgEnableSidebarCache ) {
2095 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2098 wfProfileOut( __METHOD__
);
2102 * Add content from a sidebar system message
2103 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2105 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2107 * @param &$bar array
2108 * @param $message String
2110 function addToSidebar( &$bar, $message ) {
2111 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2115 * Add content from plain text
2117 * @param &$bar array
2118 * @param $text string
2120 function addToSidebarPlain( &$bar, $text ) {
2121 $lines = explode( "\n", $text );
2122 $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.
2126 foreach ( $lines as $line ) {
2127 if ( strpos( $line, '*' ) !== 0 ) {
2131 if ( strpos( $line, '**' ) !== 0 ) {
2132 $heading = trim( $line, '* ' );
2133 if ( !array_key_exists( $heading, $bar ) ) {
2134 $bar[$heading] = array();
2137 $line = trim( $line, '* ' );
2139 if ( strpos( $line, '|' ) !== false ) { // sanity check
2140 $line = array_map( 'trim', explode( '|', $line, 2 ) );
2141 $link = wfMsgForContent( $line[0] );
2143 if ( $link == '-' ) {
2147 $text = wfMsgExt( $line[1], 'parsemag' );
2149 if ( wfEmptyMsg( $line[1], $text ) ) {
2153 if ( wfEmptyMsg( $line[0], $link ) ) {
2157 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2160 $title = Title
::newFromText( $link );
2163 $title = $title->fixSpecialName();
2164 $href = $title->getLocalURL();
2166 $href = 'INVALID-TITLE';
2170 $bar[$heading][] = array(
2173 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2176 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
2177 global $wgParser, $wgTitle;
2179 $line = substr( $line, 2, strlen( $line ) - 4 );
2181 if ( is_null( $wgParser->mOptions
) ) {
2182 $wgParser->mOptions
= new ParserOptions();
2185 $wgParser->mOptions
->setEditSection( false );
2186 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $wgParser->mOptions
)->getText();
2193 if ( count( $wikiBar ) > 0 ) {
2194 $bar = array_merge( $bar, $wikiBar );
2201 * Should we include common/wikiprintable.css? Skins that have their own
2202 * print stylesheet should override this and return false. (This is an
2203 * ugly hack to get Monobook to play nicely with
2204 * OutputPage::headElement().)
2208 public function commonPrintStylesheet() {
2213 * Gets new talk page messages for the current user.
2214 * @return MediaWiki message or if no new talk page messages, nothing
2216 function getNewtalks() {
2217 global $wgUser, $wgOut;
2219 $newtalks = $wgUser->getNewMessageLinks();
2222 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2223 $userTitle = $this->mUser
->getUserPage();
2224 $userTalkTitle = $userTitle->getTalkPage();
2226 if ( !$userTalkTitle->equals( $this->mTitle
) ) {
2227 $newMessagesLink = $this->link(
2229 wfMsgHtml( 'newmessageslink' ),
2231 array( 'redirect' => 'no' ),
2232 array( 'known', 'noclasses' )
2235 $newMessagesDiffLink = $this->link(
2237 wfMsgHtml( 'newmessagesdifflink' ),
2239 array( 'diff' => 'cur' ),
2240 array( 'known', 'noclasses' )
2244 'youhavenewmessages',
2246 $newMessagesDiffLink
2248 # Disable Squid cache
2249 $wgOut->setSquidMaxage( 0 );
2251 } elseif ( count( $newtalks ) ) {
2252 // _>" " for BC <= 1.16
2253 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2256 foreach ( $newtalks as $newtalk ) {
2257 $msgs[] = Xml
::element(
2259 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2262 $parts = implode( $sep, $msgs );
2263 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2264 $wgOut->setSquidMaxage( 0 );