Localisation updates for core and extension messages from translatewiki.net (2011...
[lhc/web/wiklou.git] / includes / Skin.php
1 <?php
2 /**
3 * @defgroup Skins Skins
4 */
5
6 if ( !defined( 'MEDIAWIKI' ) ) {
7 die( 1 );
8 }
9
10 /**
11 * The main skin class that provide methods and properties for all other skins.
12 * This base class is also the "Standard" skin.
13 *
14 * See docs/skin.txt for more information.
15 *
16 * @ingroup Skins
17 */
18 class Skin extends Linker {
19 /**#@+
20 * @private
21 */
22 var $mWatchLinkNum = 0; // Appended to end of watch link id's
23 // How many search boxes have we made? Avoid duplicate id's.
24 protected $searchboxes = '';
25 /**#@-*/
26 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
27 protected $skinname = 'standard';
28 // @todo Fixme: should be protected :-\
29 var $mTitle = null;
30 protected $mRelevantTitle = null;
31 protected $mRelevantUser = null;
32
33 /** Constructor, call parent constructor */
34 function __construct() {
35 parent::__construct();
36 }
37
38 /**
39 * Fetch the set of available skins.
40 * @return array of strings
41 */
42 static function getSkinNames() {
43 global $wgValidSkinNames;
44 static $skinsInitialised = false;
45
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
50 #
51 wfProfileIn( __METHOD__ . '-init' );
52
53 global $wgStyleDirectory;
54
55 $skinDir = dir( $wgStyleDirectory );
56
57 # while code from www.php.net
58 while ( false !== ( $file = $skinDir->read() ) ) {
59 // Skip non-PHP files, hidden files, and '.dep' includes
60 $matches = array();
61
62 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
63 $aSkin = $matches[1];
64 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
65 }
66 }
67 $skinDir->close();
68 $skinsInitialised = true;
69 wfProfileOut( __METHOD__ . '-init' );
70 }
71 return $wgValidSkinNames;
72 }
73
74 /**
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
79 */
80 public static function getUsableSkins() {
81 global $wgSkipSkins;
82
83 $usableSkins = self::getSkinNames();
84
85 foreach ( $wgSkipSkins as $skip ) {
86 unset( $usableSkins[$skip] );
87 }
88
89 return $usableSkins;
90 }
91
92 /**
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.
97 * @return string
98 */
99 static function normalizeKey( $key ) {
100 global $wgDefaultSkin;
101
102 $skinNames = Skin::getSkinNames();
103
104 if ( $key == '' ) {
105 // Don't return the default immediately;
106 // in a misconfiguration we need to fall back.
107 $key = $wgDefaultSkin;
108 }
109
110 if ( isset( $skinNames[$key] ) ) {
111 return $key;
112 }
113
114 // Older versions of the software used a numeric setting
115 // in the user preferences.
116 $fallback = array(
117 0 => $wgDefaultSkin,
118 1 => 'nostalgia',
119 2 => 'cologneblue'
120 );
121
122 if ( isset( $fallback[$key] ) ) {
123 $key = $fallback[$key];
124 }
125
126 if ( isset( $skinNames[$key] ) ) {
127 return $key;
128 } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
129 return $wgDefaultSkin;
130 } else {
131 return 'vector';
132 }
133 }
134
135 /**
136 * Factory method for loading a skin of a given type
137 * @param $key String: 'monobook', 'standard', etc.
138 * @return Skin
139 */
140 static function &newFromKey( $key ) {
141 global $wgStyleDirectory;
142
143 $key = Skin::normalizeKey( $key );
144
145 $skinNames = Skin::getSkinNames();
146 $skinName = $skinNames[$key];
147 $className = "Skin{$skinName}";
148
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";
153
154 if ( file_exists( $deps ) ) {
155 include_once( $deps );
156 }
157 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
158
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" );
168 }
169 }
170 $skin = new $className;
171 return $skin;
172 }
173
174 /** @return string path to the skin stylesheet */
175 function getStylesheet() {
176 return 'common/wikistandard.css';
177 }
178
179 /** @return string skin name */
180 public function getSkinName() {
181 return $this->skinname;
182 }
183
184 function qbSetting() {
185 global $wgOut, $wgUser;
186
187 if ( $wgOut->isQuickbarSuppressed() ) {
188 return 0;
189 }
190
191 $q = $wgUser->getOption( 'quickbar', 0 );
192
193 return $q;
194 }
195
196 function initPage( OutputPage $out ) {
197 global $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI;
198
199 wfProfileIn( __METHOD__ );
200
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 ) );
207 }
208
209 if ( false !== $wgFavicon ) {
210 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
211 }
212
213 # OpenSearch description link
214 $out->addLink( array(
215 'rel' => 'search',
216 'type' => 'application/opensearchdescription+xml',
217 'href' => wfScript( 'opensearch_desc' ),
218 'title' => wfMsgForContent( 'opensearch-desc' ),
219 ) );
220
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(
227 'rel' => 'EditURI',
228 'type' => 'application/rsd+xml',
229 'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ) ),
230 ) );
231 }
232
233 $this->addMetadataLinks( $out );
234
235 $this->mRevisionId = $out->mRevisionId;
236
237 $this->preloadExistence();
238
239 wfProfileOut( __METHOD__ );
240 }
241
242 /**
243 * Preload the existence of three commonly-requested pages in a single query
244 */
245 function preloadExistence() {
246 global $wgUser;
247
248 // User/talk link
249 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
250
251 // Other tab link
252 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
253 // nothing
254 } elseif ( $this->mTitle->isTalkPage() ) {
255 $titles[] = $this->mTitle->getSubjectPage();
256 } else {
257 $titles[] = $this->mTitle->getTalkPage();
258 }
259
260 $lb = new LinkBatch( $titles );
261 $lb->setCaller( __METHOD__ );
262 $lb->execute();
263 }
264
265 /**
266 * Adds metadata links below to the HTML output.
267 * <ol>
268 * <li>Creative Commons
269 * <br />See http://wiki.creativecommons.org/Extend_Metadata.
270 * </li>
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
274 * </li>
275 * <li>Copyright</li>
276 * <ol>
277 *
278 * @param $out Object: instance of OutputPage
279 */
280 function addMetadataLinks( OutputPage $out ) {
281 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
282 global $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang;
283 global $wgRightsPage, $wgRightsUrl;
284
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' ) )
292 );
293 }
294
295 if ( $wgEnableDublinCoreRdf ) {
296 $out->addMetadataLink( array(
297 'title' => 'Dublin Core',
298 'type' => 'application/rdf+xml',
299 'href' => $this->mTitle->getLocalURL( 'action=dublincore' ) )
300 );
301 }
302 }
303
304 if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks
305 && $wgContLang->hasVariants() ) {
306
307 $urlvar = $wgContLang->getURLVariant();
308
309 if ( !$urlvar ) {
310 $variants = $wgContLang->getVariants();
311 foreach ( $variants as $_v ) {
312 $out->addLink( array(
313 'rel' => 'alternate',
314 'hreflang' => $_v,
315 'href' => $this->mTitle->getLocalURL( '', $_v ) )
316 );
317 }
318 } else {
319 $out->addLink( array(
320 'rel' => 'canonical',
321 'href' => $this->mTitle->getFullURL() )
322 );
323 }
324 }
325
326 $copyright = '';
327 if ( $wgRightsPage ) {
328 $copy = Title::newFromText( $wgRightsPage );
329
330 if ( $copy ) {
331 $copyright = $copy->getLocalURL();
332 }
333 }
334
335 if ( !$copyright && $wgRightsUrl ) {
336 $copyright = $wgRightsUrl;
337 }
338
339 if ( $copyright ) {
340 $out->addLink( array(
341 'rel' => 'copyright',
342 'href' => $copyright )
343 );
344 }
345 }
346
347 /**
348 * Set some local variables
349 */
350 protected function setMembers() {
351 global $wgUser;
352 $this->mUser = $wgUser;
353 $this->userpage = $wgUser->getUserPage()->getPrefixedText();
354 $this->usercss = false;
355 }
356
357 /**
358 * Whether the revision displayed is the latest revision of the page
359 *
360 * @return Boolean
361 */
362 public function isRevisionCurrent() {
363 return $this->mRevisionId == 0 || $this->mRevisionId == $this->mTitle->getLatestRevID();
364 }
365
366 /**
367 * Set the title
368 * @param $t Title object to use
369 */
370 public function setTitle( $t ) {
371 $this->mTitle = $t;
372 }
373
374 /** Get the title */
375 public function getTitle() {
376 return $this->mTitle;
377 }
378
379 /**
380 * Set the "relevant" title
381 * @see self::getRelevantTitle()
382 * @param $t Title object to use
383 */
384 public function setRelevantTitle( $t ) {
385 $this->mRelevantTitle = $t;
386 }
387
388 /**
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.
395 */
396 public function getRelevantTitle() {
397 if ( isset($this->mRelevantTitle) ) {
398 return $this->mRelevantTitle;
399 }
400 return $this->mTitle;
401 }
402
403 /**
404 * Set the "relevant" user
405 * @see self::getRelevantUser()
406 * @param $u User object to use
407 */
408 public function setRelevantUser( $u ) {
409 $this->mRelevantUser = $u;
410 }
411
412 /**
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.
418 */
419 public function getRelevantUser() {
420 if ( isset($this->mRelevantUser) ) {
421 return $this->mRelevantUser;
422 }
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 );
428 } else {
429 $user = User::newFromName( $rootUser );
430 if ( $user->isLoggedIn() ) {
431 $this->mRelevantUser = $user;
432 }
433 }
434 return $this->mRelevantUser;
435 }
436 return null;
437 }
438
439 /**
440 * Outputs the HTML generated by other functions.
441 * @param $out Object: instance of OutputPage
442 */
443 function outputPage( OutputPage $out ) {
444 global $wgDebugComments;
445 wfProfileIn( __METHOD__ );
446
447 $this->setMembers();
448 $this->initPage( $out );
449
450 // See self::afterContentHook() for documentation
451 $afterContent = $this->afterContentHook();
452
453 $out->out( $out->headElement( $this ) );
454
455 if ( $wgDebugComments ) {
456 $out->out( "<!-- Debug output:\n" .
457 $out->mDebugtext . "-->\n" );
458 }
459
460 $out->out( $this->beforeContent() );
461
462 $out->out( $out->mBodytext . "\n" );
463
464 $out->out( $this->afterContent() );
465
466 $out->out( $afterContent );
467
468 $out->out( $this->bottomScripts( $out ) );
469
470 $out->out( wfReportTime() );
471
472 $out->out( "\n</body></html>" );
473 wfProfileOut( __METHOD__ );
474 }
475
476 static function makeVariablesScript( $data ) {
477 if ( $data ) {
478 return Html::inlineScript(
479 ResourceLoader::makeLoaderConditionalScript( ResourceLoader::makeConfigSetScript( $data ) )
480 );
481 } else {
482 return '';
483 }
484 }
485
486 /**
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!
491 *
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.
494 */
495 static function makeGlobalVariablesScript( $skinName ) {
496 global $wgTitle, $wgUser, $wgRequest, $wgOut, $wgUseAjax, $wgEnableMWSuggest;
497
498 $ns = $wgTitle->getNamespace();
499 $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
500 $vars = array(
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',
515 );
516 foreach ( $wgTitle->getRestrictionTypes() as $type ) {
517 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
518 }
519 if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
520 $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
521 }
522
523 // Allow extensions to add their custom variables to the global JS variables
524 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
525
526 return self::makeVariablesScript( $vars );
527 }
528
529 /**
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
534 * the code.
535 *
536 * @param $action String: 'edit', 'submit' etc.
537 * @return bool
538 */
539 public function userCanPreview( $action ) {
540 global $wgRequest, $wgUser;
541
542 if ( $action != 'submit' ) {
543 return false;
544 }
545 if ( !$wgRequest->wasPosted() ) {
546 return false;
547 }
548 if ( !$this->mTitle->userCanEditCssSubpage() ) {
549 return false;
550 }
551 if ( !$this->mTitle->userCanEditJsSubpage() ) {
552 return false;
553 }
554
555 return $wgUser->matchEditToken(
556 $wgRequest->getVal( 'wpEditToken' ) );
557 }
558
559 /**
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?
564 *
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-
568 * dered deprecated.
569 *
570 * @param $skinName String: If set, overrides the skin name
571 * @return string
572 */
573 public function generateUserJs( $skinName = null ) {
574
575 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
576
577 return '';
578 }
579
580 /**
581 * Generate user stylesheet for action=raw&gen=css
582 */
583 public function generateUserStylesheet() {
584
585 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
586
587 return '';
588 }
589
590 /**
591 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
592 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
593 */
594 protected function reallyGenerateUserStylesheet() {
595
596 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
597
598 return '';
599 }
600
601 /**
602 * @private
603 */
604 function setupUserCss( OutputPage $out ) {
605 global $wgRequest;
606 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
607
608 wfProfileIn( __METHOD__ );
609
610 $this->setupSkinUserCss( $out );
611 // Add any extension CSS
612 foreach ( $out->getExtStyle() as $url ) {
613 $out->addStyle( $url );
614 }
615
616 // Per-site custom styles
617 if ( $wgUseSiteCss ) {
618 $out->addModuleStyles( 'site' );
619 }
620
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' ) );
626 } else {
627 $out->addModuleStyles( 'user' );
628 }
629 }
630
631 // Per-user preference styles
632 if ( $wgAllowUserCssPrefs ) {
633 $out->addModuleStyles( 'user.options' );
634 }
635
636 wfProfileOut( __METHOD__ );
637 }
638
639 /**
640 * Get the query to generate a dynamic stylesheet
641 *
642 * @return array
643 */
644 public static function getDynamicStylesheetQuery() {
645 global $wgSquidMaxage;
646
647 return array(
648 'action' => 'raw',
649 'maxage' => $wgSquidMaxage,
650 'usemsgcache' => 'yes',
651 'ctype' => 'text/css',
652 'smaxage' => $wgSquidMaxage,
653 );
654 }
655
656 /**
657 * Add skin specific stylesheets
658 * @param $out OutputPage
659 */
660 function setupSkinUserCss( OutputPage $out ) {
661 $out->addModuleStyles( 'mediawiki.legacy.shared' );
662 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
663 }
664
665 function getPageClasses( $title ) {
666 $numeric = 'ns-' . $title->getNamespace();
667
668 if ( $title->getNamespace() == NS_SPECIAL ) {
669 $type = 'ns-special';
670 } elseif ( $title->isTalkPage() ) {
671 $type = 'ns-talk';
672 } else {
673 $type = 'ns-subject';
674 }
675
676 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
677
678 return "$numeric $type $name";
679 }
680
681 /**
682 * This will be called by OutputPage::headElement when it is creating the
683 * <body> tag, skins can override it if they have a need to add in any
684 * body attributes or classes of their own.
685 */
686 function addToBodyAttributes( $out, &$bodyAttrs ) {
687 // does nothing by default
688 }
689
690 /**
691 * URL to the logo
692 */
693 function getLogo() {
694 global $wgLogo;
695 return $wgLogo;
696 }
697
698 /**
699 * This will be called immediately after the <body> tag. Split into
700 * two functions to make it easier to subclass.
701 */
702 function beforeContent() {
703 return $this->doBeforeContent();
704 }
705
706 function doBeforeContent() {
707 global $wgContLang;
708 wfProfileIn( __METHOD__ );
709
710 $s = '';
711 $qb = $this->qbSetting();
712
713 $langlinks = $this->otherLanguages();
714 if ( $langlinks ) {
715 $rows = 2;
716 $borderhack = '';
717 } else {
718 $rows = 1;
719 $langlinks = false;
720 $borderhack = 'class="top"';
721 }
722
723 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
724 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
725
726 $shove = ( $qb != 0 );
727 $left = ( $qb == 1 || $qb == 3 );
728
729 if ( !$shove ) {
730 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
731 $this->logoText() . '</td>';
732 } elseif ( $left ) {
733 $s .= $this->getQuickbarCompensator( $rows );
734 }
735
736 $l = $wgContLang->alignStart();
737 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
738
739 $s .= $this->topLinks();
740 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
741
742 $r = $wgContLang->alignEnd();
743 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
744 $s .= $this->nameAndLogin();
745 $s .= "\n<br />" . $this->searchForm() . '</td>';
746
747 if ( $langlinks ) {
748 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
749 }
750
751 if ( $shove && !$left ) { # Right
752 $s .= $this->getQuickbarCompensator( $rows );
753 }
754
755 $s .= "</tr>\n</table>\n</div>\n";
756 $s .= "\n<div id='article'>\n";
757
758 $notice = wfGetSiteNotice();
759
760 if ( $notice ) {
761 $s .= "\n<div id='siteNotice'>$notice</div>\n";
762 }
763 $s .= $this->pageTitle();
764 $s .= $this->pageSubtitle();
765 $s .= $this->getCategories();
766
767 wfProfileOut( __METHOD__ );
768 return $s;
769 }
770
771 function getCategoryLinks() {
772 global $wgOut, $wgUseCategoryBrowser;
773 global $wgContLang, $wgUser;
774
775 if ( count( $wgOut->mCategoryLinks ) == 0 ) {
776 return '';
777 }
778
779 # Separator
780 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
781
782 // Use Unicode bidi embedding override characters,
783 // to make sure links don't smash each other up in ugly ways.
784 $dir = $wgContLang->getDir();
785 $embed = "<span dir='$dir'>";
786 $pop = '</span>';
787
788 $allCats = $wgOut->getCategoryLinks();
789 $s = '';
790 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
791
792 if ( !empty( $allCats['normal'] ) ) {
793 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
794
795 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
796 $s .= '<div id="mw-normal-catlinks">' .
797 $this->link( Title::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
798 . $colon . $t . '</div>';
799 }
800
801 # Hidden categories
802 if ( isset( $allCats['hidden'] ) ) {
803 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
804 $class = 'mw-hidden-cats-user-shown';
805 } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
806 $class = 'mw-hidden-cats-ns-shown';
807 } else {
808 $class = 'mw-hidden-cats-hidden';
809 }
810
811 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
812 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
813 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
814 '</div>';
815 }
816
817 # optional 'dmoz-like' category browser. Will be shown under the list
818 # of categories an article belong to
819 if ( $wgUseCategoryBrowser ) {
820 $s .= '<br /><hr />';
821
822 # get a big array of the parents tree
823 $parenttree = $this->mTitle->getParentCategoryTree();
824 # Skin object passed by reference cause it can not be
825 # accessed under the method subfunction drawCategoryBrowser
826 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
827 # Clean out bogus first entry and sort them
828 unset( $tempout[0] );
829 asort( $tempout );
830 # Output one per line
831 $s .= implode( "<br />\n", $tempout );
832 }
833
834 return $s;
835 }
836
837 /**
838 * Render the array as a serie of links.
839 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
840 * @param &skin Object: skin passed by reference
841 * @return String separated by &gt;, terminate with "\n"
842 */
843 function drawCategoryBrowser( $tree, &$skin ) {
844 $return = '';
845
846 foreach ( $tree as $element => $parent ) {
847 if ( empty( $parent ) ) {
848 # element start a new list
849 $return .= "\n";
850 } else {
851 # grab the others elements
852 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' &gt; ';
853 }
854
855 # add our current element to the list
856 $eltitle = Title::newFromText( $element );
857 $return .= $skin->link( $eltitle, $eltitle->getText() );
858 }
859
860 return $return;
861 }
862
863 function getCategories() {
864 $catlinks = $this->getCategoryLinks();
865
866 $classes = 'catlinks';
867
868 global $wgOut, $wgUser;
869
870 // Check what we're showing
871 $allCats = $wgOut->getCategoryLinks();
872 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
873 $this->mTitle->getNamespace() == NS_CATEGORY;
874
875 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
876 $classes .= ' catlinks-allhidden';
877 }
878
879 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
880 }
881
882 function getQuickbarCompensator( $rows = 1 ) {
883 return "<td width='152' rowspan='{$rows}'>&#160;</td>";
884 }
885
886 /**
887 * This runs a hook to allow extensions placing their stuff after content
888 * and article metadata (e.g. categories).
889 * Note: This function has nothing to do with afterContent().
890 *
891 * This hook is placed here in order to allow using the same hook for all
892 * skins, both the SkinTemplate based ones and the older ones, which directly
893 * use this class to get their data.
894 *
895 * The output of this function gets processed in SkinTemplate::outputPage() for
896 * the SkinTemplate based skins, all other skins should directly echo it.
897 *
898 * Returns an empty string by default, if not changed by any hook function.
899 */
900 protected function afterContentHook() {
901 $data = '';
902
903 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
904 // adding just some spaces shouldn't toggle the output
905 // of the whole <div/>, so we use trim() here
906 if ( trim( $data ) != '' ) {
907 // Doing this here instead of in the skins to
908 // ensure that the div has the same ID in all
909 // skins
910 $data = "<div id='mw-data-after-content'>\n" .
911 "\t$data\n" .
912 "</div>\n";
913 }
914 } else {
915 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
916 }
917
918 return $data;
919 }
920
921 /**
922 * Generate debug data HTML for displaying at the bottom of the main content
923 * area.
924 * @return String HTML containing debug data, if enabled (otherwise empty).
925 */
926 protected function generateDebugHTML() {
927 global $wgShowDebug, $wgOut;
928
929 if ( $wgShowDebug ) {
930 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext );
931 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
932 $listInternals . "</ul>\n";
933 }
934
935 return '';
936 }
937
938 private function formatDebugHTML( $debugText ) {
939 $lines = explode( "\n", $debugText );
940 $curIdent = 0;
941 $ret = '<li>';
942
943 foreach ( $lines as $line ) {
944 $display = ltrim( $line );
945 $ident = strlen( $line ) - strlen( $display );
946 $diff = $ident - $curIdent;
947
948 if ( $display == '' ) {
949 $display = "\xc2\xa0";
950 }
951
952 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
953 $ident = $curIdent;
954 $diff = 0;
955 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
956 } else {
957 $display = htmlspecialchars( $display );
958 }
959
960 if ( $diff < 0 ) {
961 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
962 } elseif ( $diff == 0 ) {
963 $ret .= "</li><li>\n";
964 } else {
965 $ret .= str_repeat( "<ul><li>\n", $diff );
966 }
967 $ret .= $display . "\n";
968
969 $curIdent = $ident;
970 }
971
972 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
973
974 return $ret;
975 }
976
977 /**
978 * This gets called shortly before the </body> tag.
979 * @return String HTML to be put before </body>
980 */
981 function afterContent() {
982 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
983 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
984 }
985
986 /**
987 * This gets called shortly before the </body> tag.
988 * @param $out OutputPage object
989 * @return String HTML-wrapped JS code to be put before </body>
990 */
991 function bottomScripts( $out ) {
992 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
993 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
994
995 return $bottomScriptText;
996 }
997
998 /** @return string Retrievied from HTML text */
999 function printSource() {
1000 $url = htmlspecialchars( $this->mTitle->getFullURL() );
1001 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
1002 }
1003
1004 function printFooter() {
1005 return "<p>" . $this->printSource() .
1006 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
1007 }
1008
1009 /** overloaded by derived classes */
1010 function doAfterContent() {
1011 return '</div></div>';
1012 }
1013
1014 function pageTitleLinks() {
1015 global $wgOut, $wgUser, $wgRequest, $wgLang;
1016
1017 $oldid = $wgRequest->getVal( 'oldid' );
1018 $diff = $wgRequest->getVal( 'diff' );
1019 $action = $wgRequest->getText( 'action' );
1020
1021 $s[] = $this->printableLink();
1022 $disclaimer = $this->disclaimerLink(); # may be empty
1023
1024 if ( $disclaimer ) {
1025 $s[] = $disclaimer;
1026 }
1027
1028 $privacy = $this->privacyLink(); # may be empty too
1029
1030 if ( $privacy ) {
1031 $s[] = $privacy;
1032 }
1033
1034 if ( $wgOut->isArticleRelated() ) {
1035 if ( $this->mTitle->getNamespace() == NS_FILE ) {
1036 $name = $this->mTitle->getDBkey();
1037 $image = wfFindFile( $this->mTitle );
1038
1039 if ( $image ) {
1040 $link = htmlspecialchars( $image->getURL() );
1041 $style = $this->getInternalLinkAttributes( $link, $name );
1042 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1043 }
1044 }
1045 }
1046
1047 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
1048 $s[] .= $this->link(
1049 $this->mTitle,
1050 wfMsg( 'currentrev' ),
1051 array(),
1052 array(),
1053 array( 'known', 'noclasses' )
1054 );
1055 }
1056
1057 if ( $wgUser->getNewtalk() ) {
1058 # do not show "You have new messages" text when we are viewing our
1059 # own talk page
1060 if ( !$this->mTitle->equals( $wgUser->getTalkPage() ) ) {
1061 $tl = $this->link(
1062 $wgUser->getTalkPage(),
1063 wfMsgHtml( 'newmessageslink' ),
1064 array(),
1065 array( 'redirect' => 'no' ),
1066 array( 'known', 'noclasses' )
1067 );
1068
1069 $dl = $this->link(
1070 $wgUser->getTalkPage(),
1071 wfMsgHtml( 'newmessagesdifflink' ),
1072 array(),
1073 array( 'diff' => 'cur' ),
1074 array( 'known', 'noclasses' )
1075 );
1076 $s[] = '<strong>' . wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1077 # disable caching
1078 $wgOut->setSquidMaxage( 0 );
1079 $wgOut->enableClientCache( false );
1080 }
1081 }
1082
1083 $undelete = $this->getUndeleteLink();
1084
1085 if ( !empty( $undelete ) ) {
1086 $s[] = $undelete;
1087 }
1088
1089 return $wgLang->pipeList( $s );
1090 }
1091
1092 function getUndeleteLink() {
1093 global $wgUser, $wgLang, $wgRequest;
1094
1095 $action = $wgRequest->getVal( 'action', 'view' );
1096
1097 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1098 ( $this->mTitle->getArticleId() == 0 || $action == 'history' ) ) {
1099 $n = $this->mTitle->isDeleted();
1100
1101 if ( $n ) {
1102 if ( $wgUser->isAllowed( 'undelete' ) ) {
1103 $msg = 'thisisdeleted';
1104 } else {
1105 $msg = 'viewdeleted';
1106 }
1107
1108 return wfMsg(
1109 $msg,
1110 $this->link(
1111 SpecialPage::getTitleFor( 'Undelete', $this->mTitle->getPrefixedDBkey() ),
1112 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1113 array(),
1114 array(),
1115 array( 'known', 'noclasses' )
1116 )
1117 );
1118 }
1119 }
1120
1121 return '';
1122 }
1123
1124 function printableLink() {
1125 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1126
1127 $s = array();
1128
1129 if ( !$wgOut->isPrintable() ) {
1130 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1131 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1132 }
1133
1134 if ( $wgOut->isSyndicated() ) {
1135 foreach ( $wgFeedClasses as $format => $class ) {
1136 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1137 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1138 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1139 }
1140 }
1141 return $wgLang->pipeList( $s );
1142 }
1143
1144 /**
1145 * Gets the h1 element with the page title.
1146 * @return string
1147 */
1148 function pageTitle() {
1149 global $wgOut;
1150 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1151 return $s;
1152 }
1153
1154 function pageSubtitle() {
1155 global $wgOut;
1156
1157 $sub = $wgOut->getSubtitle();
1158
1159 if ( $sub == '' ) {
1160 global $wgExtraSubtitle;
1161 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1162 }
1163
1164 $subpages = $this->subPageSubtitle();
1165 $sub .= !empty( $subpages ) ? "</p><p class='subpages'>$subpages" : '';
1166 $s = "<p class='subtitle'>{$sub}</p>\n";
1167
1168 return $s;
1169 }
1170
1171 function subPageSubtitle() {
1172 $subpages = '';
1173
1174 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this ) ) ) {
1175 return $subpages;
1176 }
1177
1178 global $wgOut;
1179
1180 if ( $wgOut->isArticle() && MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
1181 $ptext = $this->mTitle->getPrefixedText();
1182 if ( preg_match( '/\//', $ptext ) ) {
1183 $links = explode( '/', $ptext );
1184 array_pop( $links );
1185 $c = 0;
1186 $growinglink = '';
1187 $display = '';
1188
1189 foreach ( $links as $link ) {
1190 $growinglink .= $link;
1191 $display .= $link;
1192 $linkObj = Title::newFromText( $growinglink );
1193
1194 if ( is_object( $linkObj ) && $linkObj->exists() ) {
1195 $getlink = $this->link(
1196 $linkObj,
1197 htmlspecialchars( $display ),
1198 array(),
1199 array(),
1200 array( 'known', 'noclasses' )
1201 );
1202
1203 $c++;
1204
1205 if ( $c > 1 ) {
1206 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1207 } else {
1208 $subpages .= '&lt; ';
1209 }
1210
1211 $subpages .= $getlink;
1212 $display = '';
1213 } else {
1214 $display .= '/';
1215 }
1216 $growinglink .= '/';
1217 }
1218 }
1219 }
1220
1221 return $subpages;
1222 }
1223
1224 /**
1225 * Returns true if the IP should be shown in the header
1226 */
1227 function showIPinHeader() {
1228 global $wgShowIPinHeader;
1229 return $wgShowIPinHeader && session_id() != '';
1230 }
1231
1232 function nameAndLogin() {
1233 global $wgUser, $wgLang, $wgContLang;
1234
1235 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1236
1237 $ret = '';
1238
1239 if ( $wgUser->isAnon() ) {
1240 if ( $this->showIPinHeader() ) {
1241 $name = wfGetIP();
1242
1243 $talkLink = $this->link( $wgUser->getTalkPage(),
1244 $wgLang->getNsText( NS_TALK ) );
1245
1246 $ret .= "$name ($talkLink)";
1247 } else {
1248 $ret .= wfMsg( 'notloggedin' );
1249 }
1250
1251 $returnTo = $this->mTitle->getPrefixedDBkey();
1252 $query = array();
1253
1254 if ( $logoutPage != $returnTo ) {
1255 $query['returnto'] = $returnTo;
1256 }
1257
1258 $loginlink = $wgUser->isAllowed( 'createaccount' )
1259 ? 'nav-login-createaccount'
1260 : 'login';
1261 $ret .= "\n<br />" . $this->link(
1262 SpecialPage::getTitleFor( 'Userlogin' ),
1263 wfMsg( $loginlink ), array(), $query
1264 );
1265 } else {
1266 $returnTo = $this->mTitle->getPrefixedDBkey();
1267 $talkLink = $this->link( $wgUser->getTalkPage(),
1268 $wgLang->getNsText( NS_TALK ) );
1269
1270 $ret .= $this->link( $wgUser->getUserPage(),
1271 htmlspecialchars( $wgUser->getName() ) );
1272 $ret .= " ($talkLink)<br />";
1273 $ret .= $wgLang->pipeList( array(
1274 $this->link(
1275 SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1276 array(), array( 'returnto' => $returnTo )
1277 ),
1278 $this->specialLink( 'Preferences' ),
1279 ) );
1280 }
1281
1282 $ret = $wgLang->pipeList( array(
1283 $ret,
1284 $this->link(
1285 Title::newFromText( wfMsgForContent( 'helppage' ) ),
1286 wfMsg( 'help' )
1287 ),
1288 ) );
1289
1290 return $ret;
1291 }
1292
1293 function getSearchLink() {
1294 $searchPage = SpecialPage::getTitleFor( 'Search' );
1295 return $searchPage->getLocalURL();
1296 }
1297
1298 function escapeSearchLink() {
1299 return htmlspecialchars( $this->getSearchLink() );
1300 }
1301
1302 function searchForm() {
1303 global $wgRequest, $wgUseTwoButtonsSearchForm;
1304
1305 $search = $wgRequest->getText( 'search' );
1306
1307 $s = '<form id="searchform' . $this->searchboxes . '" name="search" class="inline" method="post" action="'
1308 . $this->escapeSearchLink() . "\">\n"
1309 . '<input type="text" id="searchInput' . $this->searchboxes . '" name="search" size="19" value="'
1310 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1311 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1312
1313 if ( $wgUseTwoButtonsSearchForm ) {
1314 $s .= '&#160;<input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1315 } else {
1316 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1317 }
1318
1319 $s .= '</form>';
1320
1321 // Ensure unique id's for search boxes made after the first
1322 $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
1323
1324 return $s;
1325 }
1326
1327 function topLinks() {
1328 global $wgOut;
1329
1330 $s = array(
1331 $this->mainPageLink(),
1332 $this->specialLink( 'Recentchanges' )
1333 );
1334
1335 if ( $wgOut->isArticleRelated() ) {
1336 $s[] = $this->editThisPage();
1337 $s[] = $this->historyLink();
1338 }
1339
1340 # Many people don't like this dropdown box
1341 # $s[] = $this->specialPagesList();
1342
1343 if ( $this->variantLinks() ) {
1344 $s[] = $this->variantLinks();
1345 }
1346
1347 if ( $this->extensionTabLinks() ) {
1348 $s[] = $this->extensionTabLinks();
1349 }
1350
1351 // @todo FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1352 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1353 }
1354
1355 /**
1356 * Compatibility for extensions adding functionality through tabs.
1357 * Eventually these old skins should be replaced with SkinTemplate-based
1358 * versions, sigh...
1359 * @return string
1360 */
1361 function extensionTabLinks() {
1362 $tabs = array();
1363 $out = '';
1364 $s = array();
1365 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1366 foreach ( $tabs as $tab ) {
1367 $s[] = Xml::element( 'a',
1368 array( 'href' => $tab['href'] ),
1369 $tab['text'] );
1370 }
1371
1372 if ( count( $s ) ) {
1373 global $wgLang;
1374
1375 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1376 $out .= $wgLang->pipeList( $s );
1377 }
1378
1379 return $out;
1380 }
1381
1382 /**
1383 * Language/charset variant links for classic-style skins
1384 * @return string
1385 */
1386 function variantLinks() {
1387 $s = '';
1388
1389 /* show links to different language variants */
1390 global $wgDisableLangConversion, $wgLang, $wgContLang;
1391
1392 $variants = $wgContLang->getVariants();
1393
1394 if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1395 foreach ( $variants as $code ) {
1396 $varname = $wgContLang->getVariantname( $code );
1397
1398 if ( $varname == 'disable' ) {
1399 continue;
1400 }
1401 $s = $wgLang->pipeList( array(
1402 $s,
1403 '<a href="' . $this->mTitle->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1404 ) );
1405 }
1406 }
1407
1408 return $s;
1409 }
1410
1411 function bottomLinks() {
1412 global $wgOut, $wgUser, $wgUseTrackbacks;
1413 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1414
1415 $s = '';
1416 if ( $wgOut->isArticleRelated() ) {
1417 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1418
1419 if ( $wgUser->isLoggedIn() ) {
1420 $element[] = $this->watchThisPage();
1421 }
1422
1423 $element[] = $this->talkLink();
1424 $element[] = $this->historyLink();
1425 $element[] = $this->whatLinksHere();
1426 $element[] = $this->watchPageLinksLink();
1427
1428 if ( $wgUseTrackbacks ) {
1429 $element[] = $this->trackbackLink();
1430 }
1431
1432 if (
1433 $this->mTitle->getNamespace() == NS_USER ||
1434 $this->mTitle->getNamespace() == NS_USER_TALK
1435 ) {
1436 $id = User::idFromName( $this->mTitle->getText() );
1437 $ip = User::isIP( $this->mTitle->getText() );
1438
1439 # Both anons and non-anons have contributions list
1440 if ( $id || $ip ) {
1441 $element[] = $this->userContribsLink();
1442 }
1443
1444 if ( $this->showEmailUser( $id ) ) {
1445 $element[] = $this->emailUserLink();
1446 }
1447 }
1448
1449 $s = implode( $element, $sep );
1450
1451 if ( $this->mTitle->getArticleId() ) {
1452 $s .= "\n<br />";
1453
1454 // Delete/protect/move links for privileged users
1455 if ( $wgUser->isAllowed( 'delete' ) ) {
1456 $s .= $this->deleteThisPage();
1457 }
1458
1459 if ( $wgUser->isAllowed( 'protect' ) ) {
1460 $s .= $sep . $this->protectThisPage();
1461 }
1462
1463 if ( $wgUser->isAllowed( 'move' ) ) {
1464 $s .= $sep . $this->moveThisPage();
1465 }
1466 }
1467
1468 $s .= "<br />\n" . $this->otherLanguages();
1469 }
1470
1471 return $s;
1472 }
1473
1474 function pageStats() {
1475 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1476 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1477
1478 if ( !is_null( $wgRequest->getVal( 'oldid' ) ) || !is_null( $wgRequest->getVal( 'diff' ) ) ) {
1479 return '';
1480 }
1481
1482 if ( !$wgOut->isArticle() || !$this->mTitle->exists() ) {
1483 return '';
1484 }
1485
1486 $s = '';
1487
1488 if ( !$wgDisableCounters ) {
1489 $count = $wgLang->formatNum( $wgArticle->getCount() );
1490
1491 if ( $count ) {
1492 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1493 }
1494 }
1495
1496 if ( $wgMaxCredits != 0 ) {
1497 $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1498 } else {
1499 $s .= $this->lastModified();
1500 }
1501
1502 if ( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1503 $dbr = wfGetDB( DB_SLAVE );
1504 $res = $dbr->select(
1505 'watchlist',
1506 array( 'COUNT(*) AS n' ),
1507 array(
1508 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ),
1509 'wl_namespace' => $this->mTitle->getNamespace()
1510 ),
1511 __METHOD__
1512 );
1513 $x = $dbr->fetchObject( $res );
1514
1515 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1516 array( 'parseinline' ), $wgLang->formatNum( $x->n )
1517 );
1518 }
1519
1520 return $s . ' ' . $this->getCopyright();
1521 }
1522
1523 function getCopyright( $type = 'detect' ) {
1524 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1525
1526 if ( $type == 'detect' ) {
1527 $diff = $wgRequest->getVal( 'diff' );
1528
1529 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1530 $type = 'history';
1531 } else {
1532 $type = 'normal';
1533 }
1534 }
1535
1536 if ( $type == 'history' ) {
1537 $msg = 'history_copyright';
1538 } else {
1539 $msg = 'copyright';
1540 }
1541
1542 $out = '';
1543
1544 if ( $wgRightsPage ) {
1545 $title = Title::newFromText( $wgRightsPage );
1546 $link = $this->linkKnown( $title, $wgRightsText );
1547 } elseif ( $wgRightsUrl ) {
1548 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1549 } elseif ( $wgRightsText ) {
1550 $link = $wgRightsText;
1551 } else {
1552 # Give up now
1553 return $out;
1554 }
1555
1556 // Allow for site and per-namespace customization of copyright notice.
1557 $forContent = true;
1558
1559 wfRunHooks( 'SkinCopyrightFooter', array( $this->mTitle, $type, &$msg, &$link, &$forContent ) );
1560
1561 if ( $forContent ) {
1562 $out .= wfMsgForContent( $msg, $link );
1563 } else {
1564 $out .= wfMsg( $msg, $link );
1565 }
1566
1567 return $out;
1568 }
1569
1570 function getCopyrightIcon() {
1571 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1572
1573 $out = '';
1574
1575 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1576 $out = $wgCopyrightIcon;
1577 } elseif ( $wgRightsIcon ) {
1578 $icon = htmlspecialchars( $wgRightsIcon );
1579
1580 if ( $wgRightsUrl ) {
1581 $url = htmlspecialchars( $wgRightsUrl );
1582 $out .= '<a href="' . $url . '">';
1583 }
1584
1585 $text = htmlspecialchars( $wgRightsText );
1586 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1587
1588 if ( $wgRightsUrl ) {
1589 $out .= '</a>';
1590 }
1591 }
1592
1593 return $out;
1594 }
1595
1596 /**
1597 * Gets the powered by MediaWiki icon.
1598 * @return string
1599 */
1600 function getPoweredBy() {
1601 global $wgStylePath;
1602
1603 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1604 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1605 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
1606 return $text;
1607 }
1608
1609 function lastModified() {
1610 global $wgLang, $wgArticle;
1611
1612 if ( !$this->isRevisionCurrent() ) {
1613 $timestamp = Revision::getTimestampFromId( $this->mTitle, $this->mRevisionId );
1614 } else {
1615 $timestamp = $wgArticle->getTimestamp();
1616 }
1617
1618 if ( $timestamp ) {
1619 $d = $wgLang->date( $timestamp, true );
1620 $t = $wgLang->time( $timestamp, true );
1621 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1622 } else {
1623 $s = '';
1624 }
1625
1626 if ( wfGetLB()->getLaggedSlaveMode() ) {
1627 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1628 }
1629
1630 return $s;
1631 }
1632
1633 function logoText( $align = '' ) {
1634 if ( $align != '' ) {
1635 $a = " align='{$align}'";
1636 } else {
1637 $a = '';
1638 }
1639
1640 $mp = wfMsg( 'mainpage' );
1641 $mptitle = Title::newMainPage();
1642 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
1643
1644 $logourl = $this->getLogo();
1645 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1646
1647 return $s;
1648 }
1649
1650 /**
1651 * Show a drop-down box of special pages
1652 */
1653 function specialPagesList() {
1654 global $wgContLang, $wgServer, $wgRedirectScript;
1655
1656 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1657
1658 foreach ( $pages as $name => $page ) {
1659 $pages[$name] = $page->getDescription();
1660 }
1661
1662 $go = wfMsg( 'go' );
1663 $sp = wfMsg( 'specialpages' );
1664 $spp = $wgContLang->specialPage( 'Specialpages' );
1665
1666 $s = '<form id="specialpages" method="get" ' .
1667 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1668 $s .= "<select name=\"wpDropdown\">\n";
1669 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1670
1671
1672 foreach ( $pages as $name => $desc ) {
1673 $p = $wgContLang->specialPage( $name );
1674 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1675 }
1676
1677 $s .= "</select>\n";
1678 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1679 $s .= "</form>\n";
1680
1681 return $s;
1682 }
1683
1684 /**
1685 * Renders a $wgFooterIcons icon acording to the method's arguments
1686 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
1687 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
1688 */
1689 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
1690 if ( is_string( $icon ) ) {
1691 $html = $icon;
1692 } else { // Assuming array
1693 $url = $icon["url"];
1694 unset( $icon["url"] );
1695 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
1696 $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1697 } else {
1698 $html = htmlspecialchars( $icon["alt"] );
1699 }
1700 if ( $url ) {
1701 $html = Html::rawElement( 'a', array( "href" => $url ), $html );
1702 }
1703 }
1704 return $html;
1705 }
1706
1707 /**
1708 * Gets the link to the wiki's main page.
1709 * @return string
1710 */
1711 function mainPageLink() {
1712 $s = $this->link(
1713 Title::newMainPage(),
1714 wfMsg( 'mainpage' ),
1715 array(),
1716 array(),
1717 array( 'known', 'noclasses' )
1718 );
1719
1720 return $s;
1721 }
1722
1723 public function footerLink( $desc, $page ) {
1724 // if the link description has been set to "-" in the default language,
1725 if ( wfMsgForContent( $desc ) == '-' ) {
1726 // then it is disabled, for all languages.
1727 return '';
1728 } else {
1729 // Otherwise, we display the link for the user, described in their
1730 // language (which may or may not be the same as the default language),
1731 // but we make the link target be the one site-wide page.
1732 $title = Title::newFromText( wfMsgForContent( $page ) );
1733
1734 return $this->linkKnown(
1735 $title,
1736 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1737 );
1738 }
1739 }
1740
1741 /**
1742 * Gets the link to the wiki's privacy policy page.
1743 */
1744 function privacyLink() {
1745 return $this->footerLink( 'privacy', 'privacypage' );
1746 }
1747
1748 /**
1749 * Gets the link to the wiki's about page.
1750 */
1751 function aboutLink() {
1752 return $this->footerLink( 'aboutsite', 'aboutpage' );
1753 }
1754
1755 /**
1756 * Gets the link to the wiki's general disclaimers page.
1757 */
1758 function disclaimerLink() {
1759 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1760 }
1761
1762 function editThisPage() {
1763 global $wgOut;
1764
1765 if ( !$wgOut->isArticleRelated() ) {
1766 $s = wfMsg( 'protectedpage' );
1767 } else {
1768 if ( $this->mTitle->quickUserCan( 'edit' ) && $this->mTitle->exists() ) {
1769 $t = wfMsg( 'editthispage' );
1770 } elseif ( $this->mTitle->quickUserCan( 'create' ) && !$this->mTitle->exists() ) {
1771 $t = wfMsg( 'create-this-page' );
1772 } else {
1773 $t = wfMsg( 'viewsource' );
1774 }
1775
1776 $s = $this->link(
1777 $this->mTitle,
1778 $t,
1779 array(),
1780 $this->editUrlOptions(),
1781 array( 'known', 'noclasses' )
1782 );
1783 }
1784
1785 return $s;
1786 }
1787
1788 /**
1789 * Return URL options for the 'edit page' link.
1790 * This may include an 'oldid' specifier, if the current page view is such.
1791 *
1792 * @return array
1793 * @private
1794 */
1795 function editUrlOptions() {
1796 $options = array( 'action' => 'edit' );
1797
1798 if ( !$this->isRevisionCurrent() ) {
1799 $options['oldid'] = intval( $this->mRevisionId );
1800 }
1801
1802 return $options;
1803 }
1804
1805 function deleteThisPage() {
1806 global $wgUser, $wgRequest;
1807
1808 $diff = $wgRequest->getVal( 'diff' );
1809
1810 if ( $this->mTitle->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1811 $t = wfMsg( 'deletethispage' );
1812
1813 $s = $this->link(
1814 $this->mTitle,
1815 $t,
1816 array(),
1817 array( 'action' => 'delete' ),
1818 array( 'known', 'noclasses' )
1819 );
1820 } else {
1821 $s = '';
1822 }
1823
1824 return $s;
1825 }
1826
1827 function protectThisPage() {
1828 global $wgUser, $wgRequest;
1829
1830 $diff = $wgRequest->getVal( 'diff' );
1831
1832 if ( $this->mTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
1833 if ( $this->mTitle->isProtected() ) {
1834 $text = wfMsg( 'unprotectthispage' );
1835 $query = array( 'action' => 'unprotect' );
1836 } else {
1837 $text = wfMsg( 'protectthispage' );
1838 $query = array( 'action' => 'protect' );
1839 }
1840
1841 $s = $this->link(
1842 $this->mTitle,
1843 $text,
1844 array(),
1845 $query,
1846 array( 'known', 'noclasses' )
1847 );
1848 } else {
1849 $s = '';
1850 }
1851
1852 return $s;
1853 }
1854
1855 function watchThisPage() {
1856 global $wgOut;
1857 ++$this->mWatchLinkNum;
1858
1859 if ( $wgOut->isArticleRelated() ) {
1860 if ( $this->mTitle->userIsWatching() ) {
1861 $text = wfMsg( 'unwatchthispage' );
1862 $query = array( 'action' => 'unwatch' );
1863 $id = 'mw-unwatch-link' . $this->mWatchLinkNum;
1864 } else {
1865 $text = wfMsg( 'watchthispage' );
1866 $query = array( 'action' => 'watch' );
1867 $id = 'mw-watch-link' . $this->mWatchLinkNum;
1868 }
1869
1870 $s = $this->link(
1871 $this->mTitle,
1872 $text,
1873 array( 'id' => $id ),
1874 $query,
1875 array( 'known', 'noclasses' )
1876 );
1877 } else {
1878 $s = wfMsg( 'notanarticle' );
1879 }
1880
1881 return $s;
1882 }
1883
1884 function moveThisPage() {
1885 if ( $this->mTitle->quickUserCan( 'move' ) ) {
1886 return $this->link(
1887 SpecialPage::getTitleFor( 'Movepage' ),
1888 wfMsg( 'movethispage' ),
1889 array(),
1890 array( 'target' => $this->mTitle->getPrefixedDBkey() ),
1891 array( 'known', 'noclasses' )
1892 );
1893 } else {
1894 // no message if page is protected - would be redundant
1895 return '';
1896 }
1897 }
1898
1899 function historyLink() {
1900 return $this->link(
1901 $this->mTitle,
1902 wfMsgHtml( 'history' ),
1903 array( 'rel' => 'archives' ),
1904 array( 'action' => 'history' )
1905 );
1906 }
1907
1908 function whatLinksHere() {
1909 return $this->link(
1910 SpecialPage::getTitleFor( 'Whatlinkshere', $this->mTitle->getPrefixedDBkey() ),
1911 wfMsgHtml( 'whatlinkshere' ),
1912 array(),
1913 array(),
1914 array( 'known', 'noclasses' )
1915 );
1916 }
1917
1918 function userContribsLink() {
1919 return $this->link(
1920 SpecialPage::getTitleFor( 'Contributions', $this->mTitle->getDBkey() ),
1921 wfMsgHtml( 'contributions' ),
1922 array(),
1923 array(),
1924 array( 'known', 'noclasses' )
1925 );
1926 }
1927
1928 function showEmailUser( $id ) {
1929 global $wgUser;
1930 $targetUser = User::newFromId( $id );
1931 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1932 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1933 }
1934
1935 function emailUserLink() {
1936 return $this->link(
1937 SpecialPage::getTitleFor( 'Emailuser', $this->mTitle->getDBkey() ),
1938 wfMsg( 'emailuser' ),
1939 array(),
1940 array(),
1941 array( 'known', 'noclasses' )
1942 );
1943 }
1944
1945 function watchPageLinksLink() {
1946 global $wgOut;
1947
1948 if ( !$wgOut->isArticleRelated() ) {
1949 return '(' . wfMsg( 'notanarticle' ) . ')';
1950 } else {
1951 return $this->link(
1952 SpecialPage::getTitleFor( 'Recentchangeslinked', $this->mTitle->getPrefixedDBkey() ),
1953 wfMsg( 'recentchangeslinked-toolbox' ),
1954 array(),
1955 array(),
1956 array( 'known', 'noclasses' )
1957 );
1958 }
1959 }
1960
1961 function trackbackLink() {
1962 return '<a href="' . $this->mTitle->trackbackURL() . '">'
1963 . wfMsg( 'trackbacklink' ) . '</a>';
1964 }
1965
1966 function otherLanguages() {
1967 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1968
1969 if ( $wgHideInterlanguageLinks ) {
1970 return '';
1971 }
1972
1973 $a = $wgOut->getLanguageLinks();
1974
1975 if ( 0 == count( $a ) ) {
1976 return '';
1977 }
1978
1979 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1980 $first = true;
1981
1982 if ( $wgContLang->isRTL() ) {
1983 $s .= '<span dir="LTR">';
1984 }
1985
1986 foreach ( $a as $l ) {
1987 if ( !$first ) {
1988 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1989 }
1990
1991 $first = false;
1992
1993 $nt = Title::newFromText( $l );
1994 $url = $nt->escapeFullURL();
1995 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1996 $title = htmlspecialchars( $nt->getText() );
1997
1998 if ( $text == '' ) {
1999 $text = $l;
2000 }
2001
2002 $style = $this->getExternalLinkAttributes();
2003 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
2004 }
2005
2006 if ( $wgContLang->isRTL() ) {
2007 $s .= '</span>';
2008 }
2009
2010 return $s;
2011 }
2012
2013 function talkLink() {
2014 if ( NS_SPECIAL == $this->mTitle->getNamespace() ) {
2015 # No discussion links for special pages
2016 return '';
2017 }
2018
2019 $linkOptions = array();
2020
2021 if ( $this->mTitle->isTalkPage() ) {
2022 $link = $this->mTitle->getSubjectPage();
2023 switch( $link->getNamespace() ) {
2024 case NS_MAIN:
2025 $text = wfMsg( 'articlepage' );
2026 break;
2027 case NS_USER:
2028 $text = wfMsg( 'userpage' );
2029 break;
2030 case NS_PROJECT:
2031 $text = wfMsg( 'projectpage' );
2032 break;
2033 case NS_FILE:
2034 $text = wfMsg( 'imagepage' );
2035 # Make link known if image exists, even if the desc. page doesn't.
2036 if ( wfFindFile( $link ) )
2037 $linkOptions[] = 'known';
2038 break;
2039 case NS_MEDIAWIKI:
2040 $text = wfMsg( 'mediawikipage' );
2041 break;
2042 case NS_TEMPLATE:
2043 $text = wfMsg( 'templatepage' );
2044 break;
2045 case NS_HELP:
2046 $text = wfMsg( 'viewhelppage' );
2047 break;
2048 case NS_CATEGORY:
2049 $text = wfMsg( 'categorypage' );
2050 break;
2051 default:
2052 $text = wfMsg( 'articlepage' );
2053 }
2054 } else {
2055 $link = $this->mTitle->getTalkPage();
2056 $text = wfMsg( 'talkpage' );
2057 }
2058
2059 $s = $this->link( $link, $text, array(), array(), $linkOptions );
2060
2061 return $s;
2062 }
2063
2064 function commentLink() {
2065 global $wgOut;
2066
2067 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
2068 return '';
2069 }
2070
2071 # __NEWSECTIONLINK___ changes behaviour here
2072 # If it is present, the link points to this page, otherwise
2073 # it points to the talk page
2074 if ( $this->mTitle->isTalkPage() ) {
2075 $title = $this->mTitle;
2076 } elseif ( $wgOut->showNewSectionLink() ) {
2077 $title = $this->mTitle;
2078 } else {
2079 $title = $this->mTitle->getTalkPage();
2080 }
2081
2082 return $this->link(
2083 $title,
2084 wfMsg( 'postcomment' ),
2085 array(),
2086 array(
2087 'action' => 'edit',
2088 'section' => 'new'
2089 ),
2090 array( 'known', 'noclasses' )
2091 );
2092 }
2093
2094 function getUploadLink() {
2095 global $wgUploadNavigationUrl;
2096
2097 if ( $wgUploadNavigationUrl ) {
2098 # Using an empty class attribute to avoid automatic setting of "external" class
2099 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '' ) );
2100 } else {
2101 return $this->link(
2102 SpecialPage::getTitleFor( 'Upload' ),
2103 wfMsgHtml( 'upload' ),
2104 array(),
2105 array(),
2106 array( 'known', 'noclasses' )
2107 );
2108 }
2109 }
2110
2111 /**
2112 * Return a fully resolved style path url to images or styles stored in the common folder.
2113 * This method returns a url resolved using the configured skin style path
2114 * and includes the style version inside of the url.
2115 * @param $name String: The name or path of a skin resource file
2116 * @return String The fully resolved style path url including styleversion
2117 */
2118 function getCommonStylePath( $name ) {
2119 global $wgStylePath, $wgStyleVersion;
2120 return "$wgStylePath/common/$name?$wgStyleVersion";
2121 }
2122
2123 /**
2124 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
2125 * This method returns a url resolved using the configured skin style path
2126 * and includes the style version inside of the url.
2127 * @param $name String: The name or path of a skin resource file
2128 * @return String The fully resolved style path url including styleversion
2129 */
2130 function getSkinStylePath( $name ) {
2131 global $wgStylePath, $wgStyleVersion;
2132 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
2133 }
2134
2135 /* these are used extensively in SkinTemplate, but also some other places */
2136 static function makeMainPageUrl( $urlaction = '' ) {
2137 $title = Title::newMainPage();
2138 self::checkTitle( $title, '' );
2139
2140 return $title->getLocalURL( $urlaction );
2141 }
2142
2143 static function makeSpecialUrl( $name, $urlaction = '' ) {
2144 $title = SpecialPage::getTitleFor( $name );
2145 return $title->getLocalURL( $urlaction );
2146 }
2147
2148 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2149 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
2150 return $title->getLocalURL( $urlaction );
2151 }
2152
2153 static function makeI18nUrl( $name, $urlaction = '' ) {
2154 $title = Title::newFromText( wfMsgForContent( $name ) );
2155 self::checkTitle( $title, $name );
2156 return $title->getLocalURL( $urlaction );
2157 }
2158
2159 static function makeUrl( $name, $urlaction = '' ) {
2160 $title = Title::newFromText( $name );
2161 self::checkTitle( $title, $name );
2162
2163 return $title->getLocalURL( $urlaction );
2164 }
2165
2166 /**
2167 * If url string starts with http, consider as external URL, else
2168 * internal
2169 */
2170 static function makeInternalOrExternalUrl( $name ) {
2171 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2172 return $name;
2173 } else {
2174 return self::makeUrl( $name );
2175 }
2176 }
2177
2178 # this can be passed the NS number as defined in Language.php
2179 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
2180 $title = Title::makeTitleSafe( $namespace, $name );
2181 self::checkTitle( $title, $name );
2182
2183 return $title->getLocalURL( $urlaction );
2184 }
2185
2186 /* these return an array with the 'href' and boolean 'exists' */
2187 static function makeUrlDetails( $name, $urlaction = '' ) {
2188 $title = Title::newFromText( $name );
2189 self::checkTitle( $title, $name );
2190
2191 return array(
2192 'href' => $title->getLocalURL( $urlaction ),
2193 'exists' => $title->getArticleID() != 0,
2194 );
2195 }
2196
2197 /**
2198 * Make URL details where the article exists (or at least it's convenient to think so)
2199 */
2200 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2201 $title = Title::newFromText( $name );
2202 self::checkTitle( $title, $name );
2203
2204 return array(
2205 'href' => $title->getLocalURL( $urlaction ),
2206 'exists' => true
2207 );
2208 }
2209
2210 # make sure we have some title to operate on
2211 static function checkTitle( &$title, $name ) {
2212 if ( !is_object( $title ) ) {
2213 $title = Title::newFromText( $name );
2214 if ( !is_object( $title ) ) {
2215 $title = Title::newFromText( '--error: link target missing--' );
2216 }
2217 }
2218 }
2219
2220 /**
2221 * Build an array that represents the sidebar(s), the navigation bar among them
2222 *
2223 * @return array
2224 */
2225 function buildSidebar() {
2226 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2227 global $wgLang;
2228 wfProfileIn( __METHOD__ );
2229
2230 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2231
2232 if ( $wgEnableSidebarCache ) {
2233 $cachedsidebar = $parserMemc->get( $key );
2234 if ( $cachedsidebar ) {
2235 wfProfileOut( __METHOD__ );
2236 return $cachedsidebar;
2237 }
2238 }
2239
2240 $bar = array();
2241 $this->addToSidebar( $bar, 'sidebar' );
2242
2243 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2244 if ( $wgEnableSidebarCache ) {
2245 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2246 }
2247
2248 wfProfileOut( __METHOD__ );
2249 return $bar;
2250 }
2251 /**
2252 * Add content from a sidebar system message
2253 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2254 *
2255 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2256 *
2257 * @param &$bar array
2258 * @param $message String
2259 */
2260 function addToSidebar( &$bar, $message ) {
2261 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2262 }
2263
2264 /**
2265 * Add content from plain text
2266 * @since 1.17
2267 * @param &$bar array
2268 * @param $text string
2269 */
2270 function addToSidebarPlain( &$bar, $text ) {
2271 $lines = explode( "\n", $text );
2272 $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.
2273
2274 $heading = '';
2275
2276 foreach ( $lines as $line ) {
2277 if ( strpos( $line, '*' ) !== 0 ) {
2278 continue;
2279 }
2280
2281 if ( strpos( $line, '**' ) !== 0 ) {
2282 $heading = trim( $line, '* ' );
2283 if ( !array_key_exists( $heading, $bar ) ) {
2284 $bar[$heading] = array();
2285 }
2286 } else {
2287 $line = trim( $line, '* ' );
2288
2289 if ( strpos( $line, '|' ) !== false ) { // sanity check
2290 $line = array_map( 'trim', explode( '|', $line, 2 ) );
2291 $link = wfMsgForContent( $line[0] );
2292
2293 if ( $link == '-' ) {
2294 continue;
2295 }
2296
2297 $text = wfMsgExt( $line[1], 'parsemag' );
2298
2299 if ( wfEmptyMsg( $line[1], $text ) ) {
2300 $text = $line[1];
2301 }
2302
2303 if ( wfEmptyMsg( $line[0], $link ) ) {
2304 $link = $line[0];
2305 }
2306
2307 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2308 $href = $link;
2309 } else {
2310 $title = Title::newFromText( $link );
2311
2312 if ( $title ) {
2313 $title = $title->fixSpecialName();
2314 $href = $title->getLocalURL();
2315 } else {
2316 $href = 'INVALID-TITLE';
2317 }
2318 }
2319
2320 $bar[$heading][] = array(
2321 'text' => $text,
2322 'href' => $href,
2323 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2324 'active' => false
2325 );
2326 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
2327 global $wgParser, $wgTitle;
2328
2329 $line = substr( $line, 2, strlen( $line ) - 4 );
2330
2331 $options = new ParserOptions();
2332 $options->setEditSection( false );
2333 $options->setInterfaceMessage( true );
2334 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $options )->getText();
2335 } else {
2336 continue;
2337 }
2338 }
2339 }
2340
2341 if ( count( $wikiBar ) > 0 ) {
2342 $bar = array_merge( $bar, $wikiBar );
2343 }
2344
2345 return $bar;
2346 }
2347
2348 /**
2349 * Should we include common/wikiprintable.css? Skins that have their own
2350 * print stylesheet should override this and return false. (This is an
2351 * ugly hack to get Monobook to play nicely with
2352 * OutputPage::headElement().)
2353 *
2354 * @return bool
2355 */
2356 public function commonPrintStylesheet() {
2357 return true;
2358 }
2359
2360 /**
2361 * Gets new talk page messages for the current user.
2362 * @return MediaWiki message or if no new talk page messages, nothing
2363 */
2364 function getNewtalks() {
2365 global $wgUser, $wgOut;
2366
2367 $newtalks = $wgUser->getNewMessageLinks();
2368 $ntl = '';
2369
2370 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2371 $userTitle = $this->mUser->getUserPage();
2372 $userTalkTitle = $userTitle->getTalkPage();
2373
2374 if ( !$userTalkTitle->equals( $this->mTitle ) ) {
2375 $newMessagesLink = $this->link(
2376 $userTalkTitle,
2377 wfMsgHtml( 'newmessageslink' ),
2378 array(),
2379 array( 'redirect' => 'no' ),
2380 array( 'known', 'noclasses' )
2381 );
2382
2383 $newMessagesDiffLink = $this->link(
2384 $userTalkTitle,
2385 wfMsgHtml( 'newmessagesdifflink' ),
2386 array(),
2387 array( 'diff' => 'cur' ),
2388 array( 'known', 'noclasses' )
2389 );
2390
2391 $ntl = wfMsg(
2392 'youhavenewmessages',
2393 $newMessagesLink,
2394 $newMessagesDiffLink
2395 );
2396 # Disable Squid cache
2397 $wgOut->setSquidMaxage( 0 );
2398 }
2399 } elseif ( count( $newtalks ) ) {
2400 // _>" " for BC <= 1.16
2401 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2402 $msgs = array();
2403
2404 foreach ( $newtalks as $newtalk ) {
2405 $msgs[] = Xml::element(
2406 'a',
2407 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2408 );
2409 }
2410 $parts = implode( $sep, $msgs );
2411 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2412 $wgOut->setSquidMaxage( 0 );
2413 }
2414
2415 return $ntl;
2416 }
2417 }