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, $wgEnableAPI;
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 if ( $wgEnableAPI ) {
220 # Real Simple Discovery link, provides auto-discovery information
221 # for the MediaWiki API (and potentially additional custom API
222 # support such as WordPress or Twitter-compatible APIs for a
223 # blogging extension, etc)
224 $out->addLink( array(
226 'type' => 'application/rsd+xml',
227 'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ) ),
231 $this->addMetadataLinks( $out );
233 $this->mRevisionId = $out->mRevisionId;
235 $this->preloadExistence();
237 wfProfileOut( __METHOD__ );
241 * Preload the existence of three commonly-requested pages in a single query
243 function preloadExistence() {
247 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
250 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
252 } elseif ( $this->mTitle->isTalkPage() ) {
253 $titles[] = $this->mTitle->getSubjectPage();
255 $titles[] = $this->mTitle->getTalkPage();
258 $lb = new LinkBatch( $titles );
259 $lb->setCaller( __METHOD__ );
264 * Adds metadata links below to the HTML output.
266 * <li>Creative Commons
267 * <br />See http://wiki.creativecommons.org/Extend_Metadata.
269 * <li>Dublin Core</li>
270 * <li>Use hreflang to specify canonical and alternate links
271 * <br />See http://www.google.com/support/webmasters/bin/answer.py?answer=189077
276 * @param $out Object: instance of OutputPage
278 function addMetadataLinks( OutputPage $out ) {
279 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
280 global $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang;
281 global $wgRightsPage, $wgRightsUrl;
283 if ( $out->isArticleRelated() ) {
284 # note: buggy CC software only reads first "meta" link
285 if ( $wgEnableCreativeCommonsRdf ) {
286 $out->addMetadataLink( array(
287 'title' => 'Creative Commons',
288 'type' => 'application/rdf+xml',
289 'href' => $this->mTitle->getLocalURL( 'action=creativecommons' ) )
293 if ( $wgEnableDublinCoreRdf ) {
294 $out->addMetadataLink( array(
295 'title' => 'Dublin Core',
296 'type' => 'application/rdf+xml',
297 'href' => $this->mTitle->getLocalURL( 'action=dublincore' ) )
302 if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks
303 && $wgContLang->hasVariants() ) {
305 $urlvar = $wgContLang->getURLVariant();
308 $variants = $wgContLang->getVariants();
309 foreach ( $variants as $_v ) {
310 $out->addLink( array(
311 'rel' => 'alternate',
313 'href' => $this->mTitle->getLocalURL( '', $_v ) )
317 $out->addLink( array(
318 'rel' => 'canonical',
319 'href' => $this->mTitle->getFullURL() )
325 if ( $wgRightsPage ) {
326 $copy = Title::newFromText( $wgRightsPage );
329 $copyright = $copy->getLocalURL();
333 if ( !$copyright && $wgRightsUrl ) {
334 $copyright = $wgRightsUrl;
338 $out->addLink( array(
339 'rel' => 'copyright',
340 'href' => $copyright )
346 * Set some local variables
348 protected function setMembers() {
350 $this->mUser = $wgUser;
351 $this->userpage = $wgUser->getUserPage()->getPrefixedText();
352 $this->usercss = false;
357 * @param $t Title object to use
359 public function setTitle( $t ) {
364 public function getTitle() {
365 return $this->mTitle;
369 * Outputs the HTML generated by other functions.
370 * @param $out Object: instance of OutputPage
372 function outputPage( OutputPage $out ) {
373 global $wgDebugComments;
374 wfProfileIn( __METHOD__ );
377 $this->initPage( $out );
379 // See self::afterContentHook() for documentation
380 $afterContent = $this->afterContentHook();
382 $out->out( $out->headElement( $this ) );
384 if ( $wgDebugComments ) {
385 $out->out( "<!-- Wiki debugging output:\n" .
386 $out->mDebugtext . "-->\n" );
389 $out->out( $this->beforeContent() );
391 $out->out( $out->mBodytext . "\n" );
393 $out->out( $this->afterContent() );
395 $out->out( $afterContent );
397 $out->out( $this->bottomScripts( $out ) );
399 $out->out( wfReportTime() );
401 $out->out( "\n</body></html>" );
402 wfProfileOut( __METHOD__ );
405 static function makeVariablesScript( $data ) {
407 return Html::inlineScript(
408 ResourceLoader::makeLoaderConditionalScript( ResourceLoader::makeConfigSetScript( $data ) )
416 * Make a <script> tag containing global variables
417 * @param $skinName string Name of the skin
418 * The odd calling convention is for backwards compatibility
419 * @todo FIXME: Make this not depend on $wgTitle!
421 * Do not add things here which can be evaluated in ResourceLoaderStartupScript - in other words, without state.
422 * You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes.
424 static function makeGlobalVariablesScript( $skinName ) {
425 global $wgTitle, $wgUser, $wgRequest, $wgArticle, $wgOut, $wgUseAjax, $wgEnableMWSuggest;
427 $ns = $wgTitle->getNamespace();
428 $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
430 'wgCanonicalNamespace' => $nsname,
431 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
432 SpecialPage::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
433 'wgNamespaceNumber' => $wgTitle->getNamespace(),
434 'wgPageName' => $wgTitle->getPrefixedDBKey(),
435 'wgTitle' => $wgTitle->getText(),
436 'wgAction' => $wgRequest->getText( 'action', 'view' ),
437 'wgArticleId' => $wgTitle->getArticleId(),
438 'wgIsArticle' => $wgOut->isArticle(),
439 'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(),
440 'wgUserGroups' => $wgUser->getEffectiveGroups(),
441 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
442 'wgCategories' => $wgOut->getCategories(),
443 'wgBreakFrames' => $wgOut->getFrameOptions() == 'DENY',
445 foreach ( $wgTitle->getRestrictionTypes() as $type ) {
446 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
448 if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
449 $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
452 // Allow extensions to add their custom variables to the global JS variables
453 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
455 return self::makeVariablesScript( $vars );
459 * To make it harder for someone to slip a user a fake
460 * user-JavaScript or user-CSS preview, a random token
461 * is associated with the login session. If it's not
462 * passed back with the preview request, we won't render
465 * @param $action String: 'edit', 'submit' etc.
468 public function userCanPreview( $action ) {
469 global $wgRequest, $wgUser;
471 if ( $action != 'submit' ) {
474 if ( !$wgRequest->wasPosted() ) {
477 if ( !$this->mTitle->userCanEditCssSubpage() ) {
480 if ( !$this->mTitle->userCanEditJsSubpage() ) {
484 return $wgUser->matchEditToken(
485 $wgRequest->getVal( 'wpEditToken' ) );
489 * Generated JavaScript action=raw&gen=js
490 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
491 * nated together. For some bizarre reason, it does *not* return any
492 * custom user JS from subpages. Huh?
494 * There's absolutely no reason to have separate Monobook/Common JSes.
495 * Any JS that cares can just check the skin variable generated at the
496 * top. For now Monobook.js will be maintained, but it should be consi-
499 * @param $skinName String: If set, overrides the skin name
502 public function generateUserJs( $skinName = null ) {
504 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
510 * Generate user stylesheet for action=raw&gen=css
512 public function generateUserStylesheet() {
514 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
520 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
521 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
523 protected function reallyGenerateUserStylesheet() {
525 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
533 function setupUserCss( OutputPage $out ) {
535 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
537 wfProfileIn( __METHOD__ );
539 $this->setupSkinUserCss( $out );
540 // Add any extension CSS
541 foreach ( $out->getExtStyle() as $url ) {
542 $out->addStyle( $url );
545 // Per-site custom styles
546 if ( $wgUseSiteCss ) {
547 $out->addModuleStyles( 'site' );
550 // Per-user custom styles
551 if ( $wgAllowUserCss ) {
552 if ( $this->mTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
553 // @FIXME: properly escape the cdata!
554 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
556 $out->addModuleStyles( 'user' );
560 // Per-user preference styles
561 if ( $wgAllowUserCssPrefs ) {
562 $out->addModuleStyles( 'user.options' );
565 wfProfileOut( __METHOD__ );
569 * Get the query to generate a dynamic stylesheet
573 public static function getDynamicStylesheetQuery() {
574 global $wgSquidMaxage;
578 'maxage' => $wgSquidMaxage,
579 'usemsgcache' => 'yes',
580 'ctype' => 'text/css',
581 'smaxage' => $wgSquidMaxage,
586 * Add skin specific stylesheets
587 * @param $out OutputPage
589 function setupSkinUserCss( OutputPage $out ) {
590 $out->addModuleStyles( 'mediawiki.legacy.shared' );
591 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
592 // TODO: When converting old skins to use ResourceLoader (or removing them) the following should be reconsidered
593 $out->addStyle( $this->getStylesheet() );
594 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
597 function getPageClasses( $title ) {
598 $numeric = 'ns-' . $title->getNamespace();
600 if ( $title->getNamespace() == NS_SPECIAL ) {
601 $type = 'ns-special';
602 } elseif ( $title->isTalkPage() ) {
605 $type = 'ns-subject';
608 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
610 return "$numeric $type $name";
614 * This will be called by OutputPage::headElement when it is creating the
615 * <body> tag, skins can override it if they have a need to add in any
616 * body attributes or classes of their own.
618 function addToBodyAttributes( $out, &$bodyAttrs ) {
619 // does nothing by default
631 * This will be called immediately after the <body> tag. Split into
632 * two functions to make it easier to subclass.
634 function beforeContent() {
635 return $this->doBeforeContent();
638 function doBeforeContent() {
640 wfProfileIn( __METHOD__ );
643 $qb = $this->qbSetting();
645 $langlinks = $this->otherLanguages();
652 $borderhack = 'class="top"';
655 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
656 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
658 $shove = ( $qb != 0 );
659 $left = ( $qb == 1 || $qb == 3 );
661 if ( $wgContLang->isRTL() ) {
666 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
667 $this->logoText() . '</td>';
669 $s .= $this->getQuickbarCompensator( $rows );
672 $l = $wgContLang->alignStart();
673 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
675 $s .= $this->topLinks();
676 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
678 $r = $wgContLang->alignEnd();
679 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
680 $s .= $this->nameAndLogin();
681 $s .= "\n<br />" . $this->searchForm() . '</td>';
684 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
687 if ( $shove && !$left ) { # Right
688 $s .= $this->getQuickbarCompensator( $rows );
691 $s .= "</tr>\n</table>\n</div>\n";
692 $s .= "\n<div id='article'>\n";
694 $notice = wfGetSiteNotice();
697 $s .= "\n<div id='siteNotice'>$notice</div>\n";
699 $s .= $this->pageTitle();
700 $s .= $this->pageSubtitle();
701 $s .= $this->getCategories();
703 wfProfileOut( __METHOD__ );
707 function getCategoryLinks() {
708 global $wgOut, $wgUseCategoryBrowser;
709 global $wgContLang, $wgUser;
711 if ( count( $wgOut->mCategoryLinks ) == 0 ) {
716 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
718 // Use Unicode bidi embedding override characters,
719 // to make sure links don't smash each other up in ugly ways.
720 $dir = $wgContLang->getDir();
721 $embed = "<span dir='$dir'>";
724 $allCats = $wgOut->getCategoryLinks();
726 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
728 if ( !empty( $allCats['normal'] ) ) {
729 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
731 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
732 $s .= '<div id="mw-normal-catlinks">' .
733 $this->link( Title::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
734 . $colon . $t . '</div>';
738 if ( isset( $allCats['hidden'] ) ) {
739 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
740 $class = 'mw-hidden-cats-user-shown';
741 } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
742 $class = 'mw-hidden-cats-ns-shown';
744 $class = 'mw-hidden-cats-hidden';
747 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
748 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
749 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
753 # optional 'dmoz-like' category browser. Will be shown under the list
754 # of categories an article belong to
755 if ( $wgUseCategoryBrowser ) {
756 $s .= '<br /><hr />';
758 # get a big array of the parents tree
759 $parenttree = $this->mTitle->getParentCategoryTree();
760 # Skin object passed by reference cause it can not be
761 # accessed under the method subfunction drawCategoryBrowser
762 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
763 # Clean out bogus first entry and sort them
764 unset( $tempout[0] );
766 # Output one per line
767 $s .= implode( "<br />\n", $tempout );
774 * Render the array as a serie of links.
775 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
776 * @param &skin Object: skin passed by reference
777 * @return String separated by >, terminate with "\n"
779 function drawCategoryBrowser( $tree, &$skin ) {
782 foreach ( $tree as $element => $parent ) {
783 if ( empty( $parent ) ) {
784 # element start a new list
787 # grab the others elements
788 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' > ';
791 # add our current element to the list
792 $eltitle = Title::newFromText( $element );
793 $return .= $skin->link( $eltitle, $eltitle->getText() );
799 function getCategories() {
800 $catlinks = $this->getCategoryLinks();
802 $classes = 'catlinks';
804 global $wgOut, $wgUser;
806 // Check what we're showing
807 $allCats = $wgOut->getCategoryLinks();
808 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
809 $this->mTitle->getNamespace() == NS_CATEGORY;
811 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
812 $classes .= ' catlinks-allhidden';
815 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
818 function getQuickbarCompensator( $rows = 1 ) {
819 return "<td width='152' rowspan='{$rows}'> </td>";
823 * This runs a hook to allow extensions placing their stuff after content
824 * and article metadata (e.g. categories).
825 * Note: This function has nothing to do with afterContent().
827 * This hook is placed here in order to allow using the same hook for all
828 * skins, both the SkinTemplate based ones and the older ones, which directly
829 * use this class to get their data.
831 * The output of this function gets processed in SkinTemplate::outputPage() for
832 * the SkinTemplate based skins, all other skins should directly echo it.
834 * Returns an empty string by default, if not changed by any hook function.
836 protected function afterContentHook() {
839 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
840 // adding just some spaces shouldn't toggle the output
841 // of the whole <div/>, so we use trim() here
842 if ( trim( $data ) != '' ) {
843 // Doing this here instead of in the skins to
844 // ensure that the div has the same ID in all
846 $data = "<div id='mw-data-after-content'>\n" .
851 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
858 * Generate debug data HTML for displaying at the bottom of the main content
860 * @return String HTML containing debug data, if enabled (otherwise empty).
862 protected function generateDebugHTML() {
863 global $wgShowDebug, $wgOut;
865 if ( $wgShowDebug ) {
866 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext );
867 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
868 $listInternals . "</ul>\n";
874 private function formatDebugHTML( $debugText ) {
875 $lines = explode( "\n", $debugText );
879 foreach ( $lines as $line ) {
880 $display = ltrim( $line );
881 $ident = strlen( $line ) - strlen( $display );
882 $diff = $ident - $curIdent;
884 if ( $display == '' ) {
885 $display = "\xc2\xa0";
888 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
891 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
893 $display = htmlspecialchars( $display );
897 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
898 } elseif ( $diff == 0 ) {
899 $ret .= "</li><li>\n";
901 $ret .= str_repeat( "<ul><li>\n", $diff );
903 $ret .= $display . "\n";
908 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
914 * This gets called shortly before the </body> tag.
915 * @return String HTML to be put before </body>
917 function afterContent() {
918 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
919 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
923 * This gets called shortly before the </body> tag.
924 * @param $out OutputPage object
925 * @return String HTML-wrapped JS code to be put before </body>
927 function bottomScripts( $out ) {
928 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
929 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
931 return $bottomScriptText;
934 /** @return string Retrievied from HTML text */
935 function printSource() {
936 $url = htmlspecialchars( $this->mTitle->getFullURL() );
937 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
940 function printFooter() {
941 return "<p>" . $this->printSource() .
942 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
945 /** overloaded by derived classes */
946 function doAfterContent() {
947 return '</div></div>';
950 function pageTitleLinks() {
951 global $wgOut, $wgUser, $wgRequest, $wgLang;
953 $oldid = $wgRequest->getVal( 'oldid' );
954 $diff = $wgRequest->getVal( 'diff' );
955 $action = $wgRequest->getText( 'action' );
957 $s[] = $this->printableLink();
958 $disclaimer = $this->disclaimerLink(); # may be empty
964 $privacy = $this->privacyLink(); # may be empty too
970 if ( $wgOut->isArticleRelated() ) {
971 if ( $this->mTitle->getNamespace() == NS_FILE ) {
972 $name = $this->mTitle->getDBkey();
973 $image = wfFindFile( $this->mTitle );
976 $link = htmlspecialchars( $image->getURL() );
977 $style = $this->getInternalLinkAttributes( $link, $name );
978 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
983 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
986 wfMsg( 'currentrev' ),
989 array( 'known', 'noclasses' )
993 if ( $wgUser->getNewtalk() ) {
994 # do not show "You have new messages" text when we are viewing our
996 if ( !$this->mTitle->equals( $wgUser->getTalkPage() ) ) {
998 $wgUser->getTalkPage(),
999 wfMsgHtml( 'newmessageslink' ),
1001 array( 'redirect' => 'no' ),
1002 array( 'known', 'noclasses' )
1006 $wgUser->getTalkPage(),
1007 wfMsgHtml( 'newmessagesdifflink' ),
1009 array( 'diff' => 'cur' ),
1010 array( 'known', 'noclasses' )
1012 $s[] = '<strong>' . wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1014 $wgOut->setSquidMaxage( 0 );
1015 $wgOut->enableClientCache( false );
1019 $undelete = $this->getUndeleteLink();
1021 if ( !empty( $undelete ) ) {
1025 return $wgLang->pipeList( $s );
1028 function getUndeleteLink() {
1029 global $wgUser, $wgLang, $wgRequest;
1031 $action = $wgRequest->getVal( 'action', 'view' );
1033 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1034 ( $this->mTitle->getArticleId() == 0 || $action == 'history' ) ) {
1035 $n = $this->mTitle->isDeleted();
1038 if ( $wgUser->isAllowed( 'undelete' ) ) {
1039 $msg = 'thisisdeleted';
1041 $msg = 'viewdeleted';
1047 SpecialPage::getTitleFor( 'Undelete', $this->mTitle->getPrefixedDBkey() ),
1048 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1051 array( 'known', 'noclasses' )
1060 function printableLink() {
1061 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1065 if ( !$wgOut->isPrintable() ) {
1066 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1067 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1070 if ( $wgOut->isSyndicated() ) {
1071 foreach ( $wgFeedClasses as $format => $class ) {
1072 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1073 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1074 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1077 return $wgLang->pipeList( $s );
1081 * Gets the h1 element with the page title.
1084 function pageTitle() {
1086 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1090 function pageSubtitle() {
1093 $sub = $wgOut->getSubtitle();
1096 global $wgExtraSubtitle;
1097 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1100 $subpages = $this->subPageSubtitle();
1101 $sub .= !empty( $subpages ) ? "</p><p class='subpages'>$subpages" : '';
1102 $s = "<p class='subtitle'>{$sub}</p>\n";
1107 function subPageSubtitle() {
1110 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this ) ) ) {
1116 if ( $wgOut->isArticle() && MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
1117 $ptext = $this->mTitle->getPrefixedText();
1118 if ( preg_match( '/\//', $ptext ) ) {
1119 $links = explode( '/', $ptext );
1120 array_pop( $links );
1125 foreach ( $links as $link ) {
1126 $growinglink .= $link;
1128 $linkObj = Title::newFromText( $growinglink );
1130 if ( is_object( $linkObj ) && $linkObj->exists() ) {
1131 $getlink = $this->link(
1133 htmlspecialchars( $display ),
1136 array( 'known', 'noclasses' )
1142 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1144 $subpages .= '< ';
1147 $subpages .= $getlink;
1152 $growinglink .= '/';
1161 * Returns true if the IP should be shown in the header
1163 function showIPinHeader() {
1164 global $wgShowIPinHeader;
1165 return $wgShowIPinHeader && session_id() != '';
1168 function nameAndLogin() {
1169 global $wgUser, $wgLang, $wgContLang;
1171 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1175 if ( $wgUser->isAnon() ) {
1176 if ( $this->showIPinHeader() ) {
1179 $talkLink = $this->link( $wgUser->getTalkPage(),
1180 $wgLang->getNsText( NS_TALK ) );
1182 $ret .= "$name ($talkLink)";
1184 $ret .= wfMsg( 'notloggedin' );
1187 $returnTo = $this->mTitle->getPrefixedDBkey();
1190 if ( $logoutPage != $returnTo ) {
1191 $query['returnto'] = $returnTo;
1194 $loginlink = $wgUser->isAllowed( 'createaccount' )
1195 ? 'nav-login-createaccount'
1197 $ret .= "\n<br />" . $this->link(
1198 SpecialPage::getTitleFor( 'Userlogin' ),
1199 wfMsg( $loginlink ), array(), $query
1202 $returnTo = $this->mTitle->getPrefixedDBkey();
1203 $talkLink = $this->link( $wgUser->getTalkPage(),
1204 $wgLang->getNsText( NS_TALK ) );
1206 $ret .= $this->link( $wgUser->getUserPage(),
1207 htmlspecialchars( $wgUser->getName() ) );
1208 $ret .= " ($talkLink)<br />";
1209 $ret .= $wgLang->pipeList( array(
1211 SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1212 array(), array( 'returnto' => $returnTo )
1214 $this->specialLink( 'Preferences' ),
1218 $ret = $wgLang->pipeList( array(
1221 Title::newFromText( wfMsgForContent( 'helppage' ) ),
1229 function getSearchLink() {
1230 $searchPage = SpecialPage::getTitleFor( 'Search' );
1231 return $searchPage->getLocalURL();
1234 function escapeSearchLink() {
1235 return htmlspecialchars( $this->getSearchLink() );
1238 function searchForm() {
1239 global $wgRequest, $wgUseTwoButtonsSearchForm;
1241 $search = $wgRequest->getText( 'search' );
1243 $s = '<form id="searchform' . $this->searchboxes . '" name="search" class="inline" method="post" action="'
1244 . $this->escapeSearchLink() . "\">\n"
1245 . '<input type="text" id="searchInput' . $this->searchboxes . '" name="search" size="19" value="'
1246 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1247 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1249 if ( $wgUseTwoButtonsSearchForm ) {
1250 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1252 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1257 // Ensure unique id's for search boxes made after the first
1258 $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
1263 function topLinks() {
1267 $this->mainPageLink(),
1268 $this->specialLink( 'Recentchanges' )
1271 if ( $wgOut->isArticleRelated() ) {
1272 $s[] = $this->editThisPage();
1273 $s[] = $this->historyLink();
1276 # Many people don't like this dropdown box
1277 # $s[] = $this->specialPagesList();
1279 if ( $this->variantLinks() ) {
1280 $s[] = $this->variantLinks();
1283 if ( $this->extensionTabLinks() ) {
1284 $s[] = $this->extensionTabLinks();
1287 // @todo FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1288 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1292 * Compatibility for extensions adding functionality through tabs.
1293 * Eventually these old skins should be replaced with SkinTemplate-based
1297 function extensionTabLinks() {
1301 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1302 foreach ( $tabs as $tab ) {
1303 $s[] = Xml::element( 'a',
1304 array( 'href' => $tab['href'] ),
1308 if ( count( $s ) ) {
1311 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1312 $out .= $wgLang->pipeList( $s );
1319 * Language/charset variant links for classic-style skins
1322 function variantLinks() {
1325 /* show links to different language variants */
1326 global $wgDisableLangConversion, $wgLang, $wgContLang;
1328 $variants = $wgContLang->getVariants();
1330 if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1331 foreach ( $variants as $code ) {
1332 $varname = $wgContLang->getVariantname( $code );
1334 if ( $varname == 'disable' ) {
1337 $s = $wgLang->pipeList( array(
1339 '<a href="' . $this->mTitle->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1347 function bottomLinks() {
1348 global $wgOut, $wgUser, $wgUseTrackbacks;
1349 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1352 if ( $wgOut->isArticleRelated() ) {
1353 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1355 if ( $wgUser->isLoggedIn() ) {
1356 $element[] = $this->watchThisPage();
1359 $element[] = $this->talkLink();
1360 $element[] = $this->historyLink();
1361 $element[] = $this->whatLinksHere();
1362 $element[] = $this->watchPageLinksLink();
1364 if ( $wgUseTrackbacks ) {
1365 $element[] = $this->trackbackLink();
1369 $this->mTitle->getNamespace() == NS_USER ||
1370 $this->mTitle->getNamespace() == NS_USER_TALK
1372 $id = User::idFromName( $this->mTitle->getText() );
1373 $ip = User::isIP( $this->mTitle->getText() );
1375 # Both anons and non-anons have contributions list
1377 $element[] = $this->userContribsLink();
1380 if ( $this->showEmailUser( $id ) ) {
1381 $element[] = $this->emailUserLink();
1385 $s = implode( $element, $sep );
1387 if ( $this->mTitle->getArticleId() ) {
1390 // Delete/protect/move links for privileged users
1391 if ( $wgUser->isAllowed( 'delete' ) ) {
1392 $s .= $this->deleteThisPage();
1395 if ( $wgUser->isAllowed( 'protect' ) ) {
1396 $s .= $sep . $this->protectThisPage();
1399 if ( $wgUser->isAllowed( 'move' ) ) {
1400 $s .= $sep . $this->moveThisPage();
1404 $s .= "<br />\n" . $this->otherLanguages();
1410 function pageStats() {
1411 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1412 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1414 $oldid = $wgRequest->getVal( 'oldid' );
1415 $diff = $wgRequest->getVal( 'diff' );
1417 if ( !$wgOut->isArticle() ) {
1421 if ( !$wgArticle instanceof Article ) {
1425 if ( isset( $oldid ) || isset( $diff ) ) {
1429 if ( 0 == $wgArticle->getID() ) {
1435 if ( !$wgDisableCounters ) {
1436 $count = $wgLang->formatNum( $wgArticle->getCount() );
1439 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1443 if ( $wgMaxCredits != 0 ) {
1444 $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1446 $s .= $this->lastModified();
1449 if ( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1450 $dbr = wfGetDB( DB_SLAVE );
1451 $res = $dbr->select(
1453 array( 'COUNT(*) AS n' ),
1455 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ),
1456 'wl_namespace' => $this->mTitle->getNamespace()
1460 $x = $dbr->fetchObject( $res );
1462 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1463 array( 'parseinline' ), $wgLang->formatNum( $x->n )
1467 return $s . ' ' . $this->getCopyright();
1470 function getCopyright( $type = 'detect' ) {
1471 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1473 if ( $type == 'detect' ) {
1474 $diff = $wgRequest->getVal( 'diff' );
1475 $isCur = $wgArticle && $wgArticle->isCurrent();
1477 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1484 if ( $type == 'history' ) {
1485 $msg = 'history_copyright';
1492 if ( $wgRightsPage ) {
1493 $title = Title::newFromText( $wgRightsPage );
1494 $link = $this->linkKnown( $title, $wgRightsText );
1495 } elseif ( $wgRightsUrl ) {
1496 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1497 } elseif ( $wgRightsText ) {
1498 $link = $wgRightsText;
1504 // Allow for site and per-namespace customization of copyright notice.
1507 if ( isset( $wgArticle ) ) {
1508 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link, &$forContent ) );
1511 if ( $forContent ) {
1512 $out .= wfMsgForContent( $msg, $link );
1514 $out .= wfMsg( $msg, $link );
1520 function getCopyrightIcon() {
1521 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1525 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1526 $out = $wgCopyrightIcon;
1527 } elseif ( $wgRightsIcon ) {
1528 $icon = htmlspecialchars( $wgRightsIcon );
1530 if ( $wgRightsUrl ) {
1531 $url = htmlspecialchars( $wgRightsUrl );
1532 $out .= '<a href="' . $url . '">';
1535 $text = htmlspecialchars( $wgRightsText );
1536 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1538 if ( $wgRightsUrl ) {
1547 * Gets the powered by MediaWiki icon.
1550 function getPoweredBy() {
1551 global $wgStylePath;
1553 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1554 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1555 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
1559 function lastModified() {
1560 global $wgLang, $wgArticle;
1562 if ( $this->mRevisionId && $this->mRevisionId != $wgArticle->getLatest() ) {
1563 $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
1565 $timestamp = $wgArticle->getTimestamp();
1569 $d = $wgLang->date( $timestamp, true );
1570 $t = $wgLang->time( $timestamp, true );
1571 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1576 if ( wfGetLB()->getLaggedSlaveMode() ) {
1577 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1583 function logoText( $align = '' ) {
1584 if ( $align != '' ) {
1585 $a = " align='{$align}'";
1590 $mp = wfMsg( 'mainpage' );
1591 $mptitle = Title::newMainPage();
1592 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
1594 $logourl = $this->getLogo();
1595 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1601 * Show a drop-down box of special pages
1603 function specialPagesList() {
1604 global $wgContLang, $wgServer, $wgRedirectScript;
1606 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1608 foreach ( $pages as $name => $page ) {
1609 $pages[$name] = $page->getDescription();
1612 $go = wfMsg( 'go' );
1613 $sp = wfMsg( 'specialpages' );
1614 $spp = $wgContLang->specialPage( 'Specialpages' );
1616 $s = '<form id="specialpages" method="get" ' .
1617 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1618 $s .= "<select name=\"wpDropdown\">\n";
1619 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1622 foreach ( $pages as $name => $desc ) {
1623 $p = $wgContLang->specialPage( $name );
1624 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1627 $s .= "</select>\n";
1628 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1635 * Renders a $wgFooterIcons icon acording to the method's arguments
1636 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
1637 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
1639 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
1640 if ( is_string( $icon ) ) {
1642 } else { // Assuming array
1643 $url = isset($icon["url"]) ? $icon["url"] : null;
1644 unset( $icon["url"] );
1645 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
1646 $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1648 $html = htmlspecialchars( $icon["alt"] );
1651 $html = Html::rawElement( 'a', array( "href" => $url ), $html );
1658 * Gets the link to the wiki's main page.
1661 function mainPageLink() {
1663 Title::newMainPage(),
1664 wfMsg( 'mainpage' ),
1667 array( 'known', 'noclasses' )
1673 public function footerLink( $desc, $page ) {
1674 // if the link description has been set to "-" in the default language,
1675 if ( wfMsgForContent( $desc ) == '-' ) {
1676 // then it is disabled, for all languages.
1679 // Otherwise, we display the link for the user, described in their
1680 // language (which may or may not be the same as the default language),
1681 // but we make the link target be the one site-wide page.
1682 $title = Title::newFromText( wfMsgForContent( $page ) );
1684 return $this->linkKnown(
1686 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1692 * Gets the link to the wiki's privacy policy page.
1694 function privacyLink() {
1695 return $this->footerLink( 'privacy', 'privacypage' );
1699 * Gets the link to the wiki's about page.
1701 function aboutLink() {
1702 return $this->footerLink( 'aboutsite', 'aboutpage' );
1706 * Gets the link to the wiki's general disclaimers page.
1708 function disclaimerLink() {
1709 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1712 function editThisPage() {
1715 if ( !$wgOut->isArticleRelated() ) {
1716 $s = wfMsg( 'protectedpage' );
1718 if ( $this->mTitle->quickUserCan( 'edit' ) && $this->mTitle->exists() ) {
1719 $t = wfMsg( 'editthispage' );
1720 } elseif ( $this->mTitle->quickUserCan( 'create' ) && !$this->mTitle->exists() ) {
1721 $t = wfMsg( 'create-this-page' );
1723 $t = wfMsg( 'viewsource' );
1730 $this->editUrlOptions(),
1731 array( 'known', 'noclasses' )
1739 * Return URL options for the 'edit page' link.
1740 * This may include an 'oldid' specifier, if the current page view is such.
1745 function editUrlOptions() {
1748 $options = array( 'action' => 'edit' );
1750 if ( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1751 $options['oldid'] = intval( $this->mRevisionId );
1757 function deleteThisPage() {
1758 global $wgUser, $wgRequest;
1760 $diff = $wgRequest->getVal( 'diff' );
1762 if ( $this->mTitle->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1763 $t = wfMsg( 'deletethispage' );
1769 array( 'action' => 'delete' ),
1770 array( 'known', 'noclasses' )
1779 function protectThisPage() {
1780 global $wgUser, $wgRequest;
1782 $diff = $wgRequest->getVal( 'diff' );
1784 if ( $this->mTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
1785 if ( $this->mTitle->isProtected() ) {
1786 $text = wfMsg( 'unprotectthispage' );
1787 $query = array( 'action' => 'unprotect' );
1789 $text = wfMsg( 'protectthispage' );
1790 $query = array( 'action' => 'protect' );
1798 array( 'known', 'noclasses' )
1807 function watchThisPage() {
1809 ++$this->mWatchLinkNum;
1811 if ( $wgOut->isArticleRelated() ) {
1812 if ( $this->mTitle->userIsWatching() ) {
1813 $text = wfMsg( 'unwatchthispage' );
1814 $query = array( 'action' => 'unwatch' );
1815 $id = 'mw-unwatch-link' . $this->mWatchLinkNum;
1817 $text = wfMsg( 'watchthispage' );
1818 $query = array( 'action' => 'watch' );
1819 $id = 'mw-watch-link' . $this->mWatchLinkNum;
1825 array( 'id' => $id ),
1827 array( 'known', 'noclasses' )
1830 $s = wfMsg( 'notanarticle' );
1836 function moveThisPage() {
1837 if ( $this->mTitle->quickUserCan( 'move' ) ) {
1839 SpecialPage::getTitleFor( 'Movepage' ),
1840 wfMsg( 'movethispage' ),
1842 array( 'target' => $this->mTitle->getPrefixedDBkey() ),
1843 array( 'known', 'noclasses' )
1846 // no message if page is protected - would be redundant
1851 function historyLink() {
1854 wfMsgHtml( 'history' ),
1855 array( 'rel' => 'archives' ),
1856 array( 'action' => 'history' )
1860 function whatLinksHere() {
1862 SpecialPage::getTitleFor( 'Whatlinkshere', $this->mTitle->getPrefixedDBkey() ),
1863 wfMsgHtml( 'whatlinkshere' ),
1866 array( 'known', 'noclasses' )
1870 function userContribsLink() {
1872 SpecialPage::getTitleFor( 'Contributions', $this->mTitle->getDBkey() ),
1873 wfMsgHtml( 'contributions' ),
1876 array( 'known', 'noclasses' )
1880 function showEmailUser( $id ) {
1882 $targetUser = User::newFromId( $id );
1883 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1884 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1887 function emailUserLink() {
1889 SpecialPage::getTitleFor( 'Emailuser', $this->mTitle->getDBkey() ),
1890 wfMsg( 'emailuser' ),
1893 array( 'known', 'noclasses' )
1897 function watchPageLinksLink() {
1900 if ( !$wgOut->isArticleRelated() ) {
1901 return '(' . wfMsg( 'notanarticle' ) . ')';
1904 SpecialPage::getTitleFor( 'Recentchangeslinked', $this->mTitle->getPrefixedDBkey() ),
1905 wfMsg( 'recentchangeslinked-toolbox' ),
1908 array( 'known', 'noclasses' )
1913 function trackbackLink() {
1914 return '<a href="' . $this->mTitle->trackbackURL() . '">'
1915 . wfMsg( 'trackbacklink' ) . '</a>';
1918 function otherLanguages() {
1919 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1921 if ( $wgHideInterlanguageLinks ) {
1925 $a = $wgOut->getLanguageLinks();
1927 if ( 0 == count( $a ) ) {
1931 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1934 if ( $wgContLang->isRTL() ) {
1935 $s .= '<span dir="LTR">';
1938 foreach ( $a as $l ) {
1940 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1945 $nt = Title::newFromText( $l );
1946 $url = $nt->escapeFullURL();
1947 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1948 $title = htmlspecialchars( $nt->getText() );
1950 if ( $text == '' ) {
1954 $style = $this->getExternalLinkAttributes();
1955 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
1958 if ( $wgContLang->isRTL() ) {
1965 function talkLink() {
1966 if ( NS_SPECIAL == $this->mTitle->getNamespace() ) {
1967 # No discussion links for special pages
1971 $linkOptions = array();
1973 if ( $this->mTitle->isTalkPage() ) {
1974 $link = $this->mTitle->getSubjectPage();
1975 switch( $link->getNamespace() ) {
1977 $text = wfMsg( 'articlepage' );
1980 $text = wfMsg( 'userpage' );
1983 $text = wfMsg( 'projectpage' );
1986 $text = wfMsg( 'imagepage' );
1987 # Make link known if image exists, even if the desc. page doesn't.
1988 if ( wfFindFile( $link ) )
1989 $linkOptions[] = 'known';
1992 $text = wfMsg( 'mediawikipage' );
1995 $text = wfMsg( 'templatepage' );
1998 $text = wfMsg( 'viewhelppage' );
2001 $text = wfMsg( 'categorypage' );
2004 $text = wfMsg( 'articlepage' );
2007 $link = $this->mTitle->getTalkPage();
2008 $text = wfMsg( 'talkpage' );
2011 $s = $this->link( $link, $text, array(), array(), $linkOptions );
2016 function commentLink() {
2019 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
2023 # __NEWSECTIONLINK___ changes behaviour here
2024 # If it is present, the link points to this page, otherwise
2025 # it points to the talk page
2026 if ( $this->mTitle->isTalkPage() ) {
2027 $title = $this->mTitle;
2028 } elseif ( $wgOut->showNewSectionLink() ) {
2029 $title = $this->mTitle;
2031 $title = $this->mTitle->getTalkPage();
2036 wfMsg( 'postcomment' ),
2042 array( 'known', 'noclasses' )
2046 function getUploadLink() {
2047 global $wgUploadNavigationUrl;
2049 if ( $wgUploadNavigationUrl ) {
2050 # Using an empty class attribute to avoid automatic setting of "external" class
2051 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '' ) );
2054 SpecialPage::getTitleFor( 'Upload' ),
2055 wfMsgHtml( 'upload' ),
2058 array( 'known', 'noclasses' )
2064 * Return a fully resolved style path url to images or styles stored in the common folder.
2065 * This method returns a url resolved using the configured skin style path
2066 * and includes the style version inside of the url.
2067 * @param $name String: The name or path of the common file to return the full path for.
2068 * @return String The fully resolved style path url including styleversion
2070 function getCommonStylePath( $name ) {
2071 global $wgStylePath, $wgStyleVersion;
2072 return "{$wgStylePath}/common/$name?{$wgStyleVersion}";
2076 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
2077 * This method returns a url resolved using the configured skin style path
2078 * and includes the style version inside of the url.
2079 * @param $name String: The name or path of the skin resource file to return the full path for.
2080 * @return String The fully resolved style path url including styleversion
2082 function getSkinStylePath( $name ) {
2083 global $wgStylePath, $wgStyleVersion;
2084 return "{$wgStylePath}/{$this->stylename}/$name?{$wgStyleVersion}";
2087 /* these are used extensively in SkinTemplate, but also some other places */
2088 static function makeMainPageUrl( $urlaction = '' ) {
2089 $title = Title::newMainPage();
2090 self::checkTitle( $title, '' );
2092 return $title->getLocalURL( $urlaction );
2095 static function makeSpecialUrl( $name, $urlaction = '' ) {
2096 $title = SpecialPage::getTitleFor( $name );
2097 return $title->getLocalURL( $urlaction );
2100 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2101 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
2102 return $title->getLocalURL( $urlaction );
2105 static function makeI18nUrl( $name, $urlaction = '' ) {
2106 $title = Title::newFromText( wfMsgForContent( $name ) );
2107 self::checkTitle( $title, $name );
2108 return $title->getLocalURL( $urlaction );
2111 static function makeUrl( $name, $urlaction = '' ) {
2112 $title = Title::newFromText( $name );
2113 self::checkTitle( $title, $name );
2115 return $title->getLocalURL( $urlaction );
2119 * If url string starts with http, consider as external URL, else
2122 static function makeInternalOrExternalUrl( $name ) {
2123 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2126 return self::makeUrl( $name );
2130 # this can be passed the NS number as defined in Language.php
2131 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
2132 $title = Title::makeTitleSafe( $namespace, $name );
2133 self::checkTitle( $title, $name );
2135 return $title->getLocalURL( $urlaction );
2138 /* these return an array with the 'href' and boolean 'exists' */
2139 static function makeUrlDetails( $name, $urlaction = '' ) {
2140 $title = Title::newFromText( $name );
2141 self::checkTitle( $title, $name );
2144 'href' => $title->getLocalURL( $urlaction ),
2145 'exists' => $title->getArticleID() != 0,
2150 * Make URL details where the article exists (or at least it's convenient to think so)
2152 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2153 $title = Title::newFromText( $name );
2154 self::checkTitle( $title, $name );
2157 'href' => $title->getLocalURL( $urlaction ),
2162 # make sure we have some title to operate on
2163 static function checkTitle( &$title, $name ) {
2164 if ( !is_object( $title ) ) {
2165 $title = Title::newFromText( $name );
2166 if ( !is_object( $title ) ) {
2167 $title = Title::newFromText( '--error: link target missing--' );
2173 * Build an array that represents the sidebar(s), the navigation bar among them
2177 function buildSidebar() {
2178 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2180 wfProfileIn( __METHOD__ );
2182 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2184 if ( $wgEnableSidebarCache ) {
2185 $cachedsidebar = $parserMemc->get( $key );
2186 if ( $cachedsidebar ) {
2187 wfProfileOut( __METHOD__ );
2188 return $cachedsidebar;
2193 $this->addToSidebar( $bar, 'sidebar' );
2195 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2196 if ( $wgEnableSidebarCache ) {
2197 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2200 wfProfileOut( __METHOD__ );
2204 * Add content from a sidebar system message
2205 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2207 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2209 * @param &$bar array
2210 * @param $message String
2212 function addToSidebar( &$bar, $message ) {
2213 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2217 * Add content from plain text
2219 * @param &$bar array
2220 * @param $text string
2222 function addToSidebarPlain( &$bar, $text ) {
2223 $lines = explode( "\n", $text );
2224 $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.
2228 foreach ( $lines as $line ) {
2229 if ( strpos( $line, '*' ) !== 0 ) {
2233 if ( strpos( $line, '**' ) !== 0 ) {
2234 $heading = trim( $line, '* ' );
2235 if ( !array_key_exists( $heading, $bar ) ) {
2236 $bar[$heading] = array();
2239 $line = trim( $line, '* ' );
2241 if ( strpos( $line, '|' ) !== false ) { // sanity check
2242 $line = array_map( 'trim', explode( '|', $line, 2 ) );
2243 $link = wfMsgForContent( $line[0] );
2245 if ( $link == '-' ) {
2249 $text = wfMsgExt( $line[1], 'parsemag' );
2251 if ( wfEmptyMsg( $line[1], $text ) ) {
2255 if ( wfEmptyMsg( $line[0], $link ) ) {
2259 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2262 $title = Title::newFromText( $link );
2265 $title = $title->fixSpecialName();
2266 $href = $title->getLocalURL();
2268 $href = 'INVALID-TITLE';
2272 $bar[$heading][] = array(
2275 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2278 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
2279 global $wgParser, $wgTitle;
2281 $line = substr( $line, 2, strlen( $line ) - 4 );
2283 $options = new ParserOptions();
2284 $options->setEditSection( false );
2285 $options->setInterfaceMessage( true );
2286 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $options )->getText();
2293 if ( count( $wikiBar ) > 0 ) {
2294 $bar = array_merge( $bar, $wikiBar );
2301 * Should we include common/wikiprintable.css? Skins that have their own
2302 * print stylesheet should override this and return false. (This is an
2303 * ugly hack to get Monobook to play nicely with
2304 * OutputPage::headElement().)
2308 public function commonPrintStylesheet() {
2313 * Gets new talk page messages for the current user.
2314 * @return MediaWiki message or if no new talk page messages, nothing
2316 function getNewtalks() {
2317 global $wgUser, $wgOut;
2319 $newtalks = $wgUser->getNewMessageLinks();
2322 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2323 $userTitle = $this->mUser->getUserPage();
2324 $userTalkTitle = $userTitle->getTalkPage();
2326 if ( !$userTalkTitle->equals( $this->mTitle ) ) {
2327 $newMessagesLink = $this->link(
2329 wfMsgHtml( 'newmessageslink' ),
2331 array( 'redirect' => 'no' ),
2332 array( 'known', 'noclasses' )
2335 $newMessagesDiffLink = $this->link(
2337 wfMsgHtml( 'newmessagesdifflink' ),
2339 array( 'diff' => 'cur' ),
2340 array( 'known', 'noclasses' )
2344 'youhavenewmessages',
2346 $newMessagesDiffLink
2348 # Disable Squid cache
2349 $wgOut->setSquidMaxage( 0 );
2351 } elseif ( count( $newtalks ) ) {
2352 // _>" " for BC <= 1.16
2353 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2356 foreach ( $newtalks as $newtalk ) {
2357 $msgs[] = Xml::element(
2359 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2362 $parts = implode( $sep, $msgs );
2363 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2364 $wgOut->setSquidMaxage( 0 );