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