PHPDocumentor [http://en.wikipedia.org/wiki/PhpDocumentor] documentation tweaking...
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 /**
21 * Template-filler skin base class
22 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
23 * Based on Brion's smarty skin
24 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
25 *
26 * Todo: Needs some serious refactoring into functions that correspond
27 * to the computations individual esi snippets need. Most importantly no body
28 * parsing for most of those of course.
29 *
30 * @addtogroup Skins
31 */
32
33 /**
34 * Wrapper object for MediaWiki's localization functions,
35 * to be passed to the template engine.
36 *
37 * @private
38 */
39 class MediaWiki_I18N {
40 var $_context = array();
41
42 function set($varName, $value) {
43 $this->_context[$varName] = $value;
44 }
45
46 function translate($value) {
47 $fname = 'SkinTemplate-translate';
48 wfProfileIn( $fname );
49
50 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
51 $value = preg_replace( '/^string:/', '', $value );
52
53 $value = wfMsg( $value );
54 // interpolate variables
55 $m = array();
56 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
57 list($src, $var) = $m;
58 wfSuppressWarnings();
59 $varValue = $this->_context[$var];
60 wfRestoreWarnings();
61 $value = str_replace($src, $varValue, $value);
62 }
63 wfProfileOut( $fname );
64 return $value;
65 }
66 }
67
68 /**
69 * @todo document with one-sentence top-level class description.
70 */
71 class SkinTemplate extends Skin {
72 /**#@+
73 * @private
74 */
75
76 /**
77 * Name of our skin, set in initPage()
78 * It probably need to be all lower case.
79 */
80 var $skinname;
81
82 /**
83 * Stylesheets set to use
84 * Sub directory in ./skins/ where various stylesheets are located
85 */
86 var $stylename;
87
88 /**
89 * For QuickTemplate, the name of the subclass which
90 * will actually fill the template.
91 */
92 var $template;
93
94 /**#@-*/
95
96 /**
97 * Setup the base parameters...
98 * Child classes should override this to set the name,
99 * style subdirectory, and template filler callback.
100 *
101 * @param OutputPage $out
102 */
103 function initPage( &$out ) {
104 parent::initPage( $out );
105 $this->skinname = 'monobook';
106 $this->stylename = 'monobook';
107 $this->template = 'QuickTemplate';
108 }
109
110 /**
111 * Create the template engine object; we feed it a bunch of data
112 * and eventually it spits out some HTML. Should have interface
113 * roughly equivalent to PHPTAL 0.7.
114 *
115 * @param string $callback (or file)
116 * @param string $repository subdirectory where we keep template files
117 * @param string $cache_dir
118 * @return object
119 * @private
120 */
121 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
122 return new $classname();
123 }
124
125 /**
126 * initialize various variables and generate the template
127 *
128 * @param OutputPage $out
129 * @public
130 */
131 function outputPage( &$out ) {
132 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
133 global $wgScript, $wgStylePath, $wgContLanguageCode;
134 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
135 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
136 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
137 global $wgMaxCredits, $wgShowCreditsIfMax;
138 global $wgPageShowWatchingUsers;
139 global $wgUseTrackbacks;
140 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
141
142 $fname = 'SkinTemplate::outputPage';
143 wfProfileIn( $fname );
144
145 // Hook that allows last minute changes to the output page, e.g.
146 // adding of CSS or Javascript by extensions.
147 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
148
149 $oldid = $wgRequest->getVal( 'oldid' );
150 $diff = $wgRequest->getVal( 'diff' );
151
152 wfProfileIn( "$fname-init" );
153 $this->initPage( $out );
154
155 $this->mTitle =& $wgTitle;
156 $this->mUser =& $wgUser;
157
158 $tpl = $this->setupTemplate( $this->template, 'skins' );
159
160 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
161 $tpl->setTranslator(new MediaWiki_I18N());
162 #}
163 wfProfileOut( "$fname-init" );
164
165 wfProfileIn( "$fname-stuff" );
166 $this->thispage = $this->mTitle->getPrefixedDbKey();
167 $this->thisurl = $this->mTitle->getPrefixedURL();
168 $this->loggedin = $wgUser->isLoggedIn();
169 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
170 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
171 $this->username = $wgUser->getName();
172 $userPage = $wgUser->getUserPage();
173 $this->userpage = $userPage->getPrefixedText();
174
175 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
176 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
177 } else {
178 # This won't be used in the standard skins, but we define it to preserve the interface
179 # To save time, we check for existence
180 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
181 }
182
183 $this->usercss = $this->userjs = $this->userjsprev = false;
184 $this->setupUserCss();
185 $this->setupUserJs();
186 $this->titletxt = $this->mTitle->getPrefixedText();
187 wfProfileOut( "$fname-stuff" );
188
189 wfProfileIn( "$fname-stuff2" );
190 $tpl->set( 'title', $wgOut->getPageTitle() );
191 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
192 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
193 $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$this->mTitle->getPrefixedText() ) );
194
195 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
196 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
197 $this->mTitle->getNsText();
198
199 $tpl->set( 'nscanonical', $nsname );
200 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
201 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
202 $tpl->set( 'titletext', $this->mTitle->getText() );
203 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
204 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
205
206 $tpl->set( 'isarticle', $wgOut->isArticle() );
207
208 $tpl->setRef( "thispage", $this->thispage );
209 $subpagestr = $this->subPageSubtitle();
210 $tpl->set(
211 'subtitle', !empty($subpagestr)?
212 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
213 $out->getSubtitle()
214 );
215 $undelete = $this->getUndeleteLink();
216 $tpl->set(
217 "undelete", !empty($undelete)?
218 '<span class="subpages">'.$undelete.'</span>':
219 ''
220 );
221
222 $tpl->set( 'catlinks', $this->getCategories());
223 if( $wgOut->isSyndicated() ) {
224 $feeds = array();
225 foreach( $wgFeedClasses as $format => $class ) {
226 $linktext = $format;
227 if ( $format == "atom" ) {
228 $linktext = wfMsg( 'feed-atom' );
229 } else if ( $format == "rss" ) {
230 $linktext = wfMsg( 'feed-rss' );
231 }
232 $feeds[$format] = array(
233 'text' => $linktext,
234 'href' => $wgRequest->appendQuery( "feed=$format" )
235 );
236 }
237 $tpl->setRef( 'feeds', $feeds );
238 } else {
239 $tpl->set( 'feeds', false );
240 }
241 if ($wgUseTrackbacks && $out->isArticleRelated()) {
242 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
243 } else {
244 $tpl->set( 'trackbackhtml', null );
245 }
246
247 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
248 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
249 $tpl->setRef( 'mimetype', $wgMimeType );
250 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
251 $tpl->setRef( 'charset', $wgOutputEncoding );
252 $tpl->set( 'headlinks', $out->getHeadLinks() );
253 $tpl->set('headscripts', $out->getScript() );
254 $tpl->setRef( 'wgScript', $wgScript );
255 $tpl->setRef( 'skinname', $this->skinname );
256 $tpl->set( 'skinclass', get_class( $this ) );
257 $tpl->setRef( 'stylename', $this->stylename );
258 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
259 $tpl->setRef( 'loggedin', $this->loggedin );
260 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
261 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
262 /* XXX currently unused, might get useful later
263 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
264 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
265 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
266 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
267 $tpl->set( "helppage", wfMsg('helppage'));
268 */
269 $tpl->set( 'searchaction', $this->escapeSearchLink() );
270 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
271 $tpl->setRef( 'stylepath', $wgStylePath );
272 $tpl->setRef( 'articlepath', $wgArticlePath );
273 $tpl->setRef( 'scriptpath', $wgScriptPath );
274 $tpl->setRef( 'serverurl', $wgServer );
275 $tpl->setRef( 'logopath', $wgLogo );
276 $tpl->setRef( "lang", $wgContLanguageCode );
277 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
278 $tpl->set( 'rtl', $wgContLang->isRTL() );
279 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
280 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
281 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
282 $tpl->setRef( 'userpage', $this->userpage);
283 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
284 $tpl->set( 'userlang', $wgLang->getCode() );
285 $tpl->set( 'pagecss', $this->setupPageCss() );
286 $tpl->setRef( 'usercss', $this->usercss);
287 $tpl->setRef( 'userjs', $this->userjs);
288 $tpl->setRef( 'userjsprev', $this->userjsprev);
289 global $wgUseSiteJs;
290 if ($wgUseSiteJs) {
291 if($this->loggedin) {
292 $tpl->set( 'jsvarurl', self::makeUrl('-','action=raw&smaxage=0&gen=js') );
293 } else {
294 $tpl->set( 'jsvarurl', self::makeUrl('-','action=raw&gen=js') );
295 }
296 } else {
297 $tpl->set('jsvarurl', false);
298 }
299 $newtalks = $wgUser->getNewMessageLinks();
300
301 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
302 $usertitle = $this->mUser->getUserPage();
303 $usertalktitle = $usertitle->getTalkPage();
304 if( !$usertalktitle->equals( $this->mTitle ) ) {
305 $ntl = wfMsg( 'youhavenewmessages',
306 $this->makeKnownLinkObj(
307 $usertalktitle,
308 wfMsgHtml( 'newmessageslink' ),
309 'redirect=no'
310 ),
311 $this->makeKnownLinkObj(
312 $usertalktitle,
313 wfMsgHtml( 'newmessagesdifflink' ),
314 'diff=cur'
315 )
316 );
317 # Disable Cache
318 $wgOut->setSquidMaxage(0);
319 }
320 } else if (count($newtalks)) {
321 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
322 $msgs = array();
323 foreach ($newtalks as $newtalk) {
324 $msgs[] = wfElement("a",
325 array('href' => $newtalk["link"]), $newtalk["wiki"]);
326 }
327 $parts = implode($sep, $msgs);
328 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
329 $wgOut->setSquidMaxage(0);
330 } else {
331 $ntl = '';
332 }
333 wfProfileOut( "$fname-stuff2" );
334
335 wfProfileIn( "$fname-stuff3" );
336 $tpl->setRef( 'newtalk', $ntl );
337 $tpl->setRef( 'skin', $this);
338 $tpl->set( 'logo', $this->logoText() );
339 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
340 $wgArticle and 0 != $wgArticle->getID() )
341 {
342 if ( !$wgDisableCounters ) {
343 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
344 if ( $viewcount ) {
345 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
346 } else {
347 $tpl->set('viewcount', false);
348 }
349 } else {
350 $tpl->set('viewcount', false);
351 }
352
353 if ($wgPageShowWatchingUsers) {
354 $dbr = wfGetDB( DB_SLAVE );
355 $watchlist = $dbr->tableName( 'watchlist' );
356 $sql = "SELECT COUNT(*) AS n FROM $watchlist
357 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
358 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
359 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
360 $x = $dbr->fetchObject( $res );
361 $numberofwatchingusers = $x->n;
362 if ($numberofwatchingusers > 0) {
363 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
364 } else {
365 $tpl->set('numberofwatchingusers', false);
366 }
367 } else {
368 $tpl->set('numberofwatchingusers', false);
369 }
370
371 $tpl->set('copyright',$this->getCopyright());
372
373 $this->credits = false;
374
375 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
376 require_once("Credits.php");
377 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
378 } else {
379 $tpl->set('lastmod', $this->lastModified());
380 }
381
382 $tpl->setRef( 'credits', $this->credits );
383
384 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
385 $tpl->set('copyright', $this->getCopyright());
386 $tpl->set('viewcount', false);
387 $tpl->set('lastmod', false);
388 $tpl->set('credits', false);
389 $tpl->set('numberofwatchingusers', false);
390 } else {
391 $tpl->set('copyright', false);
392 $tpl->set('viewcount', false);
393 $tpl->set('lastmod', false);
394 $tpl->set('credits', false);
395 $tpl->set('numberofwatchingusers', false);
396 }
397 wfProfileOut( "$fname-stuff3" );
398
399 wfProfileIn( "$fname-stuff4" );
400 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
401 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
402 $tpl->set( 'disclaimer', $this->disclaimerLink() );
403 $tpl->set( 'privacy', $this->privacyLink() );
404 $tpl->set( 'about', $this->aboutLink() );
405
406 $tpl->setRef( 'debug', $out->mDebugtext );
407 $tpl->set( 'reporttime', $out->reportTime() );
408 $tpl->set( 'sitenotice', wfGetSiteNotice() );
409 $tpl->set( 'bottomscripts', $this->bottomScripts() );
410
411 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
412 $out->mBodytext .= $printfooter ;
413 $tpl->setRef( 'bodytext', $out->mBodytext );
414
415 # Language links
416 $language_urls = array();
417
418 if ( !$wgHideInterlanguageLinks ) {
419 foreach( $wgOut->getLanguageLinks() as $l ) {
420 $tmp = explode( ':', $l, 2 );
421 $class = 'interwiki-' . $tmp[0];
422 unset($tmp);
423 $nt = Title::newFromText( $l );
424 $language_urls[] = array(
425 'href' => $nt->getFullURL(),
426 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
427 'class' => $class
428 );
429 }
430 }
431 if(count($language_urls)) {
432 $tpl->setRef( 'language_urls', $language_urls);
433 } else {
434 $tpl->set('language_urls', false);
435 }
436 wfProfileOut( "$fname-stuff4" );
437
438 # Personal toolbar
439 $tpl->set('personal_urls', $this->buildPersonalUrls());
440 $content_actions = $this->buildContentActionUrls();
441 $tpl->setRef('content_actions', $content_actions);
442
443 // XXX: attach this from javascript, same with section editing
444 if($this->iseditable && $wgUser->getOption("editondblclick") )
445 {
446 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
447 } else {
448 $tpl->set('body_ondblclick', false);
449 }
450 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
451 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
452 } else {
453 $tpl->set( 'body_onload', false );
454 }
455 $tpl->set( 'sidebar', $this->buildSidebar() );
456 $tpl->set( 'nav_urls', $this->buildNavUrls() );
457
458 // original version by hansm
459 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
460 wfDebug( __METHOD__ . ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
461 }
462
463 // execute template
464 wfProfileIn( "$fname-execute" );
465 $res = $tpl->execute();
466 wfProfileOut( "$fname-execute" );
467
468 // result may be an error
469 $this->printOrError( $res );
470 wfProfileOut( $fname );
471 }
472
473 /**
474 * Output the string, or print error message if it's
475 * an error object of the appropriate type.
476 * For the base class, assume strings all around.
477 *
478 * @param mixed $str
479 * @private
480 */
481 function printOrError( $str ) {
482 echo $str;
483 }
484
485 /**
486 * build array of urls for personal toolbar
487 * @return array
488 * @private
489 */
490 function buildPersonalUrls() {
491 global $wgTitle;
492
493 $fname = 'SkinTemplate::buildPersonalUrls';
494 $pageurl = $wgTitle->getLocalURL();
495 wfProfileIn( $fname );
496
497 /* set up the default links for the personal toolbar */
498 $personal_urls = array();
499 if ($this->loggedin) {
500 $personal_urls['userpage'] = array(
501 'text' => $this->username,
502 'href' => &$this->userpageUrlDetails['href'],
503 'class' => $this->userpageUrlDetails['exists']?false:'new',
504 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
505 );
506 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
507 $personal_urls['mytalk'] = array(
508 'text' => wfMsg('mytalk'),
509 'href' => &$usertalkUrlDetails['href'],
510 'class' => $usertalkUrlDetails['exists']?false:'new',
511 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
512 );
513 $href = self::makeSpecialUrl( 'Preferences' );
514 $personal_urls['preferences'] = array(
515 'text' => wfMsg( 'mypreferences' ),
516 'href' => self::makeSpecialUrl( 'Preferences' ),
517 'active' => ( $href == $pageurl )
518 );
519 $href = self::makeSpecialUrl( 'Watchlist' );
520 $personal_urls['watchlist'] = array(
521 'text' => wfMsg( 'watchlist' ),
522 'href' => $href,
523 'active' => ( $href == $pageurl )
524 );
525 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
526 $personal_urls['mycontris'] = array(
527 'text' => wfMsg( 'mycontris' ),
528 'href' => $href,
529 // FIXME # 'active' was disabled in r11346 with message: "disable bold link to my contributions; link was bold on all
530 // Special:Contributions, not just current user's (fix me please!)". Until resolved (bug 4764), explicitly setting active to false.
531 'active' => false # ( ( $href == $pageurl . '/' . $this->username )
532 );
533 $personal_urls['logout'] = array(
534 'text' => wfMsg( 'userlogout' ),
535 'href' => self::makeSpecialUrl( 'Userlogout',
536 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
537 ),
538 'active' => false
539 );
540 } else {
541 if( $this->showIPinHeader() ) {
542 $href = &$this->userpageUrlDetails['href'];
543 $personal_urls['anonuserpage'] = array(
544 'text' => $this->username,
545 'href' => $href,
546 'class' => $this->userpageUrlDetails['exists']?false:'new',
547 'active' => ( $pageurl == $href )
548 );
549 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
550 $href = &$usertalkUrlDetails['href'];
551 $personal_urls['anontalk'] = array(
552 'text' => wfMsg('anontalk'),
553 'href' => $href,
554 'class' => $usertalkUrlDetails['exists']?false:'new',
555 'active' => ( $pageurl == $href )
556 );
557 $personal_urls['anonlogin'] = array(
558 'text' => wfMsg('userlogin'),
559 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
560 'active' => $wgTitle->isSpecial( 'Userlogin' )
561 );
562 } else {
563
564 $personal_urls['login'] = array(
565 'text' => wfMsg('userlogin'),
566 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
567 'active' => $wgTitle->isSpecial( 'Userlogin' )
568 );
569 }
570 }
571
572 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
573 wfProfileOut( $fname );
574 return $personal_urls;
575 }
576
577 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
578 $classes = array();
579 if( $selected ) {
580 $classes[] = 'selected';
581 }
582 if( $checkEdit && $title->getArticleId() == 0 ) {
583 $classes[] = 'new';
584 $query = 'action=edit';
585 }
586
587 $text = wfMsg( $message );
588 if ( wfEmptyMsg( $message, $text ) ) {
589 global $wgContLang;
590 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
591 }
592
593 return array(
594 'class' => implode( ' ', $classes ),
595 'text' => $text,
596 'href' => $title->getLocalUrl( $query ) );
597 }
598
599 function makeTalkUrlDetails( $name, $urlaction = '' ) {
600 $title = Title::newFromText( $name );
601 if( !is_object($title) ) {
602 throw new MWException( __METHOD__." given invalid pagename $name" );
603 }
604 $title = $title->getTalkPage();
605 self::checkTitle( $title, $name );
606 return array(
607 'href' => $title->getLocalURL( $urlaction ),
608 'exists' => $title->getArticleID() != 0 ? true : false
609 );
610 }
611
612 function makeArticleUrlDetails( $name, $urlaction = '' ) {
613 $title = Title::newFromText( $name );
614 $title= $title->getSubjectPage();
615 self::checkTitle( $title, $name );
616 return array(
617 'href' => $title->getLocalURL( $urlaction ),
618 'exists' => $title->getArticleID() != 0 ? true : false
619 );
620 }
621
622 /**
623 * an array of edit links by default used for the tabs
624 * @return array
625 * @private
626 */
627 function buildContentActionUrls () {
628 global $wgContLang, $wgOut;
629 $fname = 'SkinTemplate::buildContentActionUrls';
630 wfProfileIn( $fname );
631
632 global $wgUser, $wgRequest;
633 $action = $wgRequest->getText( 'action' );
634 $section = $wgRequest->getText( 'section' );
635 $content_actions = array();
636
637 $prevent_active_tabs = false ;
638 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
639
640 if( $this->iscontent ) {
641 $subjpage = $this->mTitle->getSubjectPage();
642 $talkpage = $this->mTitle->getTalkPage();
643
644 $nskey = $this->mTitle->getNamespaceKey();
645 $content_actions[$nskey] = $this->tabAction(
646 $subjpage,
647 $nskey,
648 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
649 '', true);
650
651 $content_actions['talk'] = $this->tabAction(
652 $talkpage,
653 'talk',
654 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
655 '',
656 true);
657
658 wfProfileIn( "$fname-edit" );
659 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
660 $istalk = $this->mTitle->isTalkPage();
661 $istalkclass = $istalk?' istalk':'';
662 $content_actions['edit'] = array(
663 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
664 'text' => wfMsg('edit'),
665 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
666 );
667
668 if ( $istalk || $wgOut->showNewSectionLink() ) {
669 $content_actions['addsection'] = array(
670 'class' => $section == 'new'?'selected':false,
671 'text' => wfMsg('addsection'),
672 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
673 );
674 }
675 } else {
676 $content_actions['viewsource'] = array(
677 'class' => ($action == 'edit') ? 'selected' : false,
678 'text' => wfMsg('viewsource'),
679 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
680 );
681 }
682 wfProfileOut( "$fname-edit" );
683
684 wfProfileIn( "$fname-live" );
685 if ( $this->mTitle->getArticleId() ) {
686
687 $content_actions['history'] = array(
688 'class' => ($action == 'history') ? 'selected' : false,
689 'text' => wfMsg('history_short'),
690 'href' => $this->mTitle->getLocalUrl( 'action=history')
691 );
692
693 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
694 if(!$this->mTitle->isProtected()){
695 $content_actions['protect'] = array(
696 'class' => ($action == 'protect') ? 'selected' : false,
697 'text' => wfMsg('protect'),
698 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
699 );
700
701 } else {
702 $content_actions['unprotect'] = array(
703 'class' => ($action == 'unprotect') ? 'selected' : false,
704 'text' => wfMsg('unprotect'),
705 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
706 );
707 }
708 }
709 if($wgUser->isAllowed('delete')){
710 $content_actions['delete'] = array(
711 'class' => ($action == 'delete') ? 'selected' : false,
712 'text' => wfMsg('delete'),
713 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
714 );
715 }
716 if ( $this->mTitle->quickUserCan( 'move' ) ) {
717 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
718 $content_actions['move'] = array(
719 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
720 'text' => wfMsg('move'),
721 'href' => $moveTitle->getLocalUrl()
722 );
723 }
724 } else {
725 //article doesn't exist or is deleted
726 if( $wgUser->isAllowed( 'delete' ) ) {
727 if( $n = $this->mTitle->isDeleted() ) {
728 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
729 $content_actions['undelete'] = array(
730 'class' => false,
731 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
732 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
733 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
734 );
735 }
736 }
737 }
738 wfProfileOut( "$fname-live" );
739
740 if( $this->loggedin ) {
741 if( !$this->mTitle->userIsWatching()) {
742 $content_actions['watch'] = array(
743 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
744 'text' => wfMsg('watch'),
745 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
746 );
747 } else {
748 $content_actions['unwatch'] = array(
749 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
750 'text' => wfMsg('unwatch'),
751 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
752 );
753 }
754 }
755
756
757 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
758 } else {
759 /* show special page tab */
760
761 $content_actions[$this->mTitle->getNamespaceKey()] = array(
762 'class' => 'selected',
763 'text' => wfMsg('nstab-special'),
764 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
765 );
766
767 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
768 }
769
770 /* show links to different language variants */
771 global $wgDisableLangConversion;
772 $variants = $wgContLang->getVariants();
773 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
774 $preferred = $wgContLang->getPreferredVariant();
775 $vcount=0;
776 foreach( $variants as $code ) {
777 $varname = $wgContLang->getVariantname( $code );
778 if( $varname == 'disable' )
779 continue;
780 $selected = ( $code == $preferred )? 'selected' : false;
781 $content_actions['varlang-' . $vcount] = array(
782 'class' => $selected,
783 'text' => $varname,
784 'href' => $this->mTitle->getLocalURL('',$code)
785 );
786 $vcount ++;
787 }
788 }
789
790 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
791
792 wfProfileOut( $fname );
793 return $content_actions;
794 }
795
796
797
798 /**
799 * build array of common navigation links
800 * @return array
801 * @private
802 */
803 function buildNavUrls () {
804 global $wgUseTrackbacks, $wgTitle, $wgArticle;
805
806 $fname = 'SkinTemplate::buildNavUrls';
807 wfProfileIn( $fname );
808
809 global $wgUser, $wgRequest;
810 global $wgEnableUploads, $wgUploadNavigationUrl;
811
812 $action = $wgRequest->getText( 'action' );
813 $oldid = $wgRequest->getVal( 'oldid' );
814
815 $nav_urls = array();
816 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
817 if( $wgEnableUploads ) {
818 if ($wgUploadNavigationUrl) {
819 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
820 } else {
821 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
822 }
823 } else {
824 if ($wgUploadNavigationUrl)
825 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
826 else
827 $nav_urls['upload'] = false;
828 }
829 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
830
831 // default permalink to being off, will override it as required below.
832 $nav_urls['permalink'] = false;
833
834 // A print stylesheet is attached to all pages, but nobody ever
835 // figures that out. :) Add a link...
836 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
837 $nav_urls['print'] = array(
838 'text' => wfMsg( 'printableversion' ),
839 'href' => $wgRequest->appendQuery( 'printable=yes' )
840 );
841
842 // Also add a "permalink" while we're at it
843 if ( (int)$oldid ) {
844 $nav_urls['permalink'] = array(
845 'text' => wfMsg( 'permalink' ),
846 'href' => ''
847 );
848 } else if( $wgArticle ) {
849 $revid = ($wgArticle->mRevision) ? $wgArticle->mRevision->mId : $wgArticle->getLatest();
850 if ( $revid )
851 $nav_urls['permalink'] = array(
852 'text' => wfMsg( 'permalink' ),
853 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
854 );
855 }
856
857 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
858 }
859
860 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
861 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
862 $nav_urls['whatlinkshere'] = array(
863 'href' => $wlhTitle->getLocalUrl()
864 );
865 if( $this->mTitle->getArticleId() ) {
866 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
867 $nav_urls['recentchangeslinked'] = array(
868 'href' => $rclTitle->getLocalUrl()
869 );
870 } else {
871 $nav_urls['recentchangeslinked'] = false;
872 }
873 if ($wgUseTrackbacks)
874 $nav_urls['trackbacklink'] = array(
875 'href' => $wgTitle->trackbackURL()
876 );
877 }
878
879 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
880 $id = User::idFromName($this->mTitle->getText());
881 $ip = User::isIP($this->mTitle->getText());
882 } else {
883 $id = 0;
884 $ip = false;
885 }
886
887 if($id || $ip) { # both anons and non-anons have contri list
888 $nav_urls['contributions'] = array(
889 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
890 );
891 if ( $wgUser->isAllowed( 'block' ) ) {
892 $nav_urls['blockip'] = array(
893 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
894 );
895 } else {
896 $nav_urls['blockip'] = false;
897 }
898 } else {
899 $nav_urls['contributions'] = false;
900 $nav_urls['blockip'] = false;
901 }
902 $nav_urls['emailuser'] = false;
903 if( $this->showEmailUser( $id ) ) {
904 $nav_urls['emailuser'] = array(
905 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
906 );
907 }
908 wfProfileOut( $fname );
909 return $nav_urls;
910 }
911
912 /**
913 * Generate strings used for xml 'id' names
914 * @return string
915 * @private
916 */
917 function getNameSpaceKey () {
918 return $this->mTitle->getNamespaceKey();
919 }
920
921 /**
922 * @private
923 */
924 function setupUserCss() {
925 $fname = 'SkinTemplate::setupUserCss';
926 wfProfileIn( $fname );
927
928 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
929
930 $sitecss = '';
931 $usercss = '';
932 $siteargs = '&maxage=' . $wgSquidMaxage;
933 if( $this->loggedin ) {
934 // Ensure that logged-in users' generated CSS isn't clobbered
935 // by anons' publicly cacheable generated CSS.
936 $siteargs .= '&smaxage=0';
937 }
938
939 # Add user-specific code if this is a user and we allow that kind of thing
940
941 if ( $wgAllowUserCss && $this->loggedin ) {
942 $action = $wgRequest->getText('action');
943
944 # if we're previewing the CSS page, use it
945 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
946 $siteargs = "&smaxage=0&maxage=0";
947 $usercss = $wgRequest->getText('wpTextbox1');
948 } else {
949 $usercss = '@import "' .
950 self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
951 'action=raw&ctype=text/css') . '";' ."\n";
952 }
953
954 $siteargs .= '&ts=' . $wgUser->mTouched;
955 }
956
957 if( $wgContLang->isRTL() ) {
958 global $wgStyleVersion;
959 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
960 }
961
962 # If we use the site's dynamic CSS, throw that in, too
963 if ( $wgUseSiteCss ) {
964 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
965 $sitecss .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
966 $sitecss .= '@import "' . self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ) . '";' . "\n";
967 $sitecss .= '@import "' . self::makeUrl( '-', 'action=raw&gen=css' . $siteargs ) . '";' . "\n";
968 }
969
970 # If we use any dynamic CSS, make a little CDATA block out of it.
971
972 if ( !empty($sitecss) || !empty($usercss) ) {
973 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
974 }
975 wfProfileOut( $fname );
976 }
977
978 /**
979 * @private
980 */
981 function setupUserJs() {
982 $fname = 'SkinTemplate::setupUserJs';
983 wfProfileIn( $fname );
984
985 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
986 $action = $wgRequest->getText('action');
987
988 if( $wgAllowUserJs && $this->loggedin ) {
989 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
990 # XXX: additional security check/prompt?
991 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
992 } else {
993 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
994 }
995 }
996 wfProfileOut( $fname );
997 }
998
999 /**
1000 * Code for extensions to hook into to provide per-page CSS, see
1001 * extensions/PageCSS/PageCSS.php for an implementation of this.
1002 *
1003 * @private
1004 */
1005 function setupPageCss() {
1006 $fname = 'SkinTemplate::setupPageCss';
1007 wfProfileIn( $fname );
1008 $out = false;
1009 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1010
1011 wfProfileOut( $fname );
1012 return $out;
1013 }
1014
1015 /**
1016 * returns css with user-specific options
1017 * @public
1018 */
1019
1020 function getUserStylesheet() {
1021 $fname = 'SkinTemplate::getUserStylesheet';
1022 wfProfileIn( $fname );
1023
1024 $s = "/* generated user stylesheet */\n";
1025 $s .= $this->reallyDoGetUserStyles();
1026 wfProfileOut( $fname );
1027 return $s;
1028 }
1029
1030 /**
1031 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1032 * nated together. For some bizarre reason, it does *not* return any
1033 * custom user JS from subpages. Huh?
1034 *
1035 * There's absolutely no reason to have separate Monobook/Common JSes.
1036 * Any JS that cares can just check the skin variable generated at the
1037 * top. For now Monobook.js will be maintained, but it should be consi-
1038 * dered deprecated.
1039 *
1040 * @return string
1041 */
1042 public function getUserJs() {
1043 $fname = 'SkinTemplate::getUserJs';
1044 wfProfileIn( $fname );
1045
1046 $s = parent::getUserJs();
1047 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname).".js (deprecated; migrate to Common.js!) */\n";
1048
1049 // avoid inclusion of non defined user JavaScript (with custom skins only)
1050 // by checking for default message content
1051 $msgKey = ucfirst($this->skinname).'.js';
1052 $userJS = wfMsgForContent($msgKey);
1053 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1054 $s .= $userJS;
1055 }
1056
1057 wfProfileOut( $fname );
1058 return $s;
1059 }
1060 }
1061
1062 /**
1063 * Generic wrapper for template functions, with interface
1064 * compatible with what we use of PHPTAL 0.7.
1065 * @addtogroup Skins
1066 */
1067 class QuickTemplate {
1068 /**
1069 * @public
1070 */
1071 function QuickTemplate() {
1072 $this->data = array();
1073 $this->translator = new MediaWiki_I18N();
1074 }
1075
1076 /**
1077 * @public
1078 */
1079 function set( $name, $value ) {
1080 $this->data[$name] = $value;
1081 }
1082
1083 /**
1084 * @public
1085 */
1086 function setRef($name, &$value) {
1087 $this->data[$name] =& $value;
1088 }
1089
1090 /**
1091 * @public
1092 */
1093 function setTranslator( &$t ) {
1094 $this->translator = &$t;
1095 }
1096
1097 /**
1098 * @public
1099 */
1100 function execute() {
1101 echo "Override this function.";
1102 }
1103
1104
1105 /**
1106 * @private
1107 */
1108 function text( $str ) {
1109 echo htmlspecialchars( $this->data[$str] );
1110 }
1111
1112 /**
1113 * @private
1114 */
1115 function jstext( $str ) {
1116 echo Xml::escapeJsString( $this->data[$str] );
1117 }
1118
1119 /**
1120 * @private
1121 */
1122 function html( $str ) {
1123 echo $this->data[$str];
1124 }
1125
1126 /**
1127 * @private
1128 */
1129 function msg( $str ) {
1130 echo htmlspecialchars( $this->translator->translate( $str ) );
1131 }
1132
1133 /**
1134 * @private
1135 */
1136 function msgHtml( $str ) {
1137 echo $this->translator->translate( $str );
1138 }
1139
1140 /**
1141 * An ugly, ugly hack.
1142 * @private
1143 */
1144 function msgWiki( $str ) {
1145 global $wgParser, $wgTitle, $wgOut;
1146
1147 $text = $this->translator->translate( $str );
1148 $parserOutput = $wgParser->parse( $text, $wgTitle,
1149 $wgOut->parserOptions(), true );
1150 echo $parserOutput->getText();
1151 }
1152
1153 /**
1154 * @private
1155 */
1156 function haveData( $str ) {
1157 return isset( $this->data[$str] );
1158 }
1159
1160 /**
1161 * @private
1162 */
1163 function haveMsg( $str ) {
1164 $msg = $this->translator->translate( $str );
1165 return ($msg != '-') && ($msg != ''); # ????
1166 }
1167 }
1168 ?>