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