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