Commit some fixes for comments on r77741
[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, $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 $article = new Article( $this->mTitle, 0 );
1487
1488 $s = '';
1489
1490 if ( !$wgDisableCounters ) {
1491 $count = $wgLang->formatNum( $article->getCount() );
1492
1493 if ( $count ) {
1494 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1495 }
1496 }
1497
1498 if ( $wgMaxCredits != 0 ) {
1499 $s .= ' ' . Credits::getCredits( $article, $wgMaxCredits, $wgShowCreditsIfMax );
1500 } else {
1501 $s .= $this->lastModified( $article );
1502 }
1503
1504 if ( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1505 $dbr = wfGetDB( DB_SLAVE );
1506 $res = $dbr->select(
1507 'watchlist',
1508 array( 'COUNT(*) AS n' ),
1509 array(
1510 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ),
1511 'wl_namespace' => $this->mTitle->getNamespace()
1512 ),
1513 __METHOD__
1514 );
1515 $x = $dbr->fetchObject( $res );
1516
1517 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1518 array( 'parseinline' ), $wgLang->formatNum( $x->n )
1519 );
1520 }
1521
1522 return $s . ' ' . $this->getCopyright();
1523 }
1524
1525 function getCopyright( $type = 'detect' ) {
1526 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1527
1528 if ( $type == 'detect' ) {
1529 $diff = $wgRequest->getVal( 'diff' );
1530
1531 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1532 $type = 'history';
1533 } else {
1534 $type = 'normal';
1535 }
1536 }
1537
1538 if ( $type == 'history' ) {
1539 $msg = 'history_copyright';
1540 } else {
1541 $msg = 'copyright';
1542 }
1543
1544 $out = '';
1545
1546 if ( $wgRightsPage ) {
1547 $title = Title::newFromText( $wgRightsPage );
1548 $link = $this->linkKnown( $title, $wgRightsText );
1549 } elseif ( $wgRightsUrl ) {
1550 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1551 } elseif ( $wgRightsText ) {
1552 $link = $wgRightsText;
1553 } else {
1554 # Give up now
1555 return $out;
1556 }
1557
1558 // Allow for site and per-namespace customization of copyright notice.
1559 $forContent = true;
1560
1561 wfRunHooks( 'SkinCopyrightFooter', array( $this->mTitle, $type, &$msg, &$link, &$forContent ) );
1562
1563 if ( $forContent ) {
1564 $out .= wfMsgForContent( $msg, $link );
1565 } else {
1566 $out .= wfMsg( $msg, $link );
1567 }
1568
1569 return $out;
1570 }
1571
1572 function getCopyrightIcon() {
1573 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1574
1575 $out = '';
1576
1577 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1578 $out = $wgCopyrightIcon;
1579 } elseif ( $wgRightsIcon ) {
1580 $icon = htmlspecialchars( $wgRightsIcon );
1581
1582 if ( $wgRightsUrl ) {
1583 $url = htmlspecialchars( $wgRightsUrl );
1584 $out .= '<a href="' . $url . '">';
1585 }
1586
1587 $text = htmlspecialchars( $wgRightsText );
1588 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1589
1590 if ( $wgRightsUrl ) {
1591 $out .= '</a>';
1592 }
1593 }
1594
1595 return $out;
1596 }
1597
1598 /**
1599 * Gets the powered by MediaWiki icon.
1600 * @return string
1601 */
1602 function getPoweredBy() {
1603 global $wgStylePath;
1604
1605 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1606 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1607 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
1608 return $text;
1609 }
1610
1611 /**
1612 * Get the timestamp of the latest revision, formatted in user language
1613 *
1614 * @param $article Article object. Used if we're working with the current revision
1615 * @return String
1616 */
1617 protected function lastModified( $article ) {
1618 global $wgLang;
1619
1620 if ( !$this->isRevisionCurrent() ) {
1621 $timestamp = Revision::getTimestampFromId( $this->mTitle, $this->mRevisionId );
1622 } else {
1623 $timestamp = $article->getTimestamp();
1624 }
1625
1626 if ( $timestamp ) {
1627 $d = $wgLang->date( $timestamp, true );
1628 $t = $wgLang->time( $timestamp, true );
1629 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1630 } else {
1631 $s = '';
1632 }
1633
1634 if ( wfGetLB()->getLaggedSlaveMode() ) {
1635 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1636 }
1637
1638 return $s;
1639 }
1640
1641 function logoText( $align = '' ) {
1642 if ( $align != '' ) {
1643 $a = " align='{$align}'";
1644 } else {
1645 $a = '';
1646 }
1647
1648 $mp = wfMsg( 'mainpage' );
1649 $mptitle = Title::newMainPage();
1650 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
1651
1652 $logourl = $this->getLogo();
1653 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1654
1655 return $s;
1656 }
1657
1658 /**
1659 * Show a drop-down box of special pages
1660 */
1661 function specialPagesList() {
1662 global $wgContLang, $wgServer, $wgRedirectScript;
1663
1664 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1665
1666 foreach ( $pages as $name => $page ) {
1667 $pages[$name] = $page->getDescription();
1668 }
1669
1670 $go = wfMsg( 'go' );
1671 $sp = wfMsg( 'specialpages' );
1672 $spp = $wgContLang->specialPage( 'Specialpages' );
1673
1674 $s = '<form id="specialpages" method="get" ' .
1675 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1676 $s .= "<select name=\"wpDropdown\">\n";
1677 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1678
1679
1680 foreach ( $pages as $name => $desc ) {
1681 $p = $wgContLang->specialPage( $name );
1682 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1683 }
1684
1685 $s .= "</select>\n";
1686 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1687 $s .= "</form>\n";
1688
1689 return $s;
1690 }
1691
1692 /**
1693 * Renders a $wgFooterIcons icon acording to the method's arguments
1694 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
1695 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
1696 */
1697 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
1698 if ( is_string( $icon ) ) {
1699 $html = $icon;
1700 } else { // Assuming array
1701 $url = isset($icon["url"]) ? $icon["url"] : null;
1702 unset( $icon["url"] );
1703 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
1704 $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1705 } else {
1706 $html = htmlspecialchars( $icon["alt"] );
1707 }
1708 if ( $url ) {
1709 $html = Html::rawElement( 'a', array( "href" => $url ), $html );
1710 }
1711 }
1712 return $html;
1713 }
1714
1715 /**
1716 * Gets the link to the wiki's main page.
1717 * @return string
1718 */
1719 function mainPageLink() {
1720 $s = $this->link(
1721 Title::newMainPage(),
1722 wfMsg( 'mainpage' ),
1723 array(),
1724 array(),
1725 array( 'known', 'noclasses' )
1726 );
1727
1728 return $s;
1729 }
1730
1731 public function footerLink( $desc, $page ) {
1732 // if the link description has been set to "-" in the default language,
1733 if ( wfMsgForContent( $desc ) == '-' ) {
1734 // then it is disabled, for all languages.
1735 return '';
1736 } else {
1737 // Otherwise, we display the link for the user, described in their
1738 // language (which may or may not be the same as the default language),
1739 // but we make the link target be the one site-wide page.
1740 $title = Title::newFromText( wfMsgForContent( $page ) );
1741
1742 return $this->linkKnown(
1743 $title,
1744 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1745 );
1746 }
1747 }
1748
1749 /**
1750 * Gets the link to the wiki's privacy policy page.
1751 */
1752 function privacyLink() {
1753 return $this->footerLink( 'privacy', 'privacypage' );
1754 }
1755
1756 /**
1757 * Gets the link to the wiki's about page.
1758 */
1759 function aboutLink() {
1760 return $this->footerLink( 'aboutsite', 'aboutpage' );
1761 }
1762
1763 /**
1764 * Gets the link to the wiki's general disclaimers page.
1765 */
1766 function disclaimerLink() {
1767 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1768 }
1769
1770 function editThisPage() {
1771 global $wgOut;
1772
1773 if ( !$wgOut->isArticleRelated() ) {
1774 $s = wfMsg( 'protectedpage' );
1775 } else {
1776 if ( $this->mTitle->quickUserCan( 'edit' ) && $this->mTitle->exists() ) {
1777 $t = wfMsg( 'editthispage' );
1778 } elseif ( $this->mTitle->quickUserCan( 'create' ) && !$this->mTitle->exists() ) {
1779 $t = wfMsg( 'create-this-page' );
1780 } else {
1781 $t = wfMsg( 'viewsource' );
1782 }
1783
1784 $s = $this->link(
1785 $this->mTitle,
1786 $t,
1787 array(),
1788 $this->editUrlOptions(),
1789 array( 'known', 'noclasses' )
1790 );
1791 }
1792
1793 return $s;
1794 }
1795
1796 /**
1797 * Return URL options for the 'edit page' link.
1798 * This may include an 'oldid' specifier, if the current page view is such.
1799 *
1800 * @return array
1801 * @private
1802 */
1803 function editUrlOptions() {
1804 $options = array( 'action' => 'edit' );
1805
1806 if ( !$this->isRevisionCurrent() ) {
1807 $options['oldid'] = intval( $this->mRevisionId );
1808 }
1809
1810 return $options;
1811 }
1812
1813 function deleteThisPage() {
1814 global $wgUser, $wgRequest;
1815
1816 $diff = $wgRequest->getVal( 'diff' );
1817
1818 if ( $this->mTitle->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1819 $t = wfMsg( 'deletethispage' );
1820
1821 $s = $this->link(
1822 $this->mTitle,
1823 $t,
1824 array(),
1825 array( 'action' => 'delete' ),
1826 array( 'known', 'noclasses' )
1827 );
1828 } else {
1829 $s = '';
1830 }
1831
1832 return $s;
1833 }
1834
1835 function protectThisPage() {
1836 global $wgUser, $wgRequest;
1837
1838 $diff = $wgRequest->getVal( 'diff' );
1839
1840 if ( $this->mTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
1841 if ( $this->mTitle->isProtected() ) {
1842 $text = wfMsg( 'unprotectthispage' );
1843 $query = array( 'action' => 'unprotect' );
1844 } else {
1845 $text = wfMsg( 'protectthispage' );
1846 $query = array( 'action' => 'protect' );
1847 }
1848
1849 $s = $this->link(
1850 $this->mTitle,
1851 $text,
1852 array(),
1853 $query,
1854 array( 'known', 'noclasses' )
1855 );
1856 } else {
1857 $s = '';
1858 }
1859
1860 return $s;
1861 }
1862
1863 function watchThisPage() {
1864 global $wgOut;
1865 ++$this->mWatchLinkNum;
1866
1867 if ( $wgOut->isArticleRelated() ) {
1868 if ( $this->mTitle->userIsWatching() ) {
1869 $text = wfMsg( 'unwatchthispage' );
1870 $query = array( 'action' => 'unwatch' );
1871 $id = 'mw-unwatch-link' . $this->mWatchLinkNum;
1872 } else {
1873 $text = wfMsg( 'watchthispage' );
1874 $query = array( 'action' => 'watch' );
1875 $id = 'mw-watch-link' . $this->mWatchLinkNum;
1876 }
1877
1878 $s = $this->link(
1879 $this->mTitle,
1880 $text,
1881 array( 'id' => $id ),
1882 $query,
1883 array( 'known', 'noclasses' )
1884 );
1885 } else {
1886 $s = wfMsg( 'notanarticle' );
1887 }
1888
1889 return $s;
1890 }
1891
1892 function moveThisPage() {
1893 if ( $this->mTitle->quickUserCan( 'move' ) ) {
1894 return $this->link(
1895 SpecialPage::getTitleFor( 'Movepage' ),
1896 wfMsg( 'movethispage' ),
1897 array(),
1898 array( 'target' => $this->mTitle->getPrefixedDBkey() ),
1899 array( 'known', 'noclasses' )
1900 );
1901 } else {
1902 // no message if page is protected - would be redundant
1903 return '';
1904 }
1905 }
1906
1907 function historyLink() {
1908 return $this->link(
1909 $this->mTitle,
1910 wfMsgHtml( 'history' ),
1911 array( 'rel' => 'archives' ),
1912 array( 'action' => 'history' )
1913 );
1914 }
1915
1916 function whatLinksHere() {
1917 return $this->link(
1918 SpecialPage::getTitleFor( 'Whatlinkshere', $this->mTitle->getPrefixedDBkey() ),
1919 wfMsgHtml( 'whatlinkshere' ),
1920 array(),
1921 array(),
1922 array( 'known', 'noclasses' )
1923 );
1924 }
1925
1926 function userContribsLink() {
1927 return $this->link(
1928 SpecialPage::getTitleFor( 'Contributions', $this->mTitle->getDBkey() ),
1929 wfMsgHtml( 'contributions' ),
1930 array(),
1931 array(),
1932 array( 'known', 'noclasses' )
1933 );
1934 }
1935
1936 function showEmailUser( $id ) {
1937 global $wgUser;
1938 $targetUser = User::newFromId( $id );
1939 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1940 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1941 }
1942
1943 function emailUserLink() {
1944 return $this->link(
1945 SpecialPage::getTitleFor( 'Emailuser', $this->mTitle->getDBkey() ),
1946 wfMsg( 'emailuser' ),
1947 array(),
1948 array(),
1949 array( 'known', 'noclasses' )
1950 );
1951 }
1952
1953 function watchPageLinksLink() {
1954 global $wgOut;
1955
1956 if ( !$wgOut->isArticleRelated() ) {
1957 return '(' . wfMsg( 'notanarticle' ) . ')';
1958 } else {
1959 return $this->link(
1960 SpecialPage::getTitleFor( 'Recentchangeslinked', $this->mTitle->getPrefixedDBkey() ),
1961 wfMsg( 'recentchangeslinked-toolbox' ),
1962 array(),
1963 array(),
1964 array( 'known', 'noclasses' )
1965 );
1966 }
1967 }
1968
1969 function trackbackLink() {
1970 return '<a href="' . $this->mTitle->trackbackURL() . '">'
1971 . wfMsg( 'trackbacklink' ) . '</a>';
1972 }
1973
1974 function otherLanguages() {
1975 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1976
1977 if ( $wgHideInterlanguageLinks ) {
1978 return '';
1979 }
1980
1981 $a = $wgOut->getLanguageLinks();
1982
1983 if ( 0 == count( $a ) ) {
1984 return '';
1985 }
1986
1987 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1988 $first = true;
1989
1990 if ( $wgContLang->isRTL() ) {
1991 $s .= '<span dir="LTR">';
1992 }
1993
1994 foreach ( $a as $l ) {
1995 if ( !$first ) {
1996 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1997 }
1998
1999 $first = false;
2000
2001 $nt = Title::newFromText( $l );
2002 $url = $nt->escapeFullURL();
2003 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
2004 $title = htmlspecialchars( $nt->getText() );
2005
2006 if ( $text == '' ) {
2007 $text = $l;
2008 }
2009
2010 $style = $this->getExternalLinkAttributes();
2011 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
2012 }
2013
2014 if ( $wgContLang->isRTL() ) {
2015 $s .= '</span>';
2016 }
2017
2018 return $s;
2019 }
2020
2021 function talkLink() {
2022 if ( NS_SPECIAL == $this->mTitle->getNamespace() ) {
2023 # No discussion links for special pages
2024 return '';
2025 }
2026
2027 $linkOptions = array();
2028
2029 if ( $this->mTitle->isTalkPage() ) {
2030 $link = $this->mTitle->getSubjectPage();
2031 switch( $link->getNamespace() ) {
2032 case NS_MAIN:
2033 $text = wfMsg( 'articlepage' );
2034 break;
2035 case NS_USER:
2036 $text = wfMsg( 'userpage' );
2037 break;
2038 case NS_PROJECT:
2039 $text = wfMsg( 'projectpage' );
2040 break;
2041 case NS_FILE:
2042 $text = wfMsg( 'imagepage' );
2043 # Make link known if image exists, even if the desc. page doesn't.
2044 if ( wfFindFile( $link ) )
2045 $linkOptions[] = 'known';
2046 break;
2047 case NS_MEDIAWIKI:
2048 $text = wfMsg( 'mediawikipage' );
2049 break;
2050 case NS_TEMPLATE:
2051 $text = wfMsg( 'templatepage' );
2052 break;
2053 case NS_HELP:
2054 $text = wfMsg( 'viewhelppage' );
2055 break;
2056 case NS_CATEGORY:
2057 $text = wfMsg( 'categorypage' );
2058 break;
2059 default:
2060 $text = wfMsg( 'articlepage' );
2061 }
2062 } else {
2063 $link = $this->mTitle->getTalkPage();
2064 $text = wfMsg( 'talkpage' );
2065 }
2066
2067 $s = $this->link( $link, $text, array(), array(), $linkOptions );
2068
2069 return $s;
2070 }
2071
2072 function commentLink() {
2073 global $wgOut;
2074
2075 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
2076 return '';
2077 }
2078
2079 # __NEWSECTIONLINK___ changes behaviour here
2080 # If it is present, the link points to this page, otherwise
2081 # it points to the talk page
2082 if ( $this->mTitle->isTalkPage() ) {
2083 $title = $this->mTitle;
2084 } elseif ( $wgOut->showNewSectionLink() ) {
2085 $title = $this->mTitle;
2086 } else {
2087 $title = $this->mTitle->getTalkPage();
2088 }
2089
2090 return $this->link(
2091 $title,
2092 wfMsg( 'postcomment' ),
2093 array(),
2094 array(
2095 'action' => 'edit',
2096 'section' => 'new'
2097 ),
2098 array( 'known', 'noclasses' )
2099 );
2100 }
2101
2102 function getUploadLink() {
2103 global $wgUploadNavigationUrl;
2104
2105 if ( $wgUploadNavigationUrl ) {
2106 # Using an empty class attribute to avoid automatic setting of "external" class
2107 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '' ) );
2108 } else {
2109 return $this->link(
2110 SpecialPage::getTitleFor( 'Upload' ),
2111 wfMsgHtml( 'upload' ),
2112 array(),
2113 array(),
2114 array( 'known', 'noclasses' )
2115 );
2116 }
2117 }
2118
2119 /**
2120 * Return a fully resolved style path url to images or styles stored in the common folder.
2121 * This method returns a url resolved using the configured skin style path
2122 * and includes the style version inside of the url.
2123 * @param $name String: The name or path of a skin resource file
2124 * @return String The fully resolved style path url including styleversion
2125 */
2126 function getCommonStylePath( $name ) {
2127 global $wgStylePath, $wgStyleVersion;
2128 return "$wgStylePath/common/$name?$wgStyleVersion";
2129 }
2130
2131 /**
2132 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
2133 * This method returns a url resolved using the configured skin style path
2134 * and includes the style version inside of the url.
2135 * @param $name String: The name or path of a skin resource file
2136 * @return String The fully resolved style path url including styleversion
2137 */
2138 function getSkinStylePath( $name ) {
2139 global $wgStylePath, $wgStyleVersion;
2140 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
2141 }
2142
2143 /* these are used extensively in SkinTemplate, but also some other places */
2144 static function makeMainPageUrl( $urlaction = '' ) {
2145 $title = Title::newMainPage();
2146 self::checkTitle( $title, '' );
2147
2148 return $title->getLocalURL( $urlaction );
2149 }
2150
2151 static function makeSpecialUrl( $name, $urlaction = '' ) {
2152 $title = SpecialPage::getTitleFor( $name );
2153 return $title->getLocalURL( $urlaction );
2154 }
2155
2156 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2157 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
2158 return $title->getLocalURL( $urlaction );
2159 }
2160
2161 static function makeI18nUrl( $name, $urlaction = '' ) {
2162 $title = Title::newFromText( wfMsgForContent( $name ) );
2163 self::checkTitle( $title, $name );
2164 return $title->getLocalURL( $urlaction );
2165 }
2166
2167 static function makeUrl( $name, $urlaction = '' ) {
2168 $title = Title::newFromText( $name );
2169 self::checkTitle( $title, $name );
2170
2171 return $title->getLocalURL( $urlaction );
2172 }
2173
2174 /**
2175 * If url string starts with http, consider as external URL, else
2176 * internal
2177 */
2178 static function makeInternalOrExternalUrl( $name ) {
2179 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2180 return $name;
2181 } else {
2182 return self::makeUrl( $name );
2183 }
2184 }
2185
2186 # this can be passed the NS number as defined in Language.php
2187 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
2188 $title = Title::makeTitleSafe( $namespace, $name );
2189 self::checkTitle( $title, $name );
2190
2191 return $title->getLocalURL( $urlaction );
2192 }
2193
2194 /* these return an array with the 'href' and boolean 'exists' */
2195 static function makeUrlDetails( $name, $urlaction = '' ) {
2196 $title = Title::newFromText( $name );
2197 self::checkTitle( $title, $name );
2198
2199 return array(
2200 'href' => $title->getLocalURL( $urlaction ),
2201 'exists' => $title->getArticleID() != 0,
2202 );
2203 }
2204
2205 /**
2206 * Make URL details where the article exists (or at least it's convenient to think so)
2207 */
2208 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2209 $title = Title::newFromText( $name );
2210 self::checkTitle( $title, $name );
2211
2212 return array(
2213 'href' => $title->getLocalURL( $urlaction ),
2214 'exists' => true
2215 );
2216 }
2217
2218 # make sure we have some title to operate on
2219 static function checkTitle( &$title, $name ) {
2220 if ( !is_object( $title ) ) {
2221 $title = Title::newFromText( $name );
2222 if ( !is_object( $title ) ) {
2223 $title = Title::newFromText( '--error: link target missing--' );
2224 }
2225 }
2226 }
2227
2228 /**
2229 * Build an array that represents the sidebar(s), the navigation bar among them
2230 *
2231 * @return array
2232 */
2233 function buildSidebar() {
2234 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2235 global $wgLang;
2236 wfProfileIn( __METHOD__ );
2237
2238 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2239
2240 if ( $wgEnableSidebarCache ) {
2241 $cachedsidebar = $parserMemc->get( $key );
2242 if ( $cachedsidebar ) {
2243 wfProfileOut( __METHOD__ );
2244 return $cachedsidebar;
2245 }
2246 }
2247
2248 $bar = array();
2249 $this->addToSidebar( $bar, 'sidebar' );
2250
2251 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2252 if ( $wgEnableSidebarCache ) {
2253 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2254 }
2255
2256 wfProfileOut( __METHOD__ );
2257 return $bar;
2258 }
2259 /**
2260 * Add content from a sidebar system message
2261 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2262 *
2263 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2264 *
2265 * @param &$bar array
2266 * @param $message String
2267 */
2268 function addToSidebar( &$bar, $message ) {
2269 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2270 }
2271
2272 /**
2273 * Add content from plain text
2274 * @since 1.17
2275 * @param &$bar array
2276 * @param $text string
2277 */
2278 function addToSidebarPlain( &$bar, $text ) {
2279 $lines = explode( "\n", $text );
2280 $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.
2281
2282 $heading = '';
2283
2284 foreach ( $lines as $line ) {
2285 if ( strpos( $line, '*' ) !== 0 ) {
2286 continue;
2287 }
2288
2289 if ( strpos( $line, '**' ) !== 0 ) {
2290 $heading = trim( $line, '* ' );
2291 if ( !array_key_exists( $heading, $bar ) ) {
2292 $bar[$heading] = array();
2293 }
2294 } else {
2295 $line = trim( $line, '* ' );
2296
2297 if ( strpos( $line, '|' ) !== false ) { // sanity check
2298 $line = array_map( 'trim', explode( '|', $line, 2 ) );
2299 $link = wfMsgForContent( $line[0] );
2300
2301 if ( $link == '-' ) {
2302 continue;
2303 }
2304
2305 $text = wfMsgExt( $line[1], 'parsemag' );
2306
2307 if ( wfEmptyMsg( $line[1], $text ) ) {
2308 $text = $line[1];
2309 }
2310
2311 if ( wfEmptyMsg( $line[0], $link ) ) {
2312 $link = $line[0];
2313 }
2314
2315 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2316 $href = $link;
2317 } else {
2318 $title = Title::newFromText( $link );
2319
2320 if ( $title ) {
2321 $title = $title->fixSpecialName();
2322 $href = $title->getLocalURL();
2323 } else {
2324 $href = 'INVALID-TITLE';
2325 }
2326 }
2327
2328 $bar[$heading][] = array(
2329 'text' => $text,
2330 'href' => $href,
2331 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2332 'active' => false
2333 );
2334 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
2335 global $wgParser, $wgTitle;
2336
2337 $line = substr( $line, 2, strlen( $line ) - 4 );
2338
2339 $options = new ParserOptions();
2340 $options->setEditSection( false );
2341 $options->setInterfaceMessage( true );
2342 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $options )->getText();
2343 } else {
2344 continue;
2345 }
2346 }
2347 }
2348
2349 if ( count( $wikiBar ) > 0 ) {
2350 $bar = array_merge( $bar, $wikiBar );
2351 }
2352
2353 return $bar;
2354 }
2355
2356 /**
2357 * Should we include common/wikiprintable.css? Skins that have their own
2358 * print stylesheet should override this and return false. (This is an
2359 * ugly hack to get Monobook to play nicely with
2360 * OutputPage::headElement().)
2361 *
2362 * @return bool
2363 */
2364 public function commonPrintStylesheet() {
2365 return true;
2366 }
2367
2368 /**
2369 * Gets new talk page messages for the current user.
2370 * @return MediaWiki message or if no new talk page messages, nothing
2371 */
2372 function getNewtalks() {
2373 global $wgUser, $wgOut;
2374
2375 $newtalks = $wgUser->getNewMessageLinks();
2376 $ntl = '';
2377
2378 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2379 $userTitle = $this->mUser->getUserPage();
2380 $userTalkTitle = $userTitle->getTalkPage();
2381
2382 if ( !$userTalkTitle->equals( $this->mTitle ) ) {
2383 $newMessagesLink = $this->link(
2384 $userTalkTitle,
2385 wfMsgHtml( 'newmessageslink' ),
2386 array(),
2387 array( 'redirect' => 'no' ),
2388 array( 'known', 'noclasses' )
2389 );
2390
2391 $newMessagesDiffLink = $this->link(
2392 $userTalkTitle,
2393 wfMsgHtml( 'newmessagesdifflink' ),
2394 array(),
2395 array( 'diff' => 'cur' ),
2396 array( 'known', 'noclasses' )
2397 );
2398
2399 $ntl = wfMsg(
2400 'youhavenewmessages',
2401 $newMessagesLink,
2402 $newMessagesDiffLink
2403 );
2404 # Disable Squid cache
2405 $wgOut->setSquidMaxage( 0 );
2406 }
2407 } elseif ( count( $newtalks ) ) {
2408 // _>" " for BC <= 1.16
2409 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2410 $msgs = array();
2411
2412 foreach ( $newtalks as $newtalk ) {
2413 $msgs[] = Xml::element(
2414 'a',
2415 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2416 );
2417 }
2418 $parts = implode( $sep, $msgs );
2419 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2420 $wgOut->setSquidMaxage( 0 );
2421 }
2422
2423 return $ntl;
2424 }
2425 }