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