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 :-\
30 protected $mRelevantTitle = null;
31 protected $mRelevantUser = null;
33 /** Constructor, call parent constructor */
34 function __construct() {
35 parent
::__construct();
39 * Fetch the set of available skins.
40 * @return array of strings
42 static function getSkinNames() {
43 global $wgValidSkinNames;
44 static $skinsInitialised = false;
46 if ( !$skinsInitialised ||
!count( $wgValidSkinNames ) ) {
47 # Get a list of available skins
48 # Build using the regular expression '^(.*).php$'
49 # Array keys are all lower case, array value keep the case used by filename
51 wfProfileIn( __METHOD__
. '-init' );
53 global $wgStyleDirectory;
55 $skinDir = dir( $wgStyleDirectory );
57 # while code from www.php.net
58 while ( false !== ( $file = $skinDir->read() ) ) {
59 // Skip non-PHP files, hidden files, and '.dep' includes
62 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
64 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
68 $skinsInitialised = true;
69 wfProfileOut( __METHOD__
. '-init' );
71 return $wgValidSkinNames;
75 * Fetch the list of usable skins in regards to $wgSkipSkins.
76 * Useful for Special:Preferences and other places where you
77 * only want to show skins users _can_ use.
78 * @return array of strings
80 public static function getUsableSkins() {
83 $usableSkins = self
::getSkinNames();
85 foreach ( $wgSkipSkins as $skip ) {
86 unset( $usableSkins[$skip] );
93 * Normalize a skin preference value to a form that can be loaded.
94 * If a skin can't be found, it will fall back to the configured
95 * default (or the old 'Classic' skin if that's broken).
96 * @param $key String: 'monobook', 'standard', etc.
99 static function normalizeKey( $key ) {
100 global $wgDefaultSkin;
102 $skinNames = Skin
::getSkinNames();
105 // Don't return the default immediately;
106 // in a misconfiguration we need to fall back.
107 $key = $wgDefaultSkin;
110 if ( isset( $skinNames[$key] ) ) {
114 // Older versions of the software used a numeric setting
115 // in the user preferences.
122 if ( isset( $fallback[$key] ) ) {
123 $key = $fallback[$key];
126 if ( isset( $skinNames[$key] ) ) {
128 } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
129 return $wgDefaultSkin;
136 * Factory method for loading a skin of a given type
137 * @param $key String: 'monobook', 'standard', etc.
140 static function &newFromKey( $key ) {
141 global $wgStyleDirectory;
143 $key = Skin
::normalizeKey( $key );
145 $skinNames = Skin
::getSkinNames();
146 $skinName = $skinNames[$key];
147 $className = "Skin{$skinName}";
149 # Grab the skin class and initialise it.
150 if ( !class_exists( $className ) ) {
151 // Preload base classes to work around APC/PHP5 bug
152 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
154 if ( file_exists( $deps ) ) {
155 include_once( $deps );
157 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
159 # Check if we got if not failback to default skin
160 if ( !class_exists( $className ) ) {
161 # DO NOT die if the class isn't found. This breaks maintenance
162 # scripts and can cause a user account to be unrecoverable
163 # except by SQL manipulation if a previously valid skin name
164 # is no longer valid.
165 wfDebug( "Skin class does not exist: $className\n" );
166 $className = 'SkinVector';
167 require_once( "{$wgStyleDirectory}/Vector.php" );
170 $skin = new $className;
174 /** @return string path to the skin stylesheet */
175 function getStylesheet() {
176 return 'common/wikistandard.css';
179 /** @return string skin name */
180 public function getSkinName() {
181 return $this->skinname
;
184 function qbSetting() {
185 global $wgOut, $wgUser;
187 if ( $wgOut->isQuickbarSuppressed() ) {
191 $q = $wgUser->getOption( 'quickbar', 0 );
196 function initPage( OutputPage
$out ) {
197 global $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI;
199 wfProfileIn( __METHOD__
);
201 # Generally the order of the favicon and apple-touch-icon links
202 # should not matter, but Konqueror (3.5.9 at least) incorrectly
203 # uses whichever one appears later in the HTML source. Make sure
204 # apple-touch-icon is specified first to avoid this.
205 if ( false !== $wgAppleTouchIcon ) {
206 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
209 if ( false !== $wgFavicon ) {
210 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
213 # OpenSearch description link
214 $out->addLink( array(
216 'type' => 'application/opensearchdescription+xml',
217 'href' => wfScript( 'opensearch_desc' ),
218 'title' => wfMsgForContent( 'opensearch-desc' ),
221 if ( $wgEnableAPI ) {
222 # Real Simple Discovery link, provides auto-discovery information
223 # for the MediaWiki API (and potentially additional custom API
224 # support such as WordPress or Twitter-compatible APIs for a
225 # blogging extension, etc)
226 $out->addLink( array(
228 'type' => 'application/rsd+xml',
229 'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ) ),
233 $this->addMetadataLinks( $out );
235 $this->mRevisionId
= $out->mRevisionId
;
237 $this->preloadExistence();
239 wfProfileOut( __METHOD__
);
243 * Preload the existence of three commonly-requested pages in a single query
245 function preloadExistence() {
249 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
252 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
254 } elseif ( $this->mTitle
->isTalkPage() ) {
255 $titles[] = $this->mTitle
->getSubjectPage();
257 $titles[] = $this->mTitle
->getTalkPage();
260 $lb = new LinkBatch( $titles );
261 $lb->setCaller( __METHOD__
);
266 * Adds metadata links below to the HTML output.
268 * <li>Creative Commons
269 * <br />See http://wiki.creativecommons.org/Extend_Metadata.
271 * <li>Dublin Core</li>
272 * <li>Use hreflang to specify canonical and alternate links
273 * <br />See http://www.google.com/support/webmasters/bin/answer.py?answer=189077
278 * @param $out Object: instance of OutputPage
280 function addMetadataLinks( OutputPage
$out ) {
281 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
282 global $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang;
283 global $wgRightsPage, $wgRightsUrl;
285 if ( $out->isArticleRelated() ) {
286 # note: buggy CC software only reads first "meta" link
287 if ( $wgEnableCreativeCommonsRdf ) {
288 $out->addMetadataLink( array(
289 'title' => 'Creative Commons',
290 'type' => 'application/rdf+xml',
291 'href' => $this->mTitle
->getLocalURL( 'action=creativecommons' ) )
295 if ( $wgEnableDublinCoreRdf ) {
296 $out->addMetadataLink( array(
297 'title' => 'Dublin Core',
298 'type' => 'application/rdf+xml',
299 'href' => $this->mTitle
->getLocalURL( 'action=dublincore' ) )
304 if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks
305 && $wgContLang->hasVariants() ) {
307 $urlvar = $wgContLang->getURLVariant();
310 $variants = $wgContLang->getVariants();
311 foreach ( $variants as $_v ) {
312 $out->addLink( array(
313 'rel' => 'alternate',
315 'href' => $this->mTitle
->getLocalURL( '', $_v ) )
319 $out->addLink( array(
320 'rel' => 'canonical',
321 'href' => $this->mTitle
->getFullURL() )
327 if ( $wgRightsPage ) {
328 $copy = Title
::newFromText( $wgRightsPage );
331 $copyright = $copy->getLocalURL();
335 if ( !$copyright && $wgRightsUrl ) {
336 $copyright = $wgRightsUrl;
340 $out->addLink( array(
341 'rel' => 'copyright',
342 'href' => $copyright )
348 * Set some local variables
350 protected function setMembers() {
352 $this->mUser
= $wgUser;
353 $this->userpage
= $wgUser->getUserPage()->getPrefixedText();
354 $this->usercss
= false;
359 * @param $t Title object to use
361 public function setTitle( $t ) {
366 public function getTitle() {
367 return $this->mTitle
;
371 * Set the "relevant" title
372 * @see self::getRelevantTitle()
373 * @param $t Title object to use
375 public function setRelevantTitle( $t ) {
376 $this->mRelevantTitle
= $t;
380 * Return the "relevant" title.
381 * A "relevant" title is not necessarily the actual title of the page.
382 * Special pages like Special:MovePage use set the page they are acting on
383 * as their "relevant" title, this allows the skin system to display things
384 * such as content tabs which belong to to that page instead of displaying
385 * a basic special page tab which has almost no meaning.
387 public function getRelevantTitle() {
388 if ( isset($this->mRelevantTitle
) ) {
389 return $this->mRelevantTitle
;
391 return $this->mTitle
;
395 * Set the "relevant" user
396 * @see self::getRelevantUser()
397 * @param $u User object to use
399 public function setRelevantUser( $u ) {
400 $this->mRelevantUser
= $u;
404 * Return the "relevant" user.
405 * A "relevant" user is similar to a relevant title. Special pages like
406 * Special:Contributions mark the user which they are relevant to so that
407 * things like the toolbox can display the information they usually are only
408 * able to display on a user's userpage and talkpage.
410 public function getRelevantUser() {
411 if ( isset($this->mRelevantUser
) ) {
412 return $this->mRelevantUser
;
414 $title = $this->getRelevantTitle();
415 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
416 $rootUser = strtok( $title->getText(), '/' );
417 if ( User
::isIP( $rootUser ) ) {
418 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
420 $user = User
::newFromName( $rootUser );
421 if ( $user->isLoggedIn() ) {
422 $this->mRelevantUser
= $user;
425 return $this->mRelevantUser
;
431 * Outputs the HTML generated by other functions.
432 * @param $out Object: instance of OutputPage
434 function outputPage( OutputPage
$out ) {
435 global $wgDebugComments;
436 wfProfileIn( __METHOD__
);
439 $this->initPage( $out );
441 // See self::afterContentHook() for documentation
442 $afterContent = $this->afterContentHook();
444 $out->out( $out->headElement( $this ) );
446 if ( $wgDebugComments ) {
447 $out->out( "<!-- Wiki debugging output:\n" .
448 $out->mDebugtext
. "-->\n" );
451 $out->out( $this->beforeContent() );
453 $out->out( $out->mBodytext
. "\n" );
455 $out->out( $this->afterContent() );
457 $out->out( $afterContent );
459 $out->out( $this->bottomScripts( $out ) );
461 $out->out( wfReportTime() );
463 $out->out( "\n</body></html>" );
464 wfProfileOut( __METHOD__
);
467 static function makeVariablesScript( $data ) {
469 return Html
::inlineScript(
470 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
478 * Make a <script> tag containing global variables
479 * @param $skinName string Name of the skin
480 * The odd calling convention is for backwards compatibility
481 * @todo FIXME: Make this not depend on $wgTitle!
483 * Do not add things here which can be evaluated in ResourceLoaderStartupScript - in other words, without state.
484 * You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes.
486 static function makeGlobalVariablesScript( $skinName ) {
487 global $wgTitle, $wgUser, $wgRequest, $wgArticle, $wgOut, $wgRestrictionTypes, $wgUseAjax, $wgEnableMWSuggest;
489 $ns = $wgTitle->getNamespace();
490 $nsname = MWNamespace
::exists( $ns ) ? MWNamespace
::getCanonicalName( $ns ) : $wgTitle->getNsText();
492 'wgCanonicalNamespace' => $nsname,
493 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
494 SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
495 'wgNamespaceNumber' => $wgTitle->getNamespace(),
496 'wgPageName' => $wgTitle->getPrefixedDBKey(),
497 'wgTitle' => $wgTitle->getText(),
498 'wgAction' => $wgRequest->getText( 'action', 'view' ),
499 'wgArticleId' => $wgTitle->getArticleId(),
500 'wgIsArticle' => $wgOut->isArticle(),
501 'wgUserName' => $wgUser->isAnon() ?
null : $wgUser->getName(),
502 'wgUserGroups' => $wgUser->getEffectiveGroups(),
503 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
504 'wgCategories' => $wgOut->getCategories(),
506 foreach ( $wgRestrictionTypes as $type ) {
507 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
509 if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
510 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
513 // Allow extensions to add their custom variables to the global JS variables
514 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
516 return self
::makeVariablesScript( $vars );
520 * To make it harder for someone to slip a user a fake
521 * user-JavaScript or user-CSS preview, a random token
522 * is associated with the login session. If it's not
523 * passed back with the preview request, we won't render
526 * @param $action String: 'edit', 'submit' etc.
529 public function userCanPreview( $action ) {
530 global $wgRequest, $wgUser;
532 if ( $action != 'submit' ) {
535 if ( !$wgRequest->wasPosted() ) {
538 if ( !$this->mTitle
->userCanEditCssSubpage() ) {
541 if ( !$this->mTitle
->userCanEditJsSubpage() ) {
545 return $wgUser->matchEditToken(
546 $wgRequest->getVal( 'wpEditToken' ) );
550 * Generated JavaScript action=raw&gen=js
551 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
552 * nated together. For some bizarre reason, it does *not* return any
553 * custom user JS from subpages. Huh?
555 * There's absolutely no reason to have separate Monobook/Common JSes.
556 * Any JS that cares can just check the skin variable generated at the
557 * top. For now Monobook.js will be maintained, but it should be consi-
560 * @param $skinName String: If set, overrides the skin name
563 public function generateUserJs( $skinName = null ) {
565 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
571 * Generate user stylesheet for action=raw&gen=css
573 public function generateUserStylesheet() {
575 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
581 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
582 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
584 protected function reallyGenerateUserStylesheet() {
586 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
594 function setupUserCss( OutputPage
$out ) {
596 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
598 wfProfileIn( __METHOD__
);
600 $this->setupSkinUserCss( $out );
601 // Add any extension CSS
602 foreach ( $out->getExtStyle() as $url ) {
603 $out->addStyle( $url );
606 // Per-site custom styles
607 if ( $wgUseSiteCss ) {
608 $out->addModuleStyles( 'site' );
611 // Per-user custom styles
612 if ( $wgAllowUserCss ) {
613 if ( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
614 // @FIXME: properly escape the cdata!
615 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
617 $out->addModuleStyles( 'user' );
621 // Per-user preference styles
622 if ( $wgAllowUserCssPrefs ) {
623 $out->addModuleStyles( 'user.options' );
626 wfProfileOut( __METHOD__
);
630 * Get the query to generate a dynamic stylesheet
634 public static function getDynamicStylesheetQuery() {
635 global $wgSquidMaxage;
639 'maxage' => $wgSquidMaxage,
640 'usemsgcache' => 'yes',
641 'ctype' => 'text/css',
642 'smaxage' => $wgSquidMaxage,
647 * Add skin specific stylesheets
648 * @param $out OutputPage
650 function setupSkinUserCss( OutputPage
$out ) {
651 $out->addModuleStyles( 'mediawiki.legacy.shared' );
652 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
653 // TODO: When converting old skins to use ResourceLoader (or removing them) the following should be reconsidered
654 $out->addStyle( $this->getStylesheet() );
655 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
658 function getPageClasses( $title ) {
659 $numeric = 'ns-' . $title->getNamespace();
661 if ( $title->getNamespace() == NS_SPECIAL
) {
662 $type = 'ns-special';
663 } elseif ( $title->isTalkPage() ) {
666 $type = 'ns-subject';
669 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
671 return "$numeric $type $name";
675 * This will be called by OutputPage::headElement when it is creating the
676 * <body> tag, skins can override it if they have a need to add in any
677 * body attributes or classes of their own.
679 function addToBodyAttributes( $out, &$bodyAttrs ) {
680 // does nothing by default
692 * This will be called immediately after the <body> tag. Split into
693 * two functions to make it easier to subclass.
695 function beforeContent() {
696 return $this->doBeforeContent();
699 function doBeforeContent() {
701 wfProfileIn( __METHOD__
);
704 $qb = $this->qbSetting();
706 $langlinks = $this->otherLanguages();
713 $borderhack = 'class="top"';
716 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
717 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
719 $shove = ( $qb != 0 );
720 $left = ( $qb == 1 ||
$qb == 3 );
722 if ( $wgContLang->isRTL() ) {
727 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
728 $this->logoText() . '</td>';
730 $s .= $this->getQuickbarCompensator( $rows );
733 $l = $wgContLang->alignStart();
734 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
736 $s .= $this->topLinks();
737 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
739 $r = $wgContLang->alignEnd();
740 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
741 $s .= $this->nameAndLogin();
742 $s .= "\n<br />" . $this->searchForm() . '</td>';
745 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
748 if ( $shove && !$left ) { # Right
749 $s .= $this->getQuickbarCompensator( $rows );
752 $s .= "</tr>\n</table>\n</div>\n";
753 $s .= "\n<div id='article'>\n";
755 $notice = wfGetSiteNotice();
758 $s .= "\n<div id='siteNotice'>$notice</div>\n";
760 $s .= $this->pageTitle();
761 $s .= $this->pageSubtitle();
762 $s .= $this->getCategories();
764 wfProfileOut( __METHOD__
);
768 function getCategoryLinks() {
769 global $wgOut, $wgUseCategoryBrowser;
770 global $wgContLang, $wgUser;
772 if ( count( $wgOut->mCategoryLinks
) == 0 ) {
777 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
779 // Use Unicode bidi embedding override characters,
780 // to make sure links don't smash each other up in ugly ways.
781 $dir = $wgContLang->getDir();
782 $embed = "<span dir='$dir'>";
785 $allCats = $wgOut->getCategoryLinks();
787 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
789 if ( !empty( $allCats['normal'] ) ) {
790 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
792 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
793 $s .= '<div id="mw-normal-catlinks">' .
794 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
795 . $colon . $t . '</div>';
799 if ( isset( $allCats['hidden'] ) ) {
800 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
801 $class = 'mw-hidden-cats-user-shown';
802 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
803 $class = 'mw-hidden-cats-ns-shown';
805 $class = 'mw-hidden-cats-hidden';
808 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
809 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
810 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
814 # optional 'dmoz-like' category browser. Will be shown under the list
815 # of categories an article belong to
816 if ( $wgUseCategoryBrowser ) {
817 $s .= '<br /><hr />';
819 # get a big array of the parents tree
820 $parenttree = $this->mTitle
->getParentCategoryTree();
821 # Skin object passed by reference cause it can not be
822 # accessed under the method subfunction drawCategoryBrowser
823 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
824 # Clean out bogus first entry and sort them
825 unset( $tempout[0] );
827 # Output one per line
828 $s .= implode( "<br />\n", $tempout );
835 * Render the array as a serie of links.
836 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
837 * @param &skin Object: skin passed by reference
838 * @return String separated by >, terminate with "\n"
840 function drawCategoryBrowser( $tree, &$skin ) {
843 foreach ( $tree as $element => $parent ) {
844 if ( empty( $parent ) ) {
845 # element start a new list
848 # grab the others elements
849 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' > ';
852 # add our current element to the list
853 $eltitle = Title
::newFromText( $element );
854 $return .= $skin->link( $eltitle, $eltitle->getText() );
860 function getCategories() {
861 $catlinks = $this->getCategoryLinks();
863 $classes = 'catlinks';
865 global $wgOut, $wgUser;
867 // Check what we're showing
868 $allCats = $wgOut->getCategoryLinks();
869 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
870 $this->mTitle
->getNamespace() == NS_CATEGORY
;
872 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
873 $classes .= ' catlinks-allhidden';
876 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
879 function getQuickbarCompensator( $rows = 1 ) {
880 return "<td width='152' rowspan='{$rows}'> </td>";
884 * This runs a hook to allow extensions placing their stuff after content
885 * and article metadata (e.g. categories).
886 * Note: This function has nothing to do with afterContent().
888 * This hook is placed here in order to allow using the same hook for all
889 * skins, both the SkinTemplate based ones and the older ones, which directly
890 * use this class to get their data.
892 * The output of this function gets processed in SkinTemplate::outputPage() for
893 * the SkinTemplate based skins, all other skins should directly echo it.
895 * Returns an empty string by default, if not changed by any hook function.
897 protected function afterContentHook() {
900 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
901 // adding just some spaces shouldn't toggle the output
902 // of the whole <div/>, so we use trim() here
903 if ( trim( $data ) != '' ) {
904 // Doing this here instead of in the skins to
905 // ensure that the div has the same ID in all
907 $data = "<div id='mw-data-after-content'>\n" .
912 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
919 * Generate debug data HTML for displaying at the bottom of the main content
921 * @return String HTML containing debug data, if enabled (otherwise empty).
923 protected function generateDebugHTML() {
924 global $wgShowDebug, $wgOut;
926 if ( $wgShowDebug ) {
927 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext
);
928 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
929 $listInternals . "</ul>\n";
935 private function formatDebugHTML( $debugText ) {
936 $lines = explode( "\n", $debugText );
940 foreach ( $lines as $line ) {
941 $display = ltrim( $line );
942 $ident = strlen( $line ) - strlen( $display );
943 $diff = $ident - $curIdent;
945 if ( $display == '' ) {
946 $display = "\xc2\xa0";
949 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
952 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
954 $display = htmlspecialchars( $display );
958 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
959 } elseif ( $diff == 0 ) {
960 $ret .= "</li><li>\n";
962 $ret .= str_repeat( "<ul><li>\n", $diff );
964 $ret .= $display . "\n";
969 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
975 * This gets called shortly before the </body> tag.
976 * @return String HTML to be put before </body>
978 function afterContent() {
979 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
980 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
984 * This gets called shortly before the </body> tag.
985 * @param $out OutputPage object
986 * @return String HTML-wrapped JS code to be put before </body>
988 function bottomScripts( $out ) {
989 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
990 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
992 return $bottomScriptText;
995 /** @return string Retrievied from HTML text */
996 function printSource() {
997 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
998 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
1001 function printFooter() {
1002 return "<p>" . $this->printSource() .
1003 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
1006 /** overloaded by derived classes */
1007 function doAfterContent() {
1008 return '</div></div>';
1011 function pageTitleLinks() {
1012 global $wgOut, $wgUser, $wgRequest, $wgLang;
1014 $oldid = $wgRequest->getVal( 'oldid' );
1015 $diff = $wgRequest->getVal( 'diff' );
1016 $action = $wgRequest->getText( 'action' );
1018 $s[] = $this->printableLink();
1019 $disclaimer = $this->disclaimerLink(); # may be empty
1021 if ( $disclaimer ) {
1025 $privacy = $this->privacyLink(); # may be empty too
1031 if ( $wgOut->isArticleRelated() ) {
1032 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
1033 $name = $this->mTitle
->getDBkey();
1034 $image = wfFindFile( $this->mTitle
);
1037 $link = htmlspecialchars( $image->getURL() );
1038 $style = $this->getInternalLinkAttributes( $link, $name );
1039 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1044 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
1045 $s[] .= $this->link(
1047 wfMsg( 'currentrev' ),
1050 array( 'known', 'noclasses' )
1054 if ( $wgUser->getNewtalk() ) {
1055 # do not show "You have new messages" text when we are viewing our
1057 if ( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1059 $wgUser->getTalkPage(),
1060 wfMsgHtml( 'newmessageslink' ),
1062 array( 'redirect' => 'no' ),
1063 array( 'known', 'noclasses' )
1067 $wgUser->getTalkPage(),
1068 wfMsgHtml( 'newmessagesdifflink' ),
1070 array( 'diff' => 'cur' ),
1071 array( 'known', 'noclasses' )
1073 $s[] = '<strong>' . wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1075 $wgOut->setSquidMaxage( 0 );
1076 $wgOut->enableClientCache( false );
1080 $undelete = $this->getUndeleteLink();
1082 if ( !empty( $undelete ) ) {
1086 return $wgLang->pipeList( $s );
1089 function getUndeleteLink() {
1090 global $wgUser, $wgLang, $wgRequest;
1092 $action = $wgRequest->getVal( 'action', 'view' );
1094 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1095 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1096 $n = $this->mTitle
->isDeleted();
1099 if ( $wgUser->isAllowed( 'undelete' ) ) {
1100 $msg = 'thisisdeleted';
1102 $msg = 'viewdeleted';
1108 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1109 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1112 array( 'known', 'noclasses' )
1121 function printableLink() {
1122 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1126 if ( !$wgOut->isPrintable() ) {
1127 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1128 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1131 if ( $wgOut->isSyndicated() ) {
1132 foreach ( $wgFeedClasses as $format => $class ) {
1133 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1134 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1135 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1138 return $wgLang->pipeList( $s );
1142 * Gets the h1 element with the page title.
1145 function pageTitle() {
1147 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1151 function pageSubtitle() {
1154 $sub = $wgOut->getSubtitle();
1157 global $wgExtraSubtitle;
1158 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1161 $subpages = $this->subPageSubtitle();
1162 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1163 $s = "<p class='subtitle'>{$sub}</p>\n";
1168 function subPageSubtitle() {
1171 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this ) ) ) {
1177 if ( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1178 $ptext = $this->mTitle
->getPrefixedText();
1179 if ( preg_match( '/\//', $ptext ) ) {
1180 $links = explode( '/', $ptext );
1181 array_pop( $links );
1186 foreach ( $links as $link ) {
1187 $growinglink .= $link;
1189 $linkObj = Title
::newFromText( $growinglink );
1191 if ( is_object( $linkObj ) && $linkObj->exists() ) {
1192 $getlink = $this->link(
1194 htmlspecialchars( $display ),
1197 array( 'known', 'noclasses' )
1203 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1205 $subpages .= '< ';
1208 $subpages .= $getlink;
1213 $growinglink .= '/';
1222 * Returns true if the IP should be shown in the header
1224 function showIPinHeader() {
1225 global $wgShowIPinHeader;
1226 return $wgShowIPinHeader && session_id() != '';
1229 function nameAndLogin() {
1230 global $wgUser, $wgLang, $wgContLang;
1232 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1236 if ( $wgUser->isAnon() ) {
1237 if ( $this->showIPinHeader() ) {
1240 $talkLink = $this->link( $wgUser->getTalkPage(),
1241 $wgLang->getNsText( NS_TALK
) );
1243 $ret .= "$name ($talkLink)";
1245 $ret .= wfMsg( 'notloggedin' );
1248 $returnTo = $this->mTitle
->getPrefixedDBkey();
1251 if ( $logoutPage != $returnTo ) {
1252 $query['returnto'] = $returnTo;
1255 $loginlink = $wgUser->isAllowed( 'createaccount' )
1256 ?
'nav-login-createaccount'
1258 $ret .= "\n<br />" . $this->link(
1259 SpecialPage
::getTitleFor( 'Userlogin' ),
1260 wfMsg( $loginlink ), array(), $query
1263 $returnTo = $this->mTitle
->getPrefixedDBkey();
1264 $talkLink = $this->link( $wgUser->getTalkPage(),
1265 $wgLang->getNsText( NS_TALK
) );
1267 $ret .= $this->link( $wgUser->getUserPage(),
1268 htmlspecialchars( $wgUser->getName() ) );
1269 $ret .= " ($talkLink)<br />";
1270 $ret .= $wgLang->pipeList( array(
1272 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1273 array(), array( 'returnto' => $returnTo )
1275 $this->specialLink( 'Preferences' ),
1279 $ret = $wgLang->pipeList( array(
1282 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1290 function getSearchLink() {
1291 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1292 return $searchPage->getLocalURL();
1295 function escapeSearchLink() {
1296 return htmlspecialchars( $this->getSearchLink() );
1299 function searchForm() {
1300 global $wgRequest, $wgUseTwoButtonsSearchForm;
1302 $search = $wgRequest->getText( 'search' );
1304 $s = '<form id="searchform' . $this->searchboxes
. '" name="search" class="inline" method="post" action="'
1305 . $this->escapeSearchLink() . "\">\n"
1306 . '<input type="text" id="searchInput' . $this->searchboxes
. '" name="search" size="19" value="'
1307 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1308 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1310 if ( $wgUseTwoButtonsSearchForm ) {
1311 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1313 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1318 // Ensure unique id's for search boxes made after the first
1319 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1324 function topLinks() {
1328 $this->mainPageLink(),
1329 $this->specialLink( 'Recentchanges' )
1332 if ( $wgOut->isArticleRelated() ) {
1333 $s[] = $this->editThisPage();
1334 $s[] = $this->historyLink();
1337 # Many people don't like this dropdown box
1338 # $s[] = $this->specialPagesList();
1340 if ( $this->variantLinks() ) {
1341 $s[] = $this->variantLinks();
1344 if ( $this->extensionTabLinks() ) {
1345 $s[] = $this->extensionTabLinks();
1348 // @todo FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1349 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1353 * Compatibility for extensions adding functionality through tabs.
1354 * Eventually these old skins should be replaced with SkinTemplate-based
1358 function extensionTabLinks() {
1362 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1363 foreach ( $tabs as $tab ) {
1364 $s[] = Xml
::element( 'a',
1365 array( 'href' => $tab['href'] ),
1369 if ( count( $s ) ) {
1372 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1373 $out .= $wgLang->pipeList( $s );
1380 * Language/charset variant links for classic-style skins
1383 function variantLinks() {
1386 /* show links to different language variants */
1387 global $wgDisableLangConversion, $wgLang, $wgContLang;
1389 $variants = $wgContLang->getVariants();
1391 if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1392 foreach ( $variants as $code ) {
1393 $varname = $wgContLang->getVariantname( $code );
1395 if ( $varname == 'disable' ) {
1398 $s = $wgLang->pipeList( array(
1400 '<a href="' . $this->mTitle
->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1408 function bottomLinks() {
1409 global $wgOut, $wgUser, $wgUseTrackbacks;
1410 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1413 if ( $wgOut->isArticleRelated() ) {
1414 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1416 if ( $wgUser->isLoggedIn() ) {
1417 $element[] = $this->watchThisPage();
1420 $element[] = $this->talkLink();
1421 $element[] = $this->historyLink();
1422 $element[] = $this->whatLinksHere();
1423 $element[] = $this->watchPageLinksLink();
1425 if ( $wgUseTrackbacks ) {
1426 $element[] = $this->trackbackLink();
1430 $this->mTitle
->getNamespace() == NS_USER ||
1431 $this->mTitle
->getNamespace() == NS_USER_TALK
1433 $id = User
::idFromName( $this->mTitle
->getText() );
1434 $ip = User
::isIP( $this->mTitle
->getText() );
1436 # Both anons and non-anons have contributions list
1438 $element[] = $this->userContribsLink();
1441 if ( $this->showEmailUser( $id ) ) {
1442 $element[] = $this->emailUserLink();
1446 $s = implode( $element, $sep );
1448 if ( $this->mTitle
->getArticleId() ) {
1451 // Delete/protect/move links for privileged users
1452 if ( $wgUser->isAllowed( 'delete' ) ) {
1453 $s .= $this->deleteThisPage();
1456 if ( $wgUser->isAllowed( 'protect' ) ) {
1457 $s .= $sep . $this->protectThisPage();
1460 if ( $wgUser->isAllowed( 'move' ) ) {
1461 $s .= $sep . $this->moveThisPage();
1465 $s .= "<br />\n" . $this->otherLanguages();
1471 function pageStats() {
1472 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1473 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1475 $oldid = $wgRequest->getVal( 'oldid' );
1476 $diff = $wgRequest->getVal( 'diff' );
1478 if ( !$wgOut->isArticle() ) {
1482 if ( !$wgArticle instanceof Article
) {
1486 if ( isset( $oldid ) ||
isset( $diff ) ) {
1490 if ( 0 == $wgArticle->getID() ) {
1496 if ( !$wgDisableCounters ) {
1497 $count = $wgLang->formatNum( $wgArticle->getCount() );
1500 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1504 if ( $wgMaxCredits != 0 ) {
1505 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1507 $s .= $this->lastModified();
1510 if ( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1511 $dbr = wfGetDB( DB_SLAVE
);
1512 $res = $dbr->select(
1514 array( 'COUNT(*) AS n' ),
1516 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ),
1517 'wl_namespace' => $this->mTitle
->getNamespace()
1521 $x = $dbr->fetchObject( $res );
1523 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1524 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1528 return $s . ' ' . $this->getCopyright();
1531 function getCopyright( $type = 'detect' ) {
1532 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1534 if ( $type == 'detect' ) {
1535 $diff = $wgRequest->getVal( 'diff' );
1536 $isCur = $wgArticle && $wgArticle->isCurrent();
1538 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1545 if ( $type == 'history' ) {
1546 $msg = 'history_copyright';
1553 if ( $wgRightsPage ) {
1554 $title = Title
::newFromText( $wgRightsPage );
1555 $link = $this->linkKnown( $title, $wgRightsText );
1556 } elseif ( $wgRightsUrl ) {
1557 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1558 } elseif ( $wgRightsText ) {
1559 $link = $wgRightsText;
1565 // Allow for site and per-namespace customization of copyright notice.
1568 if ( isset( $wgArticle ) ) {
1569 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link, &$forContent ) );
1572 if ( $forContent ) {
1573 $out .= wfMsgForContent( $msg, $link );
1575 $out .= wfMsg( $msg, $link );
1581 function getCopyrightIcon() {
1582 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1586 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1587 $out = $wgCopyrightIcon;
1588 } elseif ( $wgRightsIcon ) {
1589 $icon = htmlspecialchars( $wgRightsIcon );
1591 if ( $wgRightsUrl ) {
1592 $url = htmlspecialchars( $wgRightsUrl );
1593 $out .= '<a href="' . $url . '">';
1596 $text = htmlspecialchars( $wgRightsText );
1597 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1599 if ( $wgRightsUrl ) {
1608 * Gets the powered by MediaWiki icon.
1611 function getPoweredBy() {
1612 global $wgStylePath;
1614 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1615 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1616 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
1620 function lastModified() {
1621 global $wgLang, $wgArticle;
1623 if ( $this->mRevisionId
&& $this->mRevisionId
!= $wgArticle->getLatest() ) {
1624 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1626 $timestamp = $wgArticle->getTimestamp();
1630 $d = $wgLang->date( $timestamp, true );
1631 $t = $wgLang->time( $timestamp, true );
1632 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1637 if ( wfGetLB()->getLaggedSlaveMode() ) {
1638 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1644 function logoText( $align = '' ) {
1645 if ( $align != '' ) {
1646 $a = " align='{$align}'";
1651 $mp = wfMsg( 'mainpage' );
1652 $mptitle = Title
::newMainPage();
1653 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1655 $logourl = $this->getLogo();
1656 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1662 * Show a drop-down box of special pages
1664 function specialPagesList() {
1665 global $wgContLang, $wgServer, $wgRedirectScript;
1667 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1669 foreach ( $pages as $name => $page ) {
1670 $pages[$name] = $page->getDescription();
1673 $go = wfMsg( 'go' );
1674 $sp = wfMsg( 'specialpages' );
1675 $spp = $wgContLang->specialPage( 'Specialpages' );
1677 $s = '<form id="specialpages" method="get" ' .
1678 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1679 $s .= "<select name=\"wpDropdown\">\n";
1680 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1683 foreach ( $pages as $name => $desc ) {
1684 $p = $wgContLang->specialPage( $name );
1685 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1688 $s .= "</select>\n";
1689 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1696 * Renders a $wgFooterIcons icon acording to the method's arguments
1697 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
1698 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
1700 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
1701 if ( is_string( $icon ) ) {
1703 } else { // Assuming array
1704 $url = $icon["url"];
1705 unset( $icon["url"] );
1706 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
1707 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1709 $html = htmlspecialchars( $icon["alt"] );
1712 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
1719 * Gets the link to the wiki's main page.
1722 function mainPageLink() {
1724 Title
::newMainPage(),
1725 wfMsg( 'mainpage' ),
1728 array( 'known', 'noclasses' )
1734 public function footerLink( $desc, $page ) {
1735 // if the link description has been set to "-" in the default language,
1736 if ( wfMsgForContent( $desc ) == '-' ) {
1737 // then it is disabled, for all languages.
1740 // Otherwise, we display the link for the user, described in their
1741 // language (which may or may not be the same as the default language),
1742 // but we make the link target be the one site-wide page.
1743 $title = Title
::newFromText( wfMsgForContent( $page ) );
1745 return $this->linkKnown(
1747 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1753 * Gets the link to the wiki's privacy policy page.
1755 function privacyLink() {
1756 return $this->footerLink( 'privacy', 'privacypage' );
1760 * Gets the link to the wiki's about page.
1762 function aboutLink() {
1763 return $this->footerLink( 'aboutsite', 'aboutpage' );
1767 * Gets the link to the wiki's general disclaimers page.
1769 function disclaimerLink() {
1770 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1773 function editThisPage() {
1776 if ( !$wgOut->isArticleRelated() ) {
1777 $s = wfMsg( 'protectedpage' );
1779 if ( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1780 $t = wfMsg( 'editthispage' );
1781 } elseif ( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1782 $t = wfMsg( 'create-this-page' );
1784 $t = wfMsg( 'viewsource' );
1791 $this->editUrlOptions(),
1792 array( 'known', 'noclasses' )
1800 * Return URL options for the 'edit page' link.
1801 * This may include an 'oldid' specifier, if the current page view is such.
1806 function editUrlOptions() {
1809 $options = array( 'action' => 'edit' );
1811 if ( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1812 $options['oldid'] = intval( $this->mRevisionId
);
1818 function deleteThisPage() {
1819 global $wgUser, $wgRequest;
1821 $diff = $wgRequest->getVal( 'diff' );
1823 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1824 $t = wfMsg( 'deletethispage' );
1830 array( 'action' => 'delete' ),
1831 array( 'known', 'noclasses' )
1840 function protectThisPage() {
1841 global $wgUser, $wgRequest;
1843 $diff = $wgRequest->getVal( 'diff' );
1845 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
1846 if ( $this->mTitle
->isProtected() ) {
1847 $text = wfMsg( 'unprotectthispage' );
1848 $query = array( 'action' => 'unprotect' );
1850 $text = wfMsg( 'protectthispage' );
1851 $query = array( 'action' => 'protect' );
1859 array( 'known', 'noclasses' )
1868 function watchThisPage() {
1870 ++
$this->mWatchLinkNum
;
1872 if ( $wgOut->isArticleRelated() ) {
1873 if ( $this->mTitle
->userIsWatching() ) {
1874 $text = wfMsg( 'unwatchthispage' );
1875 $query = array( 'action' => 'unwatch' );
1876 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1878 $text = wfMsg( 'watchthispage' );
1879 $query = array( 'action' => 'watch' );
1880 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1886 array( 'id' => $id ),
1888 array( 'known', 'noclasses' )
1891 $s = wfMsg( 'notanarticle' );
1897 function moveThisPage() {
1898 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1900 SpecialPage
::getTitleFor( 'Movepage' ),
1901 wfMsg( 'movethispage' ),
1903 array( 'target' => $this->mTitle
->getPrefixedDBkey() ),
1904 array( 'known', 'noclasses' )
1907 // no message if page is protected - would be redundant
1912 function historyLink() {
1915 wfMsgHtml( 'history' ),
1916 array( 'rel' => 'archives' ),
1917 array( 'action' => 'history' )
1921 function whatLinksHere() {
1923 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1924 wfMsgHtml( 'whatlinkshere' ),
1927 array( 'known', 'noclasses' )
1931 function userContribsLink() {
1933 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1934 wfMsgHtml( 'contributions' ),
1937 array( 'known', 'noclasses' )
1941 function showEmailUser( $id ) {
1943 $targetUser = User
::newFromId( $id );
1944 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1945 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1948 function emailUserLink() {
1950 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1951 wfMsg( 'emailuser' ),
1954 array( 'known', 'noclasses' )
1958 function watchPageLinksLink() {
1961 if ( !$wgOut->isArticleRelated() ) {
1962 return '(' . wfMsg( 'notanarticle' ) . ')';
1965 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1966 wfMsg( 'recentchangeslinked-toolbox' ),
1969 array( 'known', 'noclasses' )
1974 function trackbackLink() {
1975 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1976 . wfMsg( 'trackbacklink' ) . '</a>';
1979 function otherLanguages() {
1980 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1982 if ( $wgHideInterlanguageLinks ) {
1986 $a = $wgOut->getLanguageLinks();
1988 if ( 0 == count( $a ) ) {
1992 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1995 if ( $wgContLang->isRTL() ) {
1996 $s .= '<span dir="LTR">';
1999 foreach ( $a as $l ) {
2001 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
2006 $nt = Title
::newFromText( $l );
2007 $url = $nt->escapeFullURL();
2008 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
2009 $title = htmlspecialchars( $nt->getText() );
2011 if ( $text == '' ) {
2015 $style = $this->getExternalLinkAttributes();
2016 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
2019 if ( $wgContLang->isRTL() ) {
2026 function talkLink() {
2027 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
2028 # No discussion links for special pages
2032 $linkOptions = array();
2034 if ( $this->mTitle
->isTalkPage() ) {
2035 $link = $this->mTitle
->getSubjectPage();
2036 switch( $link->getNamespace() ) {
2038 $text = wfMsg( 'articlepage' );
2041 $text = wfMsg( 'userpage' );
2044 $text = wfMsg( 'projectpage' );
2047 $text = wfMsg( 'imagepage' );
2048 # Make link known if image exists, even if the desc. page doesn't.
2049 if ( wfFindFile( $link ) )
2050 $linkOptions[] = 'known';
2053 $text = wfMsg( 'mediawikipage' );
2056 $text = wfMsg( 'templatepage' );
2059 $text = wfMsg( 'viewhelppage' );
2062 $text = wfMsg( 'categorypage' );
2065 $text = wfMsg( 'articlepage' );
2068 $link = $this->mTitle
->getTalkPage();
2069 $text = wfMsg( 'talkpage' );
2072 $s = $this->link( $link, $text, array(), array(), $linkOptions );
2077 function commentLink() {
2080 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
2084 # __NEWSECTIONLINK___ changes behaviour here
2085 # If it is present, the link points to this page, otherwise
2086 # it points to the talk page
2087 if ( $this->mTitle
->isTalkPage() ) {
2088 $title = $this->mTitle
;
2089 } elseif ( $wgOut->showNewSectionLink() ) {
2090 $title = $this->mTitle
;
2092 $title = $this->mTitle
->getTalkPage();
2097 wfMsg( 'postcomment' ),
2103 array( 'known', 'noclasses' )
2107 function getUploadLink() {
2108 global $wgUploadNavigationUrl;
2110 if ( $wgUploadNavigationUrl ) {
2111 # Using an empty class attribute to avoid automatic setting of "external" class
2112 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '' ) );
2115 SpecialPage
::getTitleFor( 'Upload' ),
2116 wfMsgHtml( 'upload' ),
2119 array( 'known', 'noclasses' )
2125 * Return a fully resolved style path url to images or styles stored in the common folder.
2126 * This method returns a url resolved using the configured skin style path
2127 * and includes the style version inside of the url.
2128 * @param $name String: The name or path of a skin resource file
2129 * @return String The fully resolved style path url including styleversion
2131 function getCommonStylePath( $name ) {
2132 global $wgStylePath, $wgStyleVersion;
2133 return "$wgStylePath/common/$name?$wgStyleVersion";
2137 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
2138 * This method returns a url resolved using the configured skin style path
2139 * and includes the style version inside of the url.
2140 * @param $name String: The name or path of a skin resource file
2141 * @return String The fully resolved style path url including styleversion
2143 function getSkinStylePath( $name ) {
2144 global $wgStylePath, $wgStyleVersion;
2145 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
2148 /* these are used extensively in SkinTemplate, but also some other places */
2149 static function makeMainPageUrl( $urlaction = '' ) {
2150 $title = Title
::newMainPage();
2151 self
::checkTitle( $title, '' );
2153 return $title->getLocalURL( $urlaction );
2156 static function makeSpecialUrl( $name, $urlaction = '' ) {
2157 $title = SpecialPage
::getTitleFor( $name );
2158 return $title->getLocalURL( $urlaction );
2161 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2162 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
2163 return $title->getLocalURL( $urlaction );
2166 static function makeI18nUrl( $name, $urlaction = '' ) {
2167 $title = Title
::newFromText( wfMsgForContent( $name ) );
2168 self
::checkTitle( $title, $name );
2169 return $title->getLocalURL( $urlaction );
2172 static function makeUrl( $name, $urlaction = '' ) {
2173 $title = Title
::newFromText( $name );
2174 self
::checkTitle( $title, $name );
2176 return $title->getLocalURL( $urlaction );
2180 * If url string starts with http, consider as external URL, else
2183 static function makeInternalOrExternalUrl( $name ) {
2184 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2187 return self
::makeUrl( $name );
2191 # this can be passed the NS number as defined in Language.php
2192 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
2193 $title = Title
::makeTitleSafe( $namespace, $name );
2194 self
::checkTitle( $title, $name );
2196 return $title->getLocalURL( $urlaction );
2199 /* these return an array with the 'href' and boolean 'exists' */
2200 static function makeUrlDetails( $name, $urlaction = '' ) {
2201 $title = Title
::newFromText( $name );
2202 self
::checkTitle( $title, $name );
2205 'href' => $title->getLocalURL( $urlaction ),
2206 'exists' => $title->getArticleID() != 0,
2211 * Make URL details where the article exists (or at least it's convenient to think so)
2213 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2214 $title = Title
::newFromText( $name );
2215 self
::checkTitle( $title, $name );
2218 'href' => $title->getLocalURL( $urlaction ),
2223 # make sure we have some title to operate on
2224 static function checkTitle( &$title, $name ) {
2225 if ( !is_object( $title ) ) {
2226 $title = Title
::newFromText( $name );
2227 if ( !is_object( $title ) ) {
2228 $title = Title
::newFromText( '--error: link target missing--' );
2234 * Build an array that represents the sidebar(s), the navigation bar among them
2238 function buildSidebar() {
2239 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2241 wfProfileIn( __METHOD__
);
2243 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2245 if ( $wgEnableSidebarCache ) {
2246 $cachedsidebar = $parserMemc->get( $key );
2247 if ( $cachedsidebar ) {
2248 wfProfileOut( __METHOD__
);
2249 return $cachedsidebar;
2254 $this->addToSidebar( $bar, 'sidebar' );
2256 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2257 if ( $wgEnableSidebarCache ) {
2258 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2261 wfProfileOut( __METHOD__
);
2265 * Add content from a sidebar system message
2266 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2268 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2270 * @param &$bar array
2271 * @param $message String
2273 function addToSidebar( &$bar, $message ) {
2274 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2278 * Add content from plain text
2280 * @param &$bar array
2281 * @param $text string
2283 function addToSidebarPlain( &$bar, $text ) {
2284 $lines = explode( "\n", $text );
2285 $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.
2289 foreach ( $lines as $line ) {
2290 if ( strpos( $line, '*' ) !== 0 ) {
2294 if ( strpos( $line, '**' ) !== 0 ) {
2295 $heading = trim( $line, '* ' );
2296 if ( !array_key_exists( $heading, $bar ) ) {
2297 $bar[$heading] = array();
2300 $line = trim( $line, '* ' );
2302 if ( strpos( $line, '|' ) !== false ) { // sanity check
2303 $line = array_map( 'trim', explode( '|', $line, 2 ) );
2304 $link = wfMsgForContent( $line[0] );
2306 if ( $link == '-' ) {
2310 $text = wfMsgExt( $line[1], 'parsemag' );
2312 if ( wfEmptyMsg( $line[1], $text ) ) {
2316 if ( wfEmptyMsg( $line[0], $link ) ) {
2320 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2323 $title = Title
::newFromText( $link );
2326 $title = $title->fixSpecialName();
2327 $href = $title->getLocalURL();
2329 $href = 'INVALID-TITLE';
2333 $bar[$heading][] = array(
2336 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2339 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
2340 global $wgParser, $wgTitle;
2342 $line = substr( $line, 2, strlen( $line ) - 4 );
2344 $options = new ParserOptions();
2345 $options->setEditSection( false );
2346 $options->setInterfaceMessage( true );
2347 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $options )->getText();
2354 if ( count( $wikiBar ) > 0 ) {
2355 $bar = array_merge( $bar, $wikiBar );
2362 * Should we include common/wikiprintable.css? Skins that have their own
2363 * print stylesheet should override this and return false. (This is an
2364 * ugly hack to get Monobook to play nicely with
2365 * OutputPage::headElement().)
2369 public function commonPrintStylesheet() {
2374 * Gets new talk page messages for the current user.
2375 * @return MediaWiki message or if no new talk page messages, nothing
2377 function getNewtalks() {
2378 global $wgUser, $wgOut;
2380 $newtalks = $wgUser->getNewMessageLinks();
2383 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2384 $userTitle = $this->mUser
->getUserPage();
2385 $userTalkTitle = $userTitle->getTalkPage();
2387 if ( !$userTalkTitle->equals( $this->mTitle
) ) {
2388 $newMessagesLink = $this->link(
2390 wfMsgHtml( 'newmessageslink' ),
2392 array( 'redirect' => 'no' ),
2393 array( 'known', 'noclasses' )
2396 $newMessagesDiffLink = $this->link(
2398 wfMsgHtml( 'newmessagesdifflink' ),
2400 array( 'diff' => 'cur' ),
2401 array( 'known', 'noclasses' )
2405 'youhavenewmessages',
2407 $newMessagesDiffLink
2409 # Disable Squid cache
2410 $wgOut->setSquidMaxage( 0 );
2412 } elseif ( count( $newtalks ) ) {
2413 // _>" " for BC <= 1.16
2414 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2417 foreach ( $newtalks as $newtalk ) {
2418 $msgs[] = Xml
::element(
2420 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2423 $parts = implode( $sep, $msgs );
2424 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2425 $wgOut->setSquidMaxage( 0 );