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