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