Revert 17297 and 17298 for the moment.
[lhc/web/wiklou.git] / includes / Skin.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
4
5 /**
6 *
7 * @package MediaWiki
8 * @subpackage Skins
9 */
10
11 # See skin.txt
12
13 /**
14 * The main skin class that provide methods and properties for all other skins.
15 * This base class is also the "Standard" skin.
16 * @package MediaWiki
17 */
18 class Skin extends Linker {
19 /**#@+
20 * @private
21 */
22 var $lastdate, $lastline;
23 var $rc_cache ; # Cache for Enhanced Recent Changes
24 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
25 var $rcMoveIndex;
26 /**#@-*/
27
28 /** Constructor, call parent constructor */
29 function Skin() { parent::Linker(); }
30
31 /**
32 * Fetch the set of available skins.
33 * @return array of strings
34 * @static
35 */
36 static function &getSkinNames() {
37 global $wgValidSkinNames;
38 static $skinsInitialised = false;
39 if ( !$skinsInitialised ) {
40 # Get a list of available skins
41 # Build using the regular expression '^(.*).php$'
42 # Array keys are all lower case, array value keep the case used by filename
43 #
44 wfProfileIn( __METHOD__ . '-init' );
45 global $wgStyleDirectory;
46 $skinDir = dir( $wgStyleDirectory );
47
48 # while code from www.php.net
49 while (false !== ($file = $skinDir->read())) {
50 // Skip non-PHP files, hidden files, and '.dep' includes
51 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
52 $aSkin = $matches[1];
53 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
54 }
55 }
56 $skinDir->close();
57 $skinsInitialised = true;
58 wfProfileOut( __METHOD__ . '-init' );
59 }
60 return $wgValidSkinNames;
61 }
62
63 /**
64 * Normalize a skin preference value to a form that can be loaded.
65 * If a skin can't be found, it will fall back to the configured
66 * default (or the old 'Classic' skin if that's broken).
67 * @param string $key
68 * @return string
69 * @static
70 */
71 static function normalizeKey( $key ) {
72 global $wgDefaultSkin;
73 $skinNames = Skin::getSkinNames();
74
75 if( $key == '' ) {
76 // Don't return the default immediately;
77 // in a misconfiguration we need to fall back.
78 $key = $wgDefaultSkin;
79 }
80
81 if( isset( $skinNames[$key] ) ) {
82 return $key;
83 }
84
85 // Older versions of the software used a numeric setting
86 // in the user preferences.
87 $fallback = array(
88 0 => $wgDefaultSkin,
89 1 => 'nostalgia',
90 2 => 'cologneblue' );
91
92 if( isset( $fallback[$key] ) ){
93 $key = $fallback[$key];
94 }
95
96 if( isset( $skinNames[$key] ) ) {
97 return $key;
98 } else {
99 // The old built-in skin
100 return 'standard';
101 }
102 }
103
104 /**
105 * Factory method for loading a skin of a given type
106 * @param string $key 'monobook', 'standard', etc
107 * @return Skin
108 * @static
109 */
110 static function &newFromKey( $key ) {
111 global $wgStyleDirectory;
112
113 $key = Skin::normalizeKey( $key );
114
115 $skinNames = Skin::getSkinNames();
116 $skinName = $skinNames[$key];
117
118 # Grab the skin class and initialise it.
119 wfSuppressWarnings();
120 // Preload base classes to work around APC/PHP5 bug
121 include_once( "{$wgStyleDirectory}/{$skinName}.deps.php" );
122 wfRestoreWarnings();
123 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
124
125 # Check if we got if not failback to default skin
126 $className = 'Skin'.$skinName;
127 if( !class_exists( $className ) ) {
128 # DO NOT die if the class isn't found. This breaks maintenance
129 # scripts and can cause a user account to be unrecoverable
130 # except by SQL manipulation if a previously valid skin name
131 # is no longer valid.
132 wfDebug( "Skin class does not exist: $className\n" );
133 $className = 'SkinStandard';
134 require_once( "{$wgStyleDirectory}/Standard.php" );
135 }
136 $skin = new $className;
137 return $skin;
138 }
139
140 /** @return string path to the skin stylesheet */
141 function getStylesheet() {
142 return 'common/wikistandard.css';
143 }
144
145 /** @return string skin name */
146 function getSkinName() {
147 return 'standard';
148 }
149
150 function qbSetting() {
151 global $wgOut, $wgUser;
152
153 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
154 $q = $wgUser->getOption( 'quickbar' );
155 if ( '' == $q ) { $q = 0; }
156 return $q;
157 }
158
159 function initPage( &$out ) {
160 global $wgFavicon, $wgScriptPath, $wgSitename, $wgLanguageCode, $wgLanguageNames;
161
162 $fname = 'Skin::initPage';
163 wfProfileIn( $fname );
164
165 if( false !== $wgFavicon ) {
166 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
167 }
168
169 # OpenSearch description link
170 $out->addLink( array(
171 'rel' => 'search',
172 'type' => 'application/opensearchdescription+xml',
173 'href' => "$wgScriptPath/opensearch_desc.php",
174 'title' => "$wgSitename ({$wgLanguageNames[$wgLanguageCode]})",
175 ));
176
177 $this->addMetadataLinks($out);
178
179 $this->mRevisionId = $out->mRevisionId;
180
181 $this->preloadExistence();
182
183 wfProfileOut( $fname );
184 }
185
186 /**
187 * Preload the existence of three commonly-requested pages in a single query
188 */
189 function preloadExistence() {
190 global $wgUser, $wgTitle;
191
192 if ( $wgTitle->isTalkPage() ) {
193 $otherTab = $wgTitle->getSubjectPage();
194 } else {
195 $otherTab = $wgTitle->getTalkPage();
196 }
197 $lb = new LinkBatch( array(
198 $wgUser->getUserPage(),
199 $wgUser->getTalkPage(),
200 $otherTab
201 ));
202 $lb->execute();
203 }
204
205 function addMetadataLinks( &$out ) {
206 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
207 global $wgRightsPage, $wgRightsUrl;
208
209 if( $out->isArticleRelated() ) {
210 # note: buggy CC software only reads first "meta" link
211 if( $wgEnableCreativeCommonsRdf ) {
212 $out->addMetadataLink( array(
213 'title' => 'Creative Commons',
214 'type' => 'application/rdf+xml',
215 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
216 }
217 if( $wgEnableDublinCoreRdf ) {
218 $out->addMetadataLink( array(
219 'title' => 'Dublin Core',
220 'type' => 'application/rdf+xml',
221 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
222 }
223 }
224 $copyright = '';
225 if( $wgRightsPage ) {
226 $copy = Title::newFromText( $wgRightsPage );
227 if( $copy ) {
228 $copyright = $copy->getLocalURL();
229 }
230 }
231 if( !$copyright && $wgRightsUrl ) {
232 $copyright = $wgRightsUrl;
233 }
234 if( $copyright ) {
235 $out->addLink( array(
236 'rel' => 'copyright',
237 'href' => $copyright ) );
238 }
239 }
240
241 function outputPage( &$out ) {
242 global $wgDebugComments;
243
244 wfProfileIn( 'Skin::outputPage' );
245 $this->initPage( $out );
246
247 $out->out( $out->headElement() );
248
249 $out->out( "\n<body" );
250 $ops = $this->getBodyOptions();
251 foreach ( $ops as $name => $val ) {
252 $out->out( " $name='$val'" );
253 }
254 $out->out( ">\n" );
255 if ( $wgDebugComments ) {
256 $out->out( "<!-- Wiki debugging output:\n" .
257 $out->mDebugtext . "-->\n" );
258 }
259
260 $out->out( $this->beforeContent() );
261
262 $out->out( $out->mBodytext . "\n" );
263
264 $out->out( $this->afterContent() );
265
266 $out->out( $this->bottomScripts() );
267
268 $out->out( $out->reportTime() );
269
270 $out->out( "\n</body></html>" );
271 }
272
273 static function makeGlobalVariablesScript( $data ) {
274 $r = '<script type= "' . $data['jsmimetype'] . '">
275 var skin = "' . Xml::escapeJsString( $data['skinname'] ) . '";
276 var stylepath = "' . Xml::escapeJsString( $data['stylepath'] ) . '";
277
278 var wgArticlePath = "' . Xml::escapeJsString( $data['articlepath'] ) . '";
279 var wgScriptPath = "' . Xml::escapeJsString( $data['scriptpath'] ) . '";
280 var wgServer = "' . Xml::escapeJsString( $data['serverurl'] ) . '";
281
282 var wgCanonicalNamespace = "' . Xml::escapeJsString( $data['nscanonical'] ) . '";
283 var wgNamespaceNumber = ' . (int)$data['nsnumber'] . ';
284 var wgPageName = "' . Xml::escapeJsString( $data['titleprefixeddbkey'] ) . '";
285 var wgTitle = "' . Xml::escapeJsString( $data['titletext'] ) . '";
286 var wgArticleId = ' . (int)$data['articleid'] . ';
287 var wgIsArticle = ' . ( $data['isarticle'] ? 'true' : 'false' ) . ';
288
289 var wgUserName = ' . ( $data['username'] == NULL ? 'null' : ( '"' . Xml::escapeJsString( $data['username'] ) . '"' ) ) . ';
290 var wgUserLanguage = "' . Xml::escapeJsString( $data['userlang'] ) . '";
291 var wgContentLanguage = "' . Xml::escapeJsString( $data['lang'] ) . '";
292 </script>
293 ';
294
295 return $r;
296 }
297
298 function getHeadScripts() {
299 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType, $wgStyleVersion;
300 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
301 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut;
302
303 $nsname = @$wgCanonicalNamespaceNames[ $wgTitle->getNamespace() ];
304 if ( $nsname === NULL ) $nsname = $wgTitle->getNsText();
305
306 $vars = array(
307 'jsmimetype' => $wgJsMimeType,
308 'skinname' => $this->getSkinName(),
309 'stylepath' => $wgStylePath,
310 'articlepath' => $wgArticlePath,
311 'scriptpath' => $wgScriptPath,
312 'serverurl' => $wgServer,
313 'nscanonical' => $nsname,
314 'nsnumber' => $wgTitle->getNamespace(),
315 'titleprefixeddbkey' => $wgTitle->getPrefixedDBKey(),
316 'titletext' => $wgTitle->getText(),
317 'articleid' => $wgTitle->getArticleId(),
318 'isarticle' => $wgOut->isArticle(),
319 'username' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
320 'userlang' => $wgLang->getCode(),
321 'lang' => $wgContLang->getCode(),
322 );
323
324 $r = self::makeGlobalVariablesScript( $vars );
325
326 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n";
327 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
328 $userpage = $wgUser->getUserPage();
329 $userjs = htmlspecialchars( self::makeUrl(
330 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
331 'action=raw&ctype='.$wgJsMimeType));
332 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
333 }
334 return $r;
335 }
336
337 /**
338 * To make it harder for someone to slip a user a fake
339 * user-JavaScript or user-CSS preview, a random token
340 * is associated with the login session. If it's not
341 * passed back with the preview request, we won't render
342 * the code.
343 *
344 * @param string $action
345 * @return bool
346 * @private
347 */
348 function userCanPreview( $action ) {
349 global $wgTitle, $wgRequest, $wgUser;
350
351 if( $action != 'submit' )
352 return false;
353 if( !$wgRequest->wasPosted() )
354 return false;
355 if( !$wgTitle->userCanEditCssJsSubpage() )
356 return false;
357 return $wgUser->matchEditToken(
358 $wgRequest->getVal( 'wpEditToken' ) );
359 }
360
361 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
362 function getUserStylesheet() {
363 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
364 $sheet = $this->getStylesheet();
365 $action = $wgRequest->getText('action');
366 $s = "@import \"$wgStylePath/common/common.css?$wgStyleVersion\";\n";
367 $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
368 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
369
370 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
371 $s .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
372 '@import "' . self::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
373
374 $s .= $this->doGetUserStyles();
375 return $s."\n";
376 }
377
378 /**
379 * placeholder, returns generated js in monobook
380 */
381 function getUserJs() { return; }
382
383 /**
384 * Return html code that include User stylesheets
385 */
386 function getUserStyles() {
387 $s = "<style type='text/css'>\n";
388 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
389 $s .= $this->getUserStylesheet();
390 $s .= "/*]]>*/ /* */\n";
391 $s .= "</style>\n";
392 return $s;
393 }
394
395 /**
396 * Some styles that are set by user through the user settings interface.
397 */
398 function doGetUserStyles() {
399 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
400
401 $s = '';
402
403 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
404 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
405 $s .= $wgRequest->getText('wpTextbox1');
406 } else {
407 $userpage = $wgUser->getUserPage();
408 $s.= '@import "'.self::makeUrl(
409 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
410 'action=raw&ctype=text/css').'";'."\n";
411 }
412 }
413
414 return $s . $this->reallyDoGetUserStyles();
415 }
416
417 function reallyDoGetUserStyles() {
418 global $wgUser;
419 $s = '';
420 if (($undopt = $wgUser->getOption("underline")) != 2) {
421 $underline = $undopt ? 'underline' : 'none';
422 $s .= "a { text-decoration: $underline; }\n";
423 }
424 if( $wgUser->getOption( 'highlightbroken' ) ) {
425 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
426 } else {
427 $s .= <<<END
428 a.new, #quickbar a.new,
429 a.stub, #quickbar a.stub {
430 color: inherit;
431 text-decoration: inherit;
432 }
433 a.new:after, #quickbar a.new:after {
434 content: "?";
435 color: #CC2200;
436 text-decoration: $underline;
437 }
438 a.stub:after, #quickbar a.stub:after {
439 content: "!";
440 color: #772233;
441 text-decoration: $underline;
442 }
443 END;
444 }
445 if( $wgUser->getOption( 'justify' ) ) {
446 $s .= "#article, #bodyContent { text-align: justify; }\n";
447 }
448 if( !$wgUser->getOption( 'showtoc' ) ) {
449 $s .= "#toc { display: none; }\n";
450 }
451 if( !$wgUser->getOption( 'editsection' ) ) {
452 $s .= ".editsection { display: none; }\n";
453 }
454 return $s;
455 }
456
457 function getBodyOptions() {
458 global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
459
460 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
461
462 if ( 0 != $wgTitle->getNamespace() ) {
463 $a = array( 'bgcolor' => '#ffffec' );
464 }
465 else $a = array( 'bgcolor' => '#FFFFFF' );
466 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
467 $wgTitle->userCanEdit() ) {
468 $t = wfMsg( 'editthispage' );
469 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
470 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
471 $a += array ('ondblclick' => $s);
472
473 }
474 $a['onload'] = $wgOut->getOnloadHandler();
475 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
476 if( $a['onload'] != '' ) {
477 $a['onload'] .= ';';
478 }
479 $a['onload'] .= 'setupRightClickEdit()';
480 }
481 $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr").
482 ' '.Sanitizer::escapeId( 'page-'.$wgTitle->getPrefixedText() );
483 return $a;
484 }
485
486 /**
487 * URL to the logo
488 */
489 function getLogo() {
490 global $wgLogo;
491 return $wgLogo;
492 }
493
494 /**
495 * This will be called immediately after the <body> tag. Split into
496 * two functions to make it easier to subclass.
497 */
498 function beforeContent() {
499 return $this->doBeforeContent();
500 }
501
502 function doBeforeContent() {
503 global $wgContLang;
504 $fname = 'Skin::doBeforeContent';
505 wfProfileIn( $fname );
506
507 $s = '';
508 $qb = $this->qbSetting();
509
510 if( $langlinks = $this->otherLanguages() ) {
511 $rows = 2;
512 $borderhack = '';
513 } else {
514 $rows = 1;
515 $langlinks = false;
516 $borderhack = 'class="top"';
517 }
518
519 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
520 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
521
522 $shove = ($qb != 0);
523 $left = ($qb == 1 || $qb == 3);
524 if($wgContLang->isRTL()) $left = !$left;
525
526 if ( !$shove ) {
527 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
528 $this->logoText() . '</td>';
529 } elseif( $left ) {
530 $s .= $this->getQuickbarCompensator( $rows );
531 }
532 $l = $wgContLang->isRTL() ? 'right' : 'left';
533 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
534
535 $s .= $this->topLinks() ;
536 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
537
538 $r = $wgContLang->isRTL() ? "left" : "right";
539 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
540 $s .= $this->nameAndLogin();
541 $s .= "\n<br />" . $this->searchForm() . "</td>";
542
543 if ( $langlinks ) {
544 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
545 }
546
547 if ( $shove && !$left ) { # Right
548 $s .= $this->getQuickbarCompensator( $rows );
549 }
550 $s .= "</tr>\n</table>\n</div>\n";
551 $s .= "\n<div id='article'>\n";
552
553 $notice = wfGetSiteNotice();
554 if( $notice ) {
555 $s .= "\n<div id='siteNotice'>$notice</div>\n";
556 }
557 $s .= $this->pageTitle();
558 $s .= $this->pageSubtitle() ;
559 $s .= $this->getCategories();
560 wfProfileOut( $fname );
561 return $s;
562 }
563
564
565 function getCategoryLinks () {
566 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
567 global $wgContLang;
568
569 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
570
571 # Separator
572 $sep = wfMsgHtml( 'catseparator' );
573
574 // Use Unicode bidi embedding override characters,
575 // to make sure links don't smash each other up in ugly ways.
576 $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
577 $embed = "<span dir='$dir'>";
578 $pop = '</span>';
579 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks ) . $pop;
580
581 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks ) );
582 $s = $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Categories' ),
583 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
584 . ': ' . $t;
585
586 # optional 'dmoz-like' category browser. Will be shown under the list
587 # of categories an article belong to
588 if($wgUseCategoryBrowser) {
589 $s .= '<br /><hr />';
590
591 # get a big array of the parents tree
592 $parenttree = $wgTitle->getParentCategoryTree();
593 # Skin object passed by reference cause it can not be
594 # accessed under the method subfunction drawCategoryBrowser
595 $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
596 # Clean out bogus first entry and sort them
597 unset($tempout[0]);
598 asort($tempout);
599 # Output one per line
600 $s .= implode("<br />\n", $tempout);
601 }
602
603 return $s;
604 }
605
606 /** Render the array as a serie of links.
607 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
608 * @param &skin Object: skin passed by reference
609 * @return String separated by &gt;, terminate with "\n"
610 */
611 function drawCategoryBrowser($tree, &$skin) {
612 $return = '';
613 foreach ($tree as $element => $parent) {
614 if (empty($parent)) {
615 # element start a new list
616 $return .= "\n";
617 } else {
618 # grab the others elements
619 $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
620 }
621 # add our current element to the list
622 $eltitle = Title::NewFromText($element);
623 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
624 }
625 return $return;
626 }
627
628 function getCategories() {
629 $catlinks=$this->getCategoryLinks();
630 if(!empty($catlinks)) {
631 return "<p class='catlinks'>{$catlinks}</p>";
632 }
633 }
634
635 function getQuickbarCompensator( $rows = 1 ) {
636 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
637 }
638
639 /**
640 * This gets called shortly before the \</body\> tag.
641 * @return String HTML to be put before \</body\>
642 */
643 function afterContent() {
644 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
645 return $printfooter . $this->doAfterContent();
646 }
647
648 /**
649 * This gets called shortly before the \</body\> tag.
650 * @return String HTML-wrapped JS code to be put before \</body\>
651 */
652 function bottomScripts() {
653 global $wgJsMimeType;
654 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
655 }
656
657 /** @return string Retrievied from HTML text */
658 function printSource() {
659 global $wgTitle;
660 $url = htmlspecialchars( $wgTitle->getFullURL() );
661 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
662 }
663
664 function printFooter() {
665 return "<p>" . $this->printSource() .
666 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
667 }
668
669 /** overloaded by derived classes */
670 function doAfterContent() { }
671
672 function pageTitleLinks() {
673 global $wgOut, $wgTitle, $wgUser, $wgRequest;
674
675 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
676 $action = $wgRequest->getText( 'action' );
677
678 $s = $this->printableLink();
679 $disclaimer = $this->disclaimerLink(); # may be empty
680 if( $disclaimer ) {
681 $s .= ' | ' . $disclaimer;
682 }
683 $privacy = $this->privacyLink(); # may be empty too
684 if( $privacy ) {
685 $s .= ' | ' . $privacy;
686 }
687
688 if ( $wgOut->isArticleRelated() ) {
689 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
690 $name = $wgTitle->getDBkey();
691 $image = new Image( $wgTitle );
692 if( $image->exists() ) {
693 $link = htmlspecialchars( $image->getURL() );
694 $style = $this->getInternalLinkAttributes( $link, $name );
695 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
696 }
697 }
698 }
699 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
700 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
701 wfMsg( 'currentrev' ) );
702 }
703
704 if ( $wgUser->getNewtalk() ) {
705 # do not show "You have new messages" text when we are viewing our
706 # own talk page
707 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
708 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
709 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
710 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
711 # disable caching
712 $wgOut->setSquidMaxage(0);
713 $wgOut->enableClientCache(false);
714 }
715 }
716
717 $undelete = $this->getUndeleteLink();
718 if( !empty( $undelete ) ) {
719 $s .= ' | '.$undelete;
720 }
721 return $s;
722 }
723
724 function getUndeleteLink() {
725 global $wgUser, $wgTitle, $wgContLang, $action;
726 if( $wgUser->isAllowed( 'deletedhistory' ) &&
727 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
728 ($n = $wgTitle->isDeleted() ) )
729 {
730 if ( $wgUser->isAllowed( 'delete' ) ) {
731 $msg = 'thisisdeleted';
732 } else {
733 $msg = 'viewdeleted';
734 }
735 return wfMsg( $msg,
736 $this->makeKnownLink(
737 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
738 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
739 }
740 return '';
741 }
742
743 function printableLink() {
744 global $wgOut, $wgFeedClasses, $wgRequest;
745
746 $baseurl = $_SERVER['REQUEST_URI'];
747 if( strpos( '?', $baseurl ) == false ) {
748 $baseurl .= '?';
749 } else {
750 $baseurl .= '&';
751 }
752 $baseurl = htmlspecialchars( $baseurl );
753 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
754
755 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
756 if( $wgOut->isSyndicated() ) {
757 foreach( $wgFeedClasses as $format => $class ) {
758 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
759 $s .= " | <a href=\"$feedurl\">{$format}</a>";
760 }
761 }
762 return $s;
763 }
764
765 function pageTitle() {
766 global $wgOut;
767 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
768 return $s;
769 }
770
771 function pageSubtitle() {
772 global $wgOut;
773
774 $sub = $wgOut->getSubtitle();
775 if ( '' == $sub ) {
776 global $wgExtraSubtitle;
777 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
778 }
779 $subpages = $this->subPageSubtitle();
780 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
781 $s = "<p class='subtitle'>{$sub}</p>\n";
782 return $s;
783 }
784
785 function subPageSubtitle() {
786 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
787 $subpages = '';
788 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
789 $ptext=$wgTitle->getPrefixedText();
790 if(preg_match('/\//',$ptext)) {
791 $links = explode('/',$ptext);
792 $c = 0;
793 $growinglink = '';
794 foreach($links as $link) {
795 $c++;
796 if ($c<count($links)) {
797 $growinglink .= $link;
798 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
799 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
800 if ($c>1) {
801 $subpages .= ' | ';
802 } else {
803 $subpages .= '&lt; ';
804 }
805 $subpages .= $getlink;
806 $growinglink .= '/';
807 }
808 }
809 }
810 }
811 return $subpages;
812 }
813
814 function nameAndLogin() {
815 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
816
817 $li = $wgContLang->specialPage( 'Userlogin' );
818 $lo = $wgContLang->specialPage( 'Userlogout' );
819
820 $s = '';
821 if ( $wgUser->isAnon() ) {
822 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
823 $n = wfGetIP();
824
825 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
826 $wgLang->getNsText( NS_TALK ) );
827
828 $s .= $n . ' ('.$tl.')';
829 } else {
830 $s .= wfMsg('notloggedin');
831 }
832
833 $rt = $wgTitle->getPrefixedURL();
834 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
835 $q = '';
836 } else { $q = "returnto={$rt}"; }
837
838 $s .= "\n<br />" . $this->makeKnownLinkObj(
839 SpecialPage::getTitleFor( 'Userlogin' ),
840 wfMsg( 'login' ), $q );
841 } else {
842 $n = $wgUser->getName();
843 $rt = $wgTitle->getPrefixedURL();
844 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
845 $wgLang->getNsText( NS_TALK ) );
846
847 $tl = " ({$tl})";
848
849 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
850 $n ) . "{$tl}<br />" .
851 $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
852 "returnto={$rt}" ) . ' | ' .
853 $this->specialLink( 'preferences' );
854 }
855 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
856 wfMsg( 'help' ) );
857
858 return $s;
859 }
860
861 function getSearchLink() {
862 $searchPage =& SpecialPage::getTitleFor( 'Search' );
863 return $searchPage->getLocalURL();
864 }
865
866 function escapeSearchLink() {
867 return htmlspecialchars( $this->getSearchLink() );
868 }
869
870 function searchForm() {
871 global $wgRequest;
872 $search = $wgRequest->getText( 'search' );
873
874 $s = '<form name="search" class="inline" method="post" action="'
875 . $this->escapeSearchLink() . "\">\n"
876 . '<input type="text" name="search" size="19" value="'
877 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
878 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
879 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
880
881 return $s;
882 }
883
884 function topLinks() {
885 global $wgOut;
886 $sep = " |\n";
887
888 $s = $this->mainPageLink() . $sep
889 . $this->specialLink( 'recentchanges' );
890
891 if ( $wgOut->isArticleRelated() ) {
892 $s .= $sep . $this->editThisPage()
893 . $sep . $this->historyLink();
894 }
895 # Many people don't like this dropdown box
896 #$s .= $sep . $this->specialPagesList();
897
898 $s .= $this->variantLinks();
899
900 return $s;
901 }
902
903 /**
904 * Language/charset variant links for classic-style skins
905 * @return string
906 */
907 function variantLinks() {
908 $s = '';
909 /* show links to different language variants */
910 global $wgDisableLangConversion, $wgContLang, $wgTitle;
911 $variants = $wgContLang->getVariants();
912 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
913 foreach( $variants as $code ) {
914 $varname = $wgContLang->getVariantname( $code );
915 if( $varname == 'disable' )
916 continue;
917 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
918 }
919 }
920 return $s;
921 }
922
923 function bottomLinks() {
924 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
925 $sep = " |\n";
926
927 $s = '';
928 if ( $wgOut->isArticleRelated() ) {
929 $s .= '<strong>' . $this->editThisPage() . '</strong>';
930 if ( $wgUser->isLoggedIn() ) {
931 $s .= $sep . $this->watchThisPage();
932 }
933 $s .= $sep . $this->talkLink()
934 . $sep . $this->historyLink()
935 . $sep . $this->whatLinksHere()
936 . $sep . $this->watchPageLinksLink();
937
938 if ($wgUseTrackbacks)
939 $s .= $sep . $this->trackbackLink();
940
941 if ( $wgTitle->getNamespace() == NS_USER
942 || $wgTitle->getNamespace() == NS_USER_TALK )
943
944 {
945 $id=User::idFromName($wgTitle->getText());
946 $ip=User::isIP($wgTitle->getText());
947
948 if($id || $ip) { # both anons and non-anons have contri list
949 $s .= $sep . $this->userContribsLink();
950 }
951 if( $this->showEmailUser( $id ) ) {
952 $s .= $sep . $this->emailUserLink();
953 }
954 }
955 if ( $wgTitle->getArticleId() ) {
956 $s .= "\n<br />";
957 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
958 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
959 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
960 }
961 $s .= "<br />\n" . $this->otherLanguages();
962 }
963 return $s;
964 }
965
966 function pageStats() {
967 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
968 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
969
970 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
971 if ( ! $wgOut->isArticle() ) { return ''; }
972 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
973 if ( 0 == $wgArticle->getID() ) { return ''; }
974
975 $s = '';
976 if ( !$wgDisableCounters ) {
977 $count = $wgLang->formatNum( $wgArticle->getCount() );
978 if ( $count ) {
979 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
980 }
981 }
982
983 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
984 require_once('Credits.php');
985 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
986 } else {
987 $s .= $this->lastModified();
988 }
989
990 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
991 $dbr =& wfGetDB( DB_SLAVE );
992 extract( $dbr->tableNames( 'watchlist' ) );
993 $sql = "SELECT COUNT(*) AS n FROM $watchlist
994 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
995 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
996 $res = $dbr->query( $sql, 'Skin::pageStats');
997 $x = $dbr->fetchObject( $res );
998 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
999 }
1000
1001 return $s . ' ' . $this->getCopyright();
1002 }
1003
1004 function getCopyright( $type = 'detect' ) {
1005 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1006
1007 if ( $type == 'detect' ) {
1008 $oldid = $wgRequest->getVal( 'oldid' );
1009 $diff = $wgRequest->getVal( 'diff' );
1010
1011 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1012 $type = 'history';
1013 } else {
1014 $type = 'normal';
1015 }
1016 }
1017
1018 if ( $type == 'history' ) {
1019 $msg = 'history_copyright';
1020 } else {
1021 $msg = 'copyright';
1022 }
1023
1024 $out = '';
1025 if( $wgRightsPage ) {
1026 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1027 } elseif( $wgRightsUrl ) {
1028 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1029 } else {
1030 # Give up now
1031 return $out;
1032 }
1033 $out .= wfMsgForContent( $msg, $link );
1034 return $out;
1035 }
1036
1037 function getCopyrightIcon() {
1038 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1039 $out = '';
1040 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1041 $out = $wgCopyrightIcon;
1042 } else if ( $wgRightsIcon ) {
1043 $icon = htmlspecialchars( $wgRightsIcon );
1044 if ( $wgRightsUrl ) {
1045 $url = htmlspecialchars( $wgRightsUrl );
1046 $out .= '<a href="'.$url.'">';
1047 }
1048 $text = htmlspecialchars( $wgRightsText );
1049 $out .= "<img src=\"$icon\" alt='$text' />";
1050 if ( $wgRightsUrl ) {
1051 $out .= '</a>';
1052 }
1053 }
1054 return $out;
1055 }
1056
1057 function getPoweredBy() {
1058 global $wgStylePath;
1059 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1060 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
1061 return $img;
1062 }
1063
1064 function lastModified() {
1065 global $wgLang, $wgArticle, $wgLoadBalancer;
1066
1067 $timestamp = $wgArticle->getTimestamp();
1068 if ( $timestamp ) {
1069 $d = $wgLang->date( $timestamp, true );
1070 $t = $wgLang->time( $timestamp, true );
1071 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1072 } else {
1073 $s = '';
1074 }
1075 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1076 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1077 }
1078 return $s;
1079 }
1080
1081 function logoText( $align = '' ) {
1082 if ( '' != $align ) { $a = " align='{$align}'"; }
1083 else { $a = ''; }
1084
1085 $mp = wfMsg( 'mainpage' );
1086 $titleObj = Title::newFromText( $mp );
1087 if ( is_object( $titleObj ) ) {
1088 $url = $titleObj->escapeLocalURL();
1089 } else {
1090 $url = '';
1091 }
1092
1093 $logourl = $this->getLogo();
1094 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1095 return $s;
1096 }
1097
1098 /**
1099 * show a drop-down box of special pages
1100 */
1101 function specialPagesList() {
1102 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1103 $a = array();
1104 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1105 foreach ( $pages as $name => $page ) {
1106 $pages[$name] = $page->getDescription();
1107 }
1108
1109 $go = wfMsg( 'go' );
1110 $sp = wfMsg( 'specialpages' );
1111 $spp = $wgContLang->specialPage( 'Specialpages' );
1112
1113 $s = '<form id="specialpages" method="get" class="inline" ' .
1114 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1115 $s .= "<select name=\"wpDropdown\">\n";
1116 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1117
1118
1119 foreach ( $pages as $name => $desc ) {
1120 $p = $wgContLang->specialPage( $name );
1121 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1122 }
1123 $s .= "</select>\n";
1124 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1125 $s .= "</form>\n";
1126 return $s;
1127 }
1128
1129 function mainPageLink() {
1130 $mp = wfMsgForContent( 'mainpage' );
1131 $mptxt = wfMsg( 'mainpage');
1132 $s = $this->makeKnownLink( $mp, $mptxt );
1133 return $s;
1134 }
1135
1136 function copyrightLink() {
1137 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1138 wfMsg( 'copyrightpagename' ) );
1139 return $s;
1140 }
1141
1142 function privacyLink() {
1143 $privacy = wfMsg( 'privacy' );
1144 if ($privacy == '-') {
1145 return '';
1146 } else {
1147 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1148 }
1149 }
1150
1151 function aboutLink() {
1152 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1153 wfMsg( 'aboutsite' ) );
1154 return $s;
1155 }
1156
1157 function disclaimerLink() {
1158 $disclaimers = wfMsg( 'disclaimers' );
1159 if ($disclaimers == '-') {
1160 return '';
1161 } else {
1162 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1163 $disclaimers );
1164 }
1165 }
1166
1167 function editThisPage() {
1168 global $wgOut, $wgTitle;
1169
1170 if ( ! $wgOut->isArticleRelated() ) {
1171 $s = wfMsg( 'protectedpage' );
1172 } else {
1173 if ( $wgTitle->userCanEdit() ) {
1174 $t = wfMsg( 'editthispage' );
1175 } else {
1176 $t = wfMsg( 'viewsource' );
1177 }
1178
1179 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1180 }
1181 return $s;
1182 }
1183
1184 /**
1185 * Return URL options for the 'edit page' link.
1186 * This may include an 'oldid' specifier, if the current page view is such.
1187 *
1188 * @return string
1189 * @private
1190 */
1191 function editUrlOptions() {
1192 global $wgArticle;
1193
1194 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1195 return "action=edit&oldid=" . intval( $this->mRevisionId );
1196 } else {
1197 return "action=edit";
1198 }
1199 }
1200
1201 function deleteThisPage() {
1202 global $wgUser, $wgTitle, $wgRequest;
1203
1204 $diff = $wgRequest->getVal( 'diff' );
1205 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1206 $t = wfMsg( 'deletethispage' );
1207
1208 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1209 } else {
1210 $s = '';
1211 }
1212 return $s;
1213 }
1214
1215 function protectThisPage() {
1216 global $wgUser, $wgTitle, $wgRequest;
1217
1218 $diff = $wgRequest->getVal( 'diff' );
1219 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1220 if ( $wgTitle->isProtected() ) {
1221 $t = wfMsg( 'unprotectthispage' );
1222 $q = 'action=unprotect';
1223 } else {
1224 $t = wfMsg( 'protectthispage' );
1225 $q = 'action=protect';
1226 }
1227 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1228 } else {
1229 $s = '';
1230 }
1231 return $s;
1232 }
1233
1234 function watchThisPage() {
1235 global $wgOut, $wgTitle;
1236
1237 if ( $wgOut->isArticleRelated() ) {
1238 if ( $wgTitle->userIsWatching() ) {
1239 $t = wfMsg( 'unwatchthispage' );
1240 $q = 'action=unwatch';
1241 } else {
1242 $t = wfMsg( 'watchthispage' );
1243 $q = 'action=watch';
1244 }
1245 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1246 } else {
1247 $s = wfMsg( 'notanarticle' );
1248 }
1249 return $s;
1250 }
1251
1252 function moveThisPage() {
1253 global $wgTitle;
1254
1255 if ( $wgTitle->userCanMove() ) {
1256 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1257 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1258 } else {
1259 // no message if page is protected - would be redundant
1260 return '';
1261 }
1262 }
1263
1264 function historyLink() {
1265 global $wgTitle;
1266
1267 return $this->makeKnownLinkObj( $wgTitle,
1268 wfMsg( 'history' ), 'action=history' );
1269 }
1270
1271 function whatLinksHere() {
1272 global $wgTitle;
1273
1274 return $this->makeKnownLinkObj(
1275 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1276 wfMsg( 'whatlinkshere' ) );
1277 }
1278
1279 function userContribsLink() {
1280 global $wgTitle;
1281
1282 return $this->makeKnownLinkObj(
1283 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1284 wfMsg( 'contributions' ) );
1285 }
1286
1287 function showEmailUser( $id ) {
1288 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1289 return $wgEnableEmail &&
1290 $wgEnableUserEmail &&
1291 $wgUser->isLoggedIn() && # show only to signed in users
1292 0 != $id; # we can only email to non-anons ..
1293 # '' != $id->getEmail() && # who must have an email address stored ..
1294 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1295 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1296 }
1297
1298 function emailUserLink() {
1299 global $wgTitle;
1300
1301 return $this->makeKnownLinkObj(
1302 SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1303 wfMsg( 'emailuser' ) );
1304 }
1305
1306 function watchPageLinksLink() {
1307 global $wgOut, $wgTitle;
1308
1309 if ( ! $wgOut->isArticleRelated() ) {
1310 return '(' . wfMsg( 'notanarticle' ) . ')';
1311 } else {
1312 return $this->makeKnownLinkObj(
1313 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1314 wfMsg( 'recentchangeslinked' ) );
1315 }
1316 }
1317
1318 function trackbackLink() {
1319 global $wgTitle;
1320
1321 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1322 . wfMsg('trackbacklink') . "</a>";
1323 }
1324
1325 function otherLanguages() {
1326 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1327
1328 if ( $wgHideInterlanguageLinks ) {
1329 return '';
1330 }
1331
1332 $a = $wgOut->getLanguageLinks();
1333 if ( 0 == count( $a ) ) {
1334 return '';
1335 }
1336
1337 $s = wfMsg( 'otherlanguages' ) . ': ';
1338 $first = true;
1339 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1340 foreach( $a as $l ) {
1341 if ( ! $first ) { $s .= ' | '; }
1342 $first = false;
1343
1344 $nt = Title::newFromText( $l );
1345 $url = $nt->escapeFullURL();
1346 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1347
1348 if ( '' == $text ) { $text = $l; }
1349 $style = $this->getExternalLinkAttributes( $l, $text );
1350 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1351 }
1352 if($wgContLang->isRTL()) $s .= '</span>';
1353 return $s;
1354 }
1355
1356 function bugReportsLink() {
1357 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1358 wfMsg( 'bugreports' ) );
1359 return $s;
1360 }
1361
1362 function dateLink() {
1363 $t1 = Title::newFromText( gmdate( 'F j' ) );
1364 $t2 = Title::newFromText( gmdate( 'Y' ) );
1365
1366 $id = $t1->getArticleID();
1367
1368 if ( 0 == $id ) {
1369 $s = $this->makeBrokenLink( $t1->getText() );
1370 } else {
1371 $s = $this->makeKnownLink( $t1->getText() );
1372 }
1373 $s .= ', ';
1374
1375 $id = $t2->getArticleID();
1376
1377 if ( 0 == $id ) {
1378 $s .= $this->makeBrokenLink( $t2->getText() );
1379 } else {
1380 $s .= $this->makeKnownLink( $t2->getText() );
1381 }
1382 return $s;
1383 }
1384
1385 function talkLink() {
1386 global $wgTitle;
1387
1388 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1389 # No discussion links for special pages
1390 return '';
1391 }
1392
1393 if( $wgTitle->isTalkPage() ) {
1394 $link = $wgTitle->getSubjectPage();
1395 switch( $link->getNamespace() ) {
1396 case NS_MAIN:
1397 $text = wfMsg( 'articlepage' );
1398 break;
1399 case NS_USER:
1400 $text = wfMsg( 'userpage' );
1401 break;
1402 case NS_PROJECT:
1403 $text = wfMsg( 'projectpage' );
1404 break;
1405 case NS_IMAGE:
1406 $text = wfMsg( 'imagepage' );
1407 break;
1408 case NS_MEDIAWIKI:
1409 $text = wfMsg( 'mediawikipage' );
1410 break;
1411 case NS_TEMPLATE:
1412 $text = wfMsg( 'templatepage' );
1413 break;
1414 case NS_HELP:
1415 $text = wfMsg( 'viewhelppage' );
1416 break;
1417 case NS_CATEGORY:
1418 $text = wfMsg( 'categorypage' );
1419 break;
1420 default:
1421 $text = wfMsg( 'articlepage' );
1422 }
1423 } else {
1424 $link = $wgTitle->getTalkPage();
1425 $text = wfMsg( 'talkpage' );
1426 }
1427
1428 $s = $this->makeLinkObj( $link, $text );
1429
1430 return $s;
1431 }
1432
1433 function commentLink() {
1434 global $wgTitle, $wgOut;
1435
1436 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1437 return '';
1438 }
1439
1440 # __NEWSECTIONLINK___ changes behaviour here
1441 # If it's present, the link points to this page, otherwise
1442 # it points to the talk page
1443 if( $wgTitle->isTalkPage() ) {
1444 $title =& $wgTitle;
1445 } elseif( $wgOut->showNewSectionLink() ) {
1446 $title =& $wgTitle;
1447 } else {
1448 $title =& $wgTitle->getTalkPage();
1449 }
1450
1451 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1452 }
1453
1454 /* these are used extensively in SkinTemplate, but also some other places */
1455 static function makeSpecialUrl( $name, $urlaction = '' ) {
1456 $title = SpecialPage::getTitleFor( $name );
1457 return $title->getLocalURL( $urlaction );
1458 }
1459
1460 static function makeI18nUrl( $name, $urlaction = '' ) {
1461 $title = Title::newFromText( wfMsgForContent( $name ) );
1462 self::checkTitle( $title, $name );
1463 return $title->getLocalURL( $urlaction );
1464 }
1465
1466 static function makeUrl( $name, $urlaction = '' ) {
1467 $title = Title::newFromText( $name );
1468 self::checkTitle( $title, $name );
1469 return $title->getLocalURL( $urlaction );
1470 }
1471
1472 # If url string starts with http, consider as external URL, else
1473 # internal
1474 static function makeInternalOrExternalUrl( $name ) {
1475 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1476 return $name;
1477 } else {
1478 return self::makeUrl( $name );
1479 }
1480 }
1481
1482 # this can be passed the NS number as defined in Language.php
1483 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1484 $title = Title::makeTitleSafe( $namespace, $name );
1485 self::checkTitle( $title, $name );
1486 return $title->getLocalURL( $urlaction );
1487 }
1488
1489 /* these return an array with the 'href' and boolean 'exists' */
1490 static function makeUrlDetails( $name, $urlaction = '' ) {
1491 $title = Title::newFromText( $name );
1492 self::checkTitle( $title, $name );
1493 return array(
1494 'href' => $title->getLocalURL( $urlaction ),
1495 'exists' => $title->getArticleID() != 0 ? true : false
1496 );
1497 }
1498
1499 /**
1500 * Make URL details where the article exists (or at least it's convenient to think so)
1501 */
1502 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1503 $title = Title::newFromText( $name );
1504 self::checkTitle( $title, $name );
1505 return array(
1506 'href' => $title->getLocalURL( $urlaction ),
1507 'exists' => true
1508 );
1509 }
1510
1511 # make sure we have some title to operate on
1512 static function checkTitle( &$title, &$name ) {
1513 if( !is_object( $title ) ) {
1514 $title = Title::newFromText( $name );
1515 if( !is_object( $title ) ) {
1516 $title = Title::newFromText( '--error: link target missing--' );
1517 }
1518 }
1519 }
1520
1521 /**
1522 * Build an array that represents the sidebar(s), the navigation bar among them
1523 *
1524 * @return array
1525 * @private
1526 */
1527 function buildSidebar() {
1528 global $parserMemc, $wgEnableSidebarCache;
1529 global $wgLang, $wgContLang;
1530
1531 $fname = 'SkinTemplate::buildSidebar';
1532
1533 wfProfileIn( $fname );
1534
1535 $key = wfMemcKey( 'sidebar' );
1536 $cacheSidebar = $wgEnableSidebarCache &&
1537 ($wgLang->getCode() == $wgContLang->getCode());
1538
1539 if ($cacheSidebar) {
1540 $cachedsidebar = $parserMemc->get( $key );
1541 if ($cachedsidebar!="") {
1542 wfProfileOut($fname);
1543 return $cachedsidebar;
1544 }
1545 }
1546
1547 $bar = array();
1548 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1549 foreach ($lines as $line) {
1550 if (strpos($line, '*') !== 0)
1551 continue;
1552 if (strpos($line, '**') !== 0) {
1553 $line = trim($line, '* ');
1554 $heading = $line;
1555 } else {
1556 if (strpos($line, '|') !== false) { // sanity check
1557 $line = explode( '|' , trim($line, '* '), 2 );
1558 $link = wfMsgForContent( $line[0] );
1559 if ($link == '-')
1560 continue;
1561 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1562 $text = $line[1];
1563 if (wfEmptyMsg($line[0], $link))
1564 $link = $line[0];
1565
1566 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1567 $href = $link;
1568 } else {
1569 $title = Title::newFromText( $link );
1570 $title = $title->fixSpecialName();
1571 $href = $title->getLocalURL();
1572 }
1573
1574 $bar[$heading][] = array(
1575 'text' => $text,
1576 'href' => $href,
1577 'id' => 'n-' . strtr($line[1], ' ', '-'),
1578 'active' => false
1579 );
1580 } else { continue; }
1581 }
1582 }
1583 if ($cacheSidebar)
1584 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1585 wfProfileOut( $fname );
1586 return $bar;
1587 }
1588 }
1589 ?>