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