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;
358 * Whether the revision displayed is the latest revision of the page
362 public function isRevisionCurrent() {
363 return $this->mRevisionId
== 0 ||
$this->mRevisionId
== $this->mTitle
->getLatestRevID();
368 * @param $t Title object to use
370 public function setTitle( $t ) {
375 public function getTitle() {
376 return $this->mTitle
;
380 * Set the "relevant" title
381 * @see self::getRelevantTitle()
382 * @param $t Title object to use
384 public function setRelevantTitle( $t ) {
385 $this->mRelevantTitle
= $t;
389 * Return the "relevant" title.
390 * A "relevant" title is not necessarily the actual title of the page.
391 * Special pages like Special:MovePage use set the page they are acting on
392 * as their "relevant" title, this allows the skin system to display things
393 * such as content tabs which belong to to that page instead of displaying
394 * a basic special page tab which has almost no meaning.
396 public function getRelevantTitle() {
397 if ( isset($this->mRelevantTitle
) ) {
398 return $this->mRelevantTitle
;
400 return $this->mTitle
;
404 * Set the "relevant" user
405 * @see self::getRelevantUser()
406 * @param $u User object to use
408 public function setRelevantUser( $u ) {
409 $this->mRelevantUser
= $u;
413 * Return the "relevant" user.
414 * A "relevant" user is similar to a relevant title. Special pages like
415 * Special:Contributions mark the user which they are relevant to so that
416 * things like the toolbox can display the information they usually are only
417 * able to display on a user's userpage and talkpage.
419 public function getRelevantUser() {
420 if ( isset($this->mRelevantUser
) ) {
421 return $this->mRelevantUser
;
423 $title = $this->getRelevantTitle();
424 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
425 $rootUser = strtok( $title->getText(), '/' );
426 if ( User
::isIP( $rootUser ) ) {
427 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
429 $user = User
::newFromName( $rootUser );
430 if ( $user->isLoggedIn() ) {
431 $this->mRelevantUser
= $user;
434 return $this->mRelevantUser
;
440 * Outputs the HTML generated by other functions.
441 * @param $out Object: instance of OutputPage
443 function outputPage( OutputPage
$out ) {
444 global $wgDebugComments;
445 wfProfileIn( __METHOD__
);
448 $this->initPage( $out );
450 // See self::afterContentHook() for documentation
451 $afterContent = $this->afterContentHook();
453 $out->out( $out->headElement( $this ) );
455 if ( $wgDebugComments ) {
456 $out->out( "<!-- Wiki debugging output:\n" .
457 $out->mDebugtext
. "-->\n" );
460 $out->out( $this->beforeContent() );
462 $out->out( $out->mBodytext
. "\n" );
464 $out->out( $this->afterContent() );
466 $out->out( $afterContent );
468 $out->out( $this->bottomScripts( $out ) );
470 $out->out( wfReportTime() );
472 $out->out( "\n</body></html>" );
473 wfProfileOut( __METHOD__
);
476 static function makeVariablesScript( $data ) {
478 return Html
::inlineScript(
479 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
487 * Make a <script> tag containing global variables
488 * @param $skinName string Name of the skin
489 * The odd calling convention is for backwards compatibility
490 * @todo FIXME: Make this not depend on $wgTitle!
492 * Do not add things here which can be evaluated in ResourceLoaderStartupScript - in other words, without state.
493 * You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes.
495 static function makeGlobalVariablesScript( $skinName ) {
496 global $wgTitle, $wgUser, $wgRequest, $wgOut, $wgUseAjax, $wgEnableMWSuggest;
498 $ns = $wgTitle->getNamespace();
499 $nsname = MWNamespace
::exists( $ns ) ? MWNamespace
::getCanonicalName( $ns ) : $wgTitle->getNsText();
501 'wgCanonicalNamespace' => $nsname,
502 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
503 SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
504 'wgNamespaceNumber' => $wgTitle->getNamespace(),
505 'wgPageName' => $wgTitle->getPrefixedDBKey(),
506 'wgTitle' => $wgTitle->getText(),
507 'wgAction' => $wgRequest->getText( 'action', 'view' ),
508 'wgArticleId' => $wgTitle->getArticleId(),
509 'wgIsArticle' => $wgOut->isArticle(),
510 'wgUserName' => $wgUser->isAnon() ?
null : $wgUser->getName(),
511 'wgUserGroups' => $wgUser->getEffectiveGroups(),
512 'wgCurRevisionId' => $wgTitle->getLatestRevID(),
513 'wgCategories' => $wgOut->getCategories(),
514 'wgBreakFrames' => $wgOut->getFrameOptions() == 'DENY',
516 foreach ( $wgTitle->getRestrictionTypes() as $type ) {
517 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
519 if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
520 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
523 // Allow extensions to add their custom variables to the global JS variables
524 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
526 return self
::makeVariablesScript( $vars );
530 * To make it harder for someone to slip a user a fake
531 * user-JavaScript or user-CSS preview, a random token
532 * is associated with the login session. If it's not
533 * passed back with the preview request, we won't render
536 * @param $action String: 'edit', 'submit' etc.
539 public function userCanPreview( $action ) {
540 global $wgRequest, $wgUser;
542 if ( $action != 'submit' ) {
545 if ( !$wgRequest->wasPosted() ) {
548 if ( !$this->mTitle
->userCanEditCssSubpage() ) {
551 if ( !$this->mTitle
->userCanEditJsSubpage() ) {
555 return $wgUser->matchEditToken(
556 $wgRequest->getVal( 'wpEditToken' ) );
560 * Generated JavaScript action=raw&gen=js
561 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
562 * nated together. For some bizarre reason, it does *not* return any
563 * custom user JS from subpages. Huh?
565 * There's absolutely no reason to have separate Monobook/Common JSes.
566 * Any JS that cares can just check the skin variable generated at the
567 * top. For now Monobook.js will be maintained, but it should be consi-
570 * @param $skinName String: If set, overrides the skin name
573 public function generateUserJs( $skinName = null ) {
575 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
581 * Generate user stylesheet for action=raw&gen=css
583 public function generateUserStylesheet() {
585 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
591 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
592 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
594 protected function reallyGenerateUserStylesheet() {
596 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
604 function setupUserCss( OutputPage
$out ) {
606 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
608 wfProfileIn( __METHOD__
);
610 $this->setupSkinUserCss( $out );
611 // Add any extension CSS
612 foreach ( $out->getExtStyle() as $url ) {
613 $out->addStyle( $url );
616 // Per-site custom styles
617 if ( $wgUseSiteCss ) {
618 $out->addModuleStyles( 'site' );
621 // Per-user custom styles
622 if ( $wgAllowUserCss ) {
623 if ( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
624 // @FIXME: properly escape the cdata!
625 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
627 $out->addModuleStyles( 'user' );
631 // Per-user preference styles
632 if ( $wgAllowUserCssPrefs ) {
633 $out->addModuleStyles( 'user.options' );
636 wfProfileOut( __METHOD__
);
640 * Get the query to generate a dynamic stylesheet
644 public static function getDynamicStylesheetQuery() {
645 global $wgSquidMaxage;
649 'maxage' => $wgSquidMaxage,
650 'usemsgcache' => 'yes',
651 'ctype' => 'text/css',
652 'smaxage' => $wgSquidMaxage,
657 * Add skin specific stylesheets
658 * @param $out OutputPage
660 function setupSkinUserCss( OutputPage
$out ) {
661 $out->addModuleStyles( 'mediawiki.legacy.shared' );
662 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
663 // TODO: When converting old skins to use ResourceLoader (or removing them) the following should be reconsidered
664 $out->addStyle( $this->getStylesheet() );
665 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
668 function getPageClasses( $title ) {
669 $numeric = 'ns-' . $title->getNamespace();
671 if ( $title->getNamespace() == NS_SPECIAL
) {
672 $type = 'ns-special';
673 } elseif ( $title->isTalkPage() ) {
676 $type = 'ns-subject';
679 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
681 return "$numeric $type $name";
685 * This will be called by OutputPage::headElement when it is creating the
686 * <body> tag, skins can override it if they have a need to add in any
687 * body attributes or classes of their own.
689 function addToBodyAttributes( $out, &$bodyAttrs ) {
690 // does nothing by default
702 * This will be called immediately after the <body> tag. Split into
703 * two functions to make it easier to subclass.
705 function beforeContent() {
706 return $this->doBeforeContent();
709 function doBeforeContent() {
711 wfProfileIn( __METHOD__
);
714 $qb = $this->qbSetting();
716 $langlinks = $this->otherLanguages();
723 $borderhack = 'class="top"';
726 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
727 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
729 $shove = ( $qb != 0 );
730 $left = ( $qb == 1 ||
$qb == 3 );
732 if ( $wgContLang->isRTL() ) {
737 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
738 $this->logoText() . '</td>';
740 $s .= $this->getQuickbarCompensator( $rows );
743 $l = $wgContLang->alignStart();
744 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
746 $s .= $this->topLinks();
747 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
749 $r = $wgContLang->alignEnd();
750 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
751 $s .= $this->nameAndLogin();
752 $s .= "\n<br />" . $this->searchForm() . '</td>';
755 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
758 if ( $shove && !$left ) { # Right
759 $s .= $this->getQuickbarCompensator( $rows );
762 $s .= "</tr>\n</table>\n</div>\n";
763 $s .= "\n<div id='article'>\n";
765 $notice = wfGetSiteNotice();
768 $s .= "\n<div id='siteNotice'>$notice</div>\n";
770 $s .= $this->pageTitle();
771 $s .= $this->pageSubtitle();
772 $s .= $this->getCategories();
774 wfProfileOut( __METHOD__
);
778 function getCategoryLinks() {
779 global $wgOut, $wgUseCategoryBrowser;
780 global $wgContLang, $wgUser;
782 if ( count( $wgOut->mCategoryLinks
) == 0 ) {
787 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
789 // Use Unicode bidi embedding override characters,
790 // to make sure links don't smash each other up in ugly ways.
791 $dir = $wgContLang->getDir();
792 $embed = "<span dir='$dir'>";
795 $allCats = $wgOut->getCategoryLinks();
797 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
799 if ( !empty( $allCats['normal'] ) ) {
800 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
802 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
803 $s .= '<div id="mw-normal-catlinks">' .
804 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
805 . $colon . $t . '</div>';
809 if ( isset( $allCats['hidden'] ) ) {
810 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
811 $class = 'mw-hidden-cats-user-shown';
812 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
813 $class = 'mw-hidden-cats-ns-shown';
815 $class = 'mw-hidden-cats-hidden';
818 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
819 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
820 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
824 # optional 'dmoz-like' category browser. Will be shown under the list
825 # of categories an article belong to
826 if ( $wgUseCategoryBrowser ) {
827 $s .= '<br /><hr />';
829 # get a big array of the parents tree
830 $parenttree = $this->mTitle
->getParentCategoryTree();
831 # Skin object passed by reference cause it can not be
832 # accessed under the method subfunction drawCategoryBrowser
833 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
834 # Clean out bogus first entry and sort them
835 unset( $tempout[0] );
837 # Output one per line
838 $s .= implode( "<br />\n", $tempout );
845 * Render the array as a serie of links.
846 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
847 * @param &skin Object: skin passed by reference
848 * @return String separated by >, terminate with "\n"
850 function drawCategoryBrowser( $tree, &$skin ) {
853 foreach ( $tree as $element => $parent ) {
854 if ( empty( $parent ) ) {
855 # element start a new list
858 # grab the others elements
859 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' > ';
862 # add our current element to the list
863 $eltitle = Title
::newFromText( $element );
864 $return .= $skin->link( $eltitle, $eltitle->getText() );
870 function getCategories() {
871 $catlinks = $this->getCategoryLinks();
873 $classes = 'catlinks';
875 global $wgOut, $wgUser;
877 // Check what we're showing
878 $allCats = $wgOut->getCategoryLinks();
879 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
880 $this->mTitle
->getNamespace() == NS_CATEGORY
;
882 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
883 $classes .= ' catlinks-allhidden';
886 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
889 function getQuickbarCompensator( $rows = 1 ) {
890 return "<td width='152' rowspan='{$rows}'> </td>";
894 * This runs a hook to allow extensions placing their stuff after content
895 * and article metadata (e.g. categories).
896 * Note: This function has nothing to do with afterContent().
898 * This hook is placed here in order to allow using the same hook for all
899 * skins, both the SkinTemplate based ones and the older ones, which directly
900 * use this class to get their data.
902 * The output of this function gets processed in SkinTemplate::outputPage() for
903 * the SkinTemplate based skins, all other skins should directly echo it.
905 * Returns an empty string by default, if not changed by any hook function.
907 protected function afterContentHook() {
910 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
911 // adding just some spaces shouldn't toggle the output
912 // of the whole <div/>, so we use trim() here
913 if ( trim( $data ) != '' ) {
914 // Doing this here instead of in the skins to
915 // ensure that the div has the same ID in all
917 $data = "<div id='mw-data-after-content'>\n" .
922 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
929 * Generate debug data HTML for displaying at the bottom of the main content
931 * @return String HTML containing debug data, if enabled (otherwise empty).
933 protected function generateDebugHTML() {
934 global $wgShowDebug, $wgOut;
936 if ( $wgShowDebug ) {
937 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext
);
938 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
939 $listInternals . "</ul>\n";
945 private function formatDebugHTML( $debugText ) {
946 $lines = explode( "\n", $debugText );
950 foreach ( $lines as $line ) {
951 $display = ltrim( $line );
952 $ident = strlen( $line ) - strlen( $display );
953 $diff = $ident - $curIdent;
955 if ( $display == '' ) {
956 $display = "\xc2\xa0";
959 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
962 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
964 $display = htmlspecialchars( $display );
968 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
969 } elseif ( $diff == 0 ) {
970 $ret .= "</li><li>\n";
972 $ret .= str_repeat( "<ul><li>\n", $diff );
974 $ret .= $display . "\n";
979 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
985 * This gets called shortly before the </body> tag.
986 * @return String HTML to be put before </body>
988 function afterContent() {
989 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
990 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
994 * This gets called shortly before the </body> tag.
995 * @param $out OutputPage object
996 * @return String HTML-wrapped JS code to be put before </body>
998 function bottomScripts( $out ) {
999 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
1000 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
1002 return $bottomScriptText;
1005 /** @return string Retrievied from HTML text */
1006 function printSource() {
1007 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
1008 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
1011 function printFooter() {
1012 return "<p>" . $this->printSource() .
1013 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
1016 /** overloaded by derived classes */
1017 function doAfterContent() {
1018 return '</div></div>';
1021 function pageTitleLinks() {
1022 global $wgOut, $wgUser, $wgRequest, $wgLang;
1024 $oldid = $wgRequest->getVal( 'oldid' );
1025 $diff = $wgRequest->getVal( 'diff' );
1026 $action = $wgRequest->getText( 'action' );
1028 $s[] = $this->printableLink();
1029 $disclaimer = $this->disclaimerLink(); # may be empty
1031 if ( $disclaimer ) {
1035 $privacy = $this->privacyLink(); # may be empty too
1041 if ( $wgOut->isArticleRelated() ) {
1042 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
1043 $name = $this->mTitle
->getDBkey();
1044 $image = wfFindFile( $this->mTitle
);
1047 $link = htmlspecialchars( $image->getURL() );
1048 $style = $this->getInternalLinkAttributes( $link, $name );
1049 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1054 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
1055 $s[] .= $this->link(
1057 wfMsg( 'currentrev' ),
1060 array( 'known', 'noclasses' )
1064 if ( $wgUser->getNewtalk() ) {
1065 # do not show "You have new messages" text when we are viewing our
1067 if ( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1069 $wgUser->getTalkPage(),
1070 wfMsgHtml( 'newmessageslink' ),
1072 array( 'redirect' => 'no' ),
1073 array( 'known', 'noclasses' )
1077 $wgUser->getTalkPage(),
1078 wfMsgHtml( 'newmessagesdifflink' ),
1080 array( 'diff' => 'cur' ),
1081 array( 'known', 'noclasses' )
1083 $s[] = '<strong>' . wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1085 $wgOut->setSquidMaxage( 0 );
1086 $wgOut->enableClientCache( false );
1090 $undelete = $this->getUndeleteLink();
1092 if ( !empty( $undelete ) ) {
1096 return $wgLang->pipeList( $s );
1099 function getUndeleteLink() {
1100 global $wgUser, $wgLang, $wgRequest;
1102 $action = $wgRequest->getVal( 'action', 'view' );
1104 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1105 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1106 $n = $this->mTitle
->isDeleted();
1109 if ( $wgUser->isAllowed( 'undelete' ) ) {
1110 $msg = 'thisisdeleted';
1112 $msg = 'viewdeleted';
1118 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1119 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1122 array( 'known', 'noclasses' )
1131 function printableLink() {
1132 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1136 if ( !$wgOut->isPrintable() ) {
1137 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1138 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1141 if ( $wgOut->isSyndicated() ) {
1142 foreach ( $wgFeedClasses as $format => $class ) {
1143 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1144 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1145 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1148 return $wgLang->pipeList( $s );
1152 * Gets the h1 element with the page title.
1155 function pageTitle() {
1157 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1161 function pageSubtitle() {
1164 $sub = $wgOut->getSubtitle();
1167 global $wgExtraSubtitle;
1168 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1171 $subpages = $this->subPageSubtitle();
1172 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1173 $s = "<p class='subtitle'>{$sub}</p>\n";
1178 function subPageSubtitle() {
1181 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this ) ) ) {
1187 if ( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1188 $ptext = $this->mTitle
->getPrefixedText();
1189 if ( preg_match( '/\//', $ptext ) ) {
1190 $links = explode( '/', $ptext );
1191 array_pop( $links );
1196 foreach ( $links as $link ) {
1197 $growinglink .= $link;
1199 $linkObj = Title
::newFromText( $growinglink );
1201 if ( is_object( $linkObj ) && $linkObj->exists() ) {
1202 $getlink = $this->link(
1204 htmlspecialchars( $display ),
1207 array( 'known', 'noclasses' )
1213 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1215 $subpages .= '< ';
1218 $subpages .= $getlink;
1223 $growinglink .= '/';
1232 * Returns true if the IP should be shown in the header
1234 function showIPinHeader() {
1235 global $wgShowIPinHeader;
1236 return $wgShowIPinHeader && session_id() != '';
1239 function nameAndLogin() {
1240 global $wgUser, $wgLang, $wgContLang;
1242 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1246 if ( $wgUser->isAnon() ) {
1247 if ( $this->showIPinHeader() ) {
1250 $talkLink = $this->link( $wgUser->getTalkPage(),
1251 $wgLang->getNsText( NS_TALK
) );
1253 $ret .= "$name ($talkLink)";
1255 $ret .= wfMsg( 'notloggedin' );
1258 $returnTo = $this->mTitle
->getPrefixedDBkey();
1261 if ( $logoutPage != $returnTo ) {
1262 $query['returnto'] = $returnTo;
1265 $loginlink = $wgUser->isAllowed( 'createaccount' )
1266 ?
'nav-login-createaccount'
1268 $ret .= "\n<br />" . $this->link(
1269 SpecialPage
::getTitleFor( 'Userlogin' ),
1270 wfMsg( $loginlink ), array(), $query
1273 $returnTo = $this->mTitle
->getPrefixedDBkey();
1274 $talkLink = $this->link( $wgUser->getTalkPage(),
1275 $wgLang->getNsText( NS_TALK
) );
1277 $ret .= $this->link( $wgUser->getUserPage(),
1278 htmlspecialchars( $wgUser->getName() ) );
1279 $ret .= " ($talkLink)<br />";
1280 $ret .= $wgLang->pipeList( array(
1282 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1283 array(), array( 'returnto' => $returnTo )
1285 $this->specialLink( 'Preferences' ),
1289 $ret = $wgLang->pipeList( array(
1292 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1300 function getSearchLink() {
1301 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1302 return $searchPage->getLocalURL();
1305 function escapeSearchLink() {
1306 return htmlspecialchars( $this->getSearchLink() );
1309 function searchForm() {
1310 global $wgRequest, $wgUseTwoButtonsSearchForm;
1312 $search = $wgRequest->getText( 'search' );
1314 $s = '<form id="searchform' . $this->searchboxes
. '" name="search" class="inline" method="post" action="'
1315 . $this->escapeSearchLink() . "\">\n"
1316 . '<input type="text" id="searchInput' . $this->searchboxes
. '" name="search" size="19" value="'
1317 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1318 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1320 if ( $wgUseTwoButtonsSearchForm ) {
1321 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1323 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1328 // Ensure unique id's for search boxes made after the first
1329 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1334 function topLinks() {
1338 $this->mainPageLink(),
1339 $this->specialLink( 'Recentchanges' )
1342 if ( $wgOut->isArticleRelated() ) {
1343 $s[] = $this->editThisPage();
1344 $s[] = $this->historyLink();
1347 # Many people don't like this dropdown box
1348 # $s[] = $this->specialPagesList();
1350 if ( $this->variantLinks() ) {
1351 $s[] = $this->variantLinks();
1354 if ( $this->extensionTabLinks() ) {
1355 $s[] = $this->extensionTabLinks();
1358 // @todo FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1359 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1363 * Compatibility for extensions adding functionality through tabs.
1364 * Eventually these old skins should be replaced with SkinTemplate-based
1368 function extensionTabLinks() {
1372 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1373 foreach ( $tabs as $tab ) {
1374 $s[] = Xml
::element( 'a',
1375 array( 'href' => $tab['href'] ),
1379 if ( count( $s ) ) {
1382 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1383 $out .= $wgLang->pipeList( $s );
1390 * Language/charset variant links for classic-style skins
1393 function variantLinks() {
1396 /* show links to different language variants */
1397 global $wgDisableLangConversion, $wgLang, $wgContLang;
1399 $variants = $wgContLang->getVariants();
1401 if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1402 foreach ( $variants as $code ) {
1403 $varname = $wgContLang->getVariantname( $code );
1405 if ( $varname == 'disable' ) {
1408 $s = $wgLang->pipeList( array(
1410 '<a href="' . $this->mTitle
->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1418 function bottomLinks() {
1419 global $wgOut, $wgUser, $wgUseTrackbacks;
1420 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1423 if ( $wgOut->isArticleRelated() ) {
1424 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1426 if ( $wgUser->isLoggedIn() ) {
1427 $element[] = $this->watchThisPage();
1430 $element[] = $this->talkLink();
1431 $element[] = $this->historyLink();
1432 $element[] = $this->whatLinksHere();
1433 $element[] = $this->watchPageLinksLink();
1435 if ( $wgUseTrackbacks ) {
1436 $element[] = $this->trackbackLink();
1440 $this->mTitle
->getNamespace() == NS_USER ||
1441 $this->mTitle
->getNamespace() == NS_USER_TALK
1443 $id = User
::idFromName( $this->mTitle
->getText() );
1444 $ip = User
::isIP( $this->mTitle
->getText() );
1446 # Both anons and non-anons have contributions list
1448 $element[] = $this->userContribsLink();
1451 if ( $this->showEmailUser( $id ) ) {
1452 $element[] = $this->emailUserLink();
1456 $s = implode( $element, $sep );
1458 if ( $this->mTitle
->getArticleId() ) {
1461 // Delete/protect/move links for privileged users
1462 if ( $wgUser->isAllowed( 'delete' ) ) {
1463 $s .= $this->deleteThisPage();
1466 if ( $wgUser->isAllowed( 'protect' ) ) {
1467 $s .= $sep . $this->protectThisPage();
1470 if ( $wgUser->isAllowed( 'move' ) ) {
1471 $s .= $sep . $this->moveThisPage();
1475 $s .= "<br />\n" . $this->otherLanguages();
1481 function pageStats() {
1482 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1483 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1485 if ( !is_null( $wgRequest->getVal( 'oldid' ) ) ||
!is_null( $wgRequest->getVal( 'diff' ) ) ) {
1489 if ( !$wgOut->isArticle() ||
!$this->mTitle
->exists() ) {
1495 if ( !$wgDisableCounters ) {
1496 $count = $wgLang->formatNum( $wgArticle->getCount() );
1499 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1503 if ( $wgMaxCredits != 0 ) {
1504 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1506 $s .= $this->lastModified();
1509 if ( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1510 $dbr = wfGetDB( DB_SLAVE
);
1511 $res = $dbr->select(
1513 array( 'COUNT(*) AS n' ),
1515 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ),
1516 'wl_namespace' => $this->mTitle
->getNamespace()
1520 $x = $dbr->fetchObject( $res );
1522 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1523 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1527 return $s . ' ' . $this->getCopyright();
1530 function getCopyright( $type = 'detect' ) {
1531 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1533 if ( $type == 'detect' ) {
1534 $diff = $wgRequest->getVal( 'diff' );
1536 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1543 if ( $type == 'history' ) {
1544 $msg = 'history_copyright';
1551 if ( $wgRightsPage ) {
1552 $title = Title
::newFromText( $wgRightsPage );
1553 $link = $this->linkKnown( $title, $wgRightsText );
1554 } elseif ( $wgRightsUrl ) {
1555 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1556 } elseif ( $wgRightsText ) {
1557 $link = $wgRightsText;
1563 // Allow for site and per-namespace customization of copyright notice.
1566 wfRunHooks( 'SkinCopyrightFooter', array( $this->mTitle
, $type, &$msg, &$link, &$forContent ) );
1568 if ( $forContent ) {
1569 $out .= wfMsgForContent( $msg, $link );
1571 $out .= wfMsg( $msg, $link );
1577 function getCopyrightIcon() {
1578 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1582 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1583 $out = $wgCopyrightIcon;
1584 } elseif ( $wgRightsIcon ) {
1585 $icon = htmlspecialchars( $wgRightsIcon );
1587 if ( $wgRightsUrl ) {
1588 $url = htmlspecialchars( $wgRightsUrl );
1589 $out .= '<a href="' . $url . '">';
1592 $text = htmlspecialchars( $wgRightsText );
1593 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1595 if ( $wgRightsUrl ) {
1604 * Gets the powered by MediaWiki icon.
1607 function getPoweredBy() {
1608 global $wgStylePath;
1610 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1611 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1612 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
1616 function lastModified() {
1617 global $wgLang, $wgArticle;
1619 if ( !$this->isRevisionCurrent() ) {
1620 $timestamp = Revision
::getTimestampFromId( $this->mTitle
, $this->mRevisionId
);
1622 $timestamp = $wgArticle->getTimestamp();
1626 $d = $wgLang->date( $timestamp, true );
1627 $t = $wgLang->time( $timestamp, true );
1628 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1633 if ( wfGetLB()->getLaggedSlaveMode() ) {
1634 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1640 function logoText( $align = '' ) {
1641 if ( $align != '' ) {
1642 $a = " align='{$align}'";
1647 $mp = wfMsg( 'mainpage' );
1648 $mptitle = Title
::newMainPage();
1649 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1651 $logourl = $this->getLogo();
1652 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1658 * Show a drop-down box of special pages
1660 function specialPagesList() {
1661 global $wgContLang, $wgServer, $wgRedirectScript;
1663 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1665 foreach ( $pages as $name => $page ) {
1666 $pages[$name] = $page->getDescription();
1669 $go = wfMsg( 'go' );
1670 $sp = wfMsg( 'specialpages' );
1671 $spp = $wgContLang->specialPage( 'Specialpages' );
1673 $s = '<form id="specialpages" method="get" ' .
1674 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1675 $s .= "<select name=\"wpDropdown\">\n";
1676 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1679 foreach ( $pages as $name => $desc ) {
1680 $p = $wgContLang->specialPage( $name );
1681 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1684 $s .= "</select>\n";
1685 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1692 * Renders a $wgFooterIcons icon acording to the method's arguments
1693 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
1694 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
1696 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
1697 if ( is_string( $icon ) ) {
1699 } else { // Assuming array
1700 $url = $icon["url"];
1701 unset( $icon["url"] );
1702 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
1703 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1705 $html = htmlspecialchars( $icon["alt"] );
1708 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
1715 * Gets the link to the wiki's main page.
1718 function mainPageLink() {
1720 Title
::newMainPage(),
1721 wfMsg( 'mainpage' ),
1724 array( 'known', 'noclasses' )
1730 public function footerLink( $desc, $page ) {
1731 // if the link description has been set to "-" in the default language,
1732 if ( wfMsgForContent( $desc ) == '-' ) {
1733 // then it is disabled, for all languages.
1736 // Otherwise, we display the link for the user, described in their
1737 // language (which may or may not be the same as the default language),
1738 // but we make the link target be the one site-wide page.
1739 $title = Title
::newFromText( wfMsgForContent( $page ) );
1741 return $this->linkKnown(
1743 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1749 * Gets the link to the wiki's privacy policy page.
1751 function privacyLink() {
1752 return $this->footerLink( 'privacy', 'privacypage' );
1756 * Gets the link to the wiki's about page.
1758 function aboutLink() {
1759 return $this->footerLink( 'aboutsite', 'aboutpage' );
1763 * Gets the link to the wiki's general disclaimers page.
1765 function disclaimerLink() {
1766 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1769 function editThisPage() {
1772 if ( !$wgOut->isArticleRelated() ) {
1773 $s = wfMsg( 'protectedpage' );
1775 if ( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1776 $t = wfMsg( 'editthispage' );
1777 } elseif ( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1778 $t = wfMsg( 'create-this-page' );
1780 $t = wfMsg( 'viewsource' );
1787 $this->editUrlOptions(),
1788 array( 'known', 'noclasses' )
1796 * Return URL options for the 'edit page' link.
1797 * This may include an 'oldid' specifier, if the current page view is such.
1802 function editUrlOptions() {
1803 $options = array( 'action' => 'edit' );
1805 if ( !$this->isRevisionCurrent() ) {
1806 $options['oldid'] = intval( $this->mRevisionId
);
1812 function deleteThisPage() {
1813 global $wgUser, $wgRequest;
1815 $diff = $wgRequest->getVal( 'diff' );
1817 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1818 $t = wfMsg( 'deletethispage' );
1824 array( 'action' => 'delete' ),
1825 array( 'known', 'noclasses' )
1834 function protectThisPage() {
1835 global $wgUser, $wgRequest;
1837 $diff = $wgRequest->getVal( 'diff' );
1839 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
1840 if ( $this->mTitle
->isProtected() ) {
1841 $text = wfMsg( 'unprotectthispage' );
1842 $query = array( 'action' => 'unprotect' );
1844 $text = wfMsg( 'protectthispage' );
1845 $query = array( 'action' => 'protect' );
1853 array( 'known', 'noclasses' )
1862 function watchThisPage() {
1864 ++
$this->mWatchLinkNum
;
1866 if ( $wgOut->isArticleRelated() ) {
1867 if ( $this->mTitle
->userIsWatching() ) {
1868 $text = wfMsg( 'unwatchthispage' );
1869 $query = array( 'action' => 'unwatch' );
1870 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1872 $text = wfMsg( 'watchthispage' );
1873 $query = array( 'action' => 'watch' );
1874 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1880 array( 'id' => $id ),
1882 array( 'known', 'noclasses' )
1885 $s = wfMsg( 'notanarticle' );
1891 function moveThisPage() {
1892 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1894 SpecialPage
::getTitleFor( 'Movepage' ),
1895 wfMsg( 'movethispage' ),
1897 array( 'target' => $this->mTitle
->getPrefixedDBkey() ),
1898 array( 'known', 'noclasses' )
1901 // no message if page is protected - would be redundant
1906 function historyLink() {
1909 wfMsgHtml( 'history' ),
1910 array( 'rel' => 'archives' ),
1911 array( 'action' => 'history' )
1915 function whatLinksHere() {
1917 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1918 wfMsgHtml( 'whatlinkshere' ),
1921 array( 'known', 'noclasses' )
1925 function userContribsLink() {
1927 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1928 wfMsgHtml( 'contributions' ),
1931 array( 'known', 'noclasses' )
1935 function showEmailUser( $id ) {
1937 $targetUser = User
::newFromId( $id );
1938 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1939 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1942 function emailUserLink() {
1944 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1945 wfMsg( 'emailuser' ),
1948 array( 'known', 'noclasses' )
1952 function watchPageLinksLink() {
1955 if ( !$wgOut->isArticleRelated() ) {
1956 return '(' . wfMsg( 'notanarticle' ) . ')';
1959 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1960 wfMsg( 'recentchangeslinked-toolbox' ),
1963 array( 'known', 'noclasses' )
1968 function trackbackLink() {
1969 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1970 . wfMsg( 'trackbacklink' ) . '</a>';
1973 function otherLanguages() {
1974 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1976 if ( $wgHideInterlanguageLinks ) {
1980 $a = $wgOut->getLanguageLinks();
1982 if ( 0 == count( $a ) ) {
1986 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1989 if ( $wgContLang->isRTL() ) {
1990 $s .= '<span dir="LTR">';
1993 foreach ( $a as $l ) {
1995 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
2000 $nt = Title
::newFromText( $l );
2001 $url = $nt->escapeFullURL();
2002 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
2003 $title = htmlspecialchars( $nt->getText() );
2005 if ( $text == '' ) {
2009 $style = $this->getExternalLinkAttributes();
2010 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
2013 if ( $wgContLang->isRTL() ) {
2020 function talkLink() {
2021 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
2022 # No discussion links for special pages
2026 $linkOptions = array();
2028 if ( $this->mTitle
->isTalkPage() ) {
2029 $link = $this->mTitle
->getSubjectPage();
2030 switch( $link->getNamespace() ) {
2032 $text = wfMsg( 'articlepage' );
2035 $text = wfMsg( 'userpage' );
2038 $text = wfMsg( 'projectpage' );
2041 $text = wfMsg( 'imagepage' );
2042 # Make link known if image exists, even if the desc. page doesn't.
2043 if ( wfFindFile( $link ) )
2044 $linkOptions[] = 'known';
2047 $text = wfMsg( 'mediawikipage' );
2050 $text = wfMsg( 'templatepage' );
2053 $text = wfMsg( 'viewhelppage' );
2056 $text = wfMsg( 'categorypage' );
2059 $text = wfMsg( 'articlepage' );
2062 $link = $this->mTitle
->getTalkPage();
2063 $text = wfMsg( 'talkpage' );
2066 $s = $this->link( $link, $text, array(), array(), $linkOptions );
2071 function commentLink() {
2074 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
2078 # __NEWSECTIONLINK___ changes behaviour here
2079 # If it is present, the link points to this page, otherwise
2080 # it points to the talk page
2081 if ( $this->mTitle
->isTalkPage() ) {
2082 $title = $this->mTitle
;
2083 } elseif ( $wgOut->showNewSectionLink() ) {
2084 $title = $this->mTitle
;
2086 $title = $this->mTitle
->getTalkPage();
2091 wfMsg( 'postcomment' ),
2097 array( 'known', 'noclasses' )
2101 function getUploadLink() {
2102 global $wgUploadNavigationUrl;
2104 if ( $wgUploadNavigationUrl ) {
2105 # Using an empty class attribute to avoid automatic setting of "external" class
2106 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '' ) );
2109 SpecialPage
::getTitleFor( 'Upload' ),
2110 wfMsgHtml( 'upload' ),
2113 array( 'known', 'noclasses' )
2119 * Return a fully resolved style path url to images or styles stored in the common folder.
2120 * This method returns a url resolved using the configured skin style path
2121 * and includes the style version inside of the url.
2122 * @param $name String: The name or path of a skin resource file
2123 * @return String The fully resolved style path url including styleversion
2125 function getCommonStylePath( $name ) {
2126 global $wgStylePath, $wgStyleVersion;
2127 return "$wgStylePath/common/$name?$wgStyleVersion";
2131 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
2132 * This method returns a url resolved using the configured skin style path
2133 * and includes the style version inside of the url.
2134 * @param $name String: The name or path of a skin resource file
2135 * @return String The fully resolved style path url including styleversion
2137 function getSkinStylePath( $name ) {
2138 global $wgStylePath, $wgStyleVersion;
2139 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
2142 /* these are used extensively in SkinTemplate, but also some other places */
2143 static function makeMainPageUrl( $urlaction = '' ) {
2144 $title = Title
::newMainPage();
2145 self
::checkTitle( $title, '' );
2147 return $title->getLocalURL( $urlaction );
2150 static function makeSpecialUrl( $name, $urlaction = '' ) {
2151 $title = SpecialPage
::getTitleFor( $name );
2152 return $title->getLocalURL( $urlaction );
2155 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2156 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
2157 return $title->getLocalURL( $urlaction );
2160 static function makeI18nUrl( $name, $urlaction = '' ) {
2161 $title = Title
::newFromText( wfMsgForContent( $name ) );
2162 self
::checkTitle( $title, $name );
2163 return $title->getLocalURL( $urlaction );
2166 static function makeUrl( $name, $urlaction = '' ) {
2167 $title = Title
::newFromText( $name );
2168 self
::checkTitle( $title, $name );
2170 return $title->getLocalURL( $urlaction );
2174 * If url string starts with http, consider as external URL, else
2177 static function makeInternalOrExternalUrl( $name ) {
2178 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2181 return self
::makeUrl( $name );
2185 # this can be passed the NS number as defined in Language.php
2186 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
2187 $title = Title
::makeTitleSafe( $namespace, $name );
2188 self
::checkTitle( $title, $name );
2190 return $title->getLocalURL( $urlaction );
2193 /* these return an array with the 'href' and boolean 'exists' */
2194 static function makeUrlDetails( $name, $urlaction = '' ) {
2195 $title = Title
::newFromText( $name );
2196 self
::checkTitle( $title, $name );
2199 'href' => $title->getLocalURL( $urlaction ),
2200 'exists' => $title->getArticleID() != 0,
2205 * Make URL details where the article exists (or at least it's convenient to think so)
2207 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2208 $title = Title
::newFromText( $name );
2209 self
::checkTitle( $title, $name );
2212 'href' => $title->getLocalURL( $urlaction ),
2217 # make sure we have some title to operate on
2218 static function checkTitle( &$title, $name ) {
2219 if ( !is_object( $title ) ) {
2220 $title = Title
::newFromText( $name );
2221 if ( !is_object( $title ) ) {
2222 $title = Title
::newFromText( '--error: link target missing--' );
2228 * Build an array that represents the sidebar(s), the navigation bar among them
2232 function buildSidebar() {
2233 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2235 wfProfileIn( __METHOD__
);
2237 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2239 if ( $wgEnableSidebarCache ) {
2240 $cachedsidebar = $parserMemc->get( $key );
2241 if ( $cachedsidebar ) {
2242 wfProfileOut( __METHOD__
);
2243 return $cachedsidebar;
2248 $this->addToSidebar( $bar, 'sidebar' );
2250 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2251 if ( $wgEnableSidebarCache ) {
2252 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2255 wfProfileOut( __METHOD__
);
2259 * Add content from a sidebar system message
2260 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2262 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2264 * @param &$bar array
2265 * @param $message String
2267 function addToSidebar( &$bar, $message ) {
2268 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2272 * Add content from plain text
2274 * @param &$bar array
2275 * @param $text string
2277 function addToSidebarPlain( &$bar, $text ) {
2278 $lines = explode( "\n", $text );
2279 $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.
2283 foreach ( $lines as $line ) {
2284 if ( strpos( $line, '*' ) !== 0 ) {
2288 if ( strpos( $line, '**' ) !== 0 ) {
2289 $heading = trim( $line, '* ' );
2290 if ( !array_key_exists( $heading, $bar ) ) {
2291 $bar[$heading] = array();
2294 $line = trim( $line, '* ' );
2296 if ( strpos( $line, '|' ) !== false ) { // sanity check
2297 $line = array_map( 'trim', explode( '|', $line, 2 ) );
2298 $link = wfMsgForContent( $line[0] );
2300 if ( $link == '-' ) {
2304 $text = wfMsgExt( $line[1], 'parsemag' );
2306 if ( wfEmptyMsg( $line[1], $text ) ) {
2310 if ( wfEmptyMsg( $line[0], $link ) ) {
2314 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2317 $title = Title
::newFromText( $link );
2320 $title = $title->fixSpecialName();
2321 $href = $title->getLocalURL();
2323 $href = 'INVALID-TITLE';
2327 $bar[$heading][] = array(
2330 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2333 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
2334 global $wgParser, $wgTitle;
2336 $line = substr( $line, 2, strlen( $line ) - 4 );
2338 $options = new ParserOptions();
2339 $options->setEditSection( false );
2340 $options->setInterfaceMessage( true );
2341 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $options )->getText();
2348 if ( count( $wikiBar ) > 0 ) {
2349 $bar = array_merge( $bar, $wikiBar );
2356 * Should we include common/wikiprintable.css? Skins that have their own
2357 * print stylesheet should override this and return false. (This is an
2358 * ugly hack to get Monobook to play nicely with
2359 * OutputPage::headElement().)
2363 public function commonPrintStylesheet() {
2368 * Gets new talk page messages for the current user.
2369 * @return MediaWiki message or if no new talk page messages, nothing
2371 function getNewtalks() {
2372 global $wgUser, $wgOut;
2374 $newtalks = $wgUser->getNewMessageLinks();
2377 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2378 $userTitle = $this->mUser
->getUserPage();
2379 $userTalkTitle = $userTitle->getTalkPage();
2381 if ( !$userTalkTitle->equals( $this->mTitle
) ) {
2382 $newMessagesLink = $this->link(
2384 wfMsgHtml( 'newmessageslink' ),
2386 array( 'redirect' => 'no' ),
2387 array( 'known', 'noclasses' )
2390 $newMessagesDiffLink = $this->link(
2392 wfMsgHtml( 'newmessagesdifflink' ),
2394 array( 'diff' => 'cur' ),
2395 array( 'known', 'noclasses' )
2399 'youhavenewmessages',
2401 $newMessagesDiffLink
2403 # Disable Squid cache
2404 $wgOut->setSquidMaxage( 0 );
2406 } elseif ( count( $newtalks ) ) {
2407 // _>" " for BC <= 1.16
2408 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2411 foreach ( $newtalks as $newtalk ) {
2412 $msgs[] = Xml
::element(
2414 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2417 $parts = implode( $sep, $msgs );
2418 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2419 $wgOut->setSquidMaxage( 0 );