ea26d8d2d9ff61c2f13fb75a0840ac6f5ed4cc1d
[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, $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 $action = $wgRequest->getVal( 'action', 'view' );
152
153 wfProfileIn( __METHOD__."-init" );
154 $this->initPage( $out );
155
156 $this->setMembers();
157 $tpl = $this->setupTemplate( $this->template, 'skins' );
158
159 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
160 $tpl->setTranslator(new MediaWiki_I18N());
161 #}
162 wfProfileOut( __METHOD__."-init" );
163
164 wfProfileIn( __METHOD__."-stuff" );
165 $this->thispage = $this->mTitle->getPrefixedDbKey();
166 $this->thisurl = $this->mTitle->getPrefixedURL();
167 $this->loggedin = $wgUser->isLoggedIn();
168 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
169 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
170 $this->username = $wgUser->getName();
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->userjs = $this->userjsprev = false;
181 $this->setupUserCss( $out );
182 $this->setupUserJs( $out->isUserJsAllowed() );
183 $this->titletxt = $this->mTitle->getPrefixedText();
184 wfProfileOut( __METHOD__."-stuff" );
185
186 wfProfileIn( __METHOD__."-stuff2" );
187 $tpl->set( 'title', $out->getPageTitle() );
188 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
189 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
190 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
191 $tpl->set( 'skinnameclass', ( "skin-" . Sanitizer::escapeClass( $this->getSkinName ( ) ) ) );
192
193 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
194 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
195 $this->mTitle->getNsText();
196
197 $tpl->set( 'nscanonical', $nsname );
198 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
199 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
200 $tpl->set( 'titletext', $this->mTitle->getText() );
201 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
202 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
203
204 $tpl->set( 'isarticle', $out->isArticle() );
205
206 $tpl->setRef( "thispage", $this->thispage );
207 $subpagestr = $this->subPageSubtitle();
208 $tpl->set(
209 'subtitle', !empty($subpagestr)?
210 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
211 $out->getSubtitle()
212 );
213 $undelete = $this->getUndeleteLink();
214 $tpl->set(
215 "undelete", !empty($undelete)?
216 '<span class="subpages">'.$undelete.'</span>':
217 ''
218 );
219
220 $tpl->set( 'catlinks', $this->getCategories());
221 if( $out->isSyndicated() ) {
222 $feeds = array();
223 foreach( $out->getSyndicationLinks() as $format => $link ) {
224 $feeds[$format] = array(
225 'text' => wfMsg( "feed-$format" ),
226 'href' => $link );
227 }
228 $tpl->setRef( 'feeds', $feeds );
229 } else {
230 $tpl->set( 'feeds', false );
231 }
232 if ($wgUseTrackbacks && $out->isArticleRelated()) {
233 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
234 } else {
235 $tpl->set( 'trackbackhtml', null );
236 }
237
238 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
239 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
240 $tpl->setRef( 'mimetype', $wgMimeType );
241 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
242 $tpl->setRef( 'charset', $wgOutputEncoding );
243 $tpl->set( 'headlinks', $out->getHeadLinks() );
244 $tpl->set( 'headscripts', $out->getScript() );
245 $tpl->set( 'csslinks', $out->buildCssLinks() );
246 $tpl->setRef( 'wgScript', $wgScript );
247 $tpl->setRef( 'skinname', $this->skinname );
248 $tpl->set( 'skinclass', get_class( $this ) );
249 $tpl->setRef( 'stylename', $this->stylename );
250 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
251 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
252 $tpl->setRef( 'loggedin', $this->loggedin );
253 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
254 /* XXX currently unused, might get useful later
255 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
256 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
257 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
258 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
259 $tpl->set( "helppage", wfMsg('helppage'));
260 */
261 $tpl->set( 'searchaction', $this->escapeSearchLink() );
262 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
263 $tpl->setRef( 'stylepath', $wgStylePath );
264 $tpl->setRef( 'articlepath', $wgArticlePath );
265 $tpl->setRef( 'scriptpath', $wgScriptPath );
266 $tpl->setRef( 'serverurl', $wgServer );
267 $tpl->setRef( 'logopath', $wgLogo );
268 $tpl->setRef( "lang", $wgContLanguageCode );
269 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
270 $tpl->set( 'rtl', $wgContLang->isRTL() );
271 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
272 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
273 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
274 $tpl->setRef( 'userpage', $this->userpage);
275 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
276 $tpl->set( 'userlang', $wgLang->getCode() );
277 $tpl->set( 'pagecss', $this->setupPageCss() );
278 $tpl->setRef( 'usercss', $this->usercss);
279 $tpl->setRef( 'userjs', $this->userjs);
280 $tpl->setRef( 'userjsprev', $this->userjsprev);
281 if( $wgUseSiteJs ) {
282 $jsCache = $this->loggedin ? '&smaxage=0' : '';
283 $tpl->set( 'jsvarurl',
284 self::makeUrl('-',
285 "action=raw$jsCache&gen=js&useskin=" .
286 urlencode( $this->getSkinName() ) ) );
287 } else {
288 $tpl->set('jsvarurl', false);
289 }
290 $newtalks = $wgUser->getNewMessageLinks();
291
292 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
293 $usertitle = $this->mUser->getUserPage();
294 $usertalktitle = $usertitle->getTalkPage();
295 if( !$usertalktitle->equals( $this->mTitle ) ) {
296 $ntl = wfMsg( 'youhavenewmessages',
297 $this->makeKnownLinkObj(
298 $usertalktitle,
299 wfMsgHtml( 'newmessageslink' ),
300 'redirect=no'
301 ),
302 $this->makeKnownLinkObj(
303 $usertalktitle,
304 wfMsgHtml( 'newmessagesdifflink' ),
305 'diff=cur'
306 )
307 );
308 # Disable Cache
309 $out->setSquidMaxage(0);
310 }
311 } else if (count($newtalks)) {
312 $sep = str_replace("_", " ", wfMsgHtml("newtalkseparator"));
313 $msgs = array();
314 foreach ($newtalks as $newtalk) {
315 $msgs[] = Xml::element("a",
316 array('href' => $newtalk["link"]), $newtalk["wiki"]);
317 }
318 $parts = implode($sep, $msgs);
319 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
320 $out->setSquidMaxage(0);
321 } else {
322 $ntl = '';
323 }
324 wfProfileOut( __METHOD__."-stuff2" );
325
326 wfProfileIn( __METHOD__."-stuff3" );
327 $tpl->setRef( 'newtalk', $ntl );
328 $tpl->setRef( 'skin', $this );
329 $tpl->set( 'logo', $this->logoText() );
330 if ( $out->isArticle() and (!isset( $oldid ) or isset( $diff )) and
331 $wgArticle and 0 != $wgArticle->getID() )
332 {
333 if ( !$wgDisableCounters ) {
334 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
335 if ( $viewcount ) {
336 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
337 } else {
338 $tpl->set('viewcount', false);
339 }
340 } else {
341 $tpl->set('viewcount', false);
342 }
343
344 if ($wgPageShowWatchingUsers) {
345 $dbr = wfGetDB( DB_SLAVE );
346 $watchlist = $dbr->tableName( 'watchlist' );
347 $sql = "SELECT COUNT(*) AS n FROM $watchlist
348 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBkey()) .
349 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
350 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
351 $x = $dbr->fetchObject( $res );
352 $numberofwatchingusers = $x->n;
353 if ($numberofwatchingusers > 0) {
354 $tpl->set('numberofwatchingusers',
355 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
356 $wgLang->formatNum($numberofwatchingusers))
357 );
358 } else {
359 $tpl->set('numberofwatchingusers', false);
360 }
361 } else {
362 $tpl->set('numberofwatchingusers', false);
363 }
364
365 $tpl->set('copyright',$this->getCopyright());
366
367 $this->credits = false;
368
369 if( $wgMaxCredits != 0 ){
370 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
371 } else {
372 $tpl->set( 'lastmod', $this->lastModified() );
373 }
374
375 $tpl->setRef( 'credits', $this->credits );
376
377 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
378 $tpl->set('copyright', $this->getCopyright());
379 $tpl->set('viewcount', false);
380 $tpl->set('lastmod', false);
381 $tpl->set('credits', false);
382 $tpl->set('numberofwatchingusers', false);
383 } else {
384 $tpl->set('copyright', false);
385 $tpl->set('viewcount', false);
386 $tpl->set('lastmod', false);
387 $tpl->set('credits', false);
388 $tpl->set('numberofwatchingusers', false);
389 }
390 wfProfileOut( __METHOD__."-stuff3" );
391
392 wfProfileIn( __METHOD__."-stuff4" );
393 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
394 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
395 $tpl->set( 'disclaimer', $this->disclaimerLink() );
396 $tpl->set( 'privacy', $this->privacyLink() );
397 $tpl->set( 'about', $this->aboutLink() );
398
399 $tpl->setRef( 'debug', $out->mDebugtext );
400 $tpl->set( 'reporttime', wfReportTime() );
401 $tpl->set( 'sitenotice', wfGetSiteNotice() );
402 $tpl->set( 'bottomscripts', $this->bottomScripts() );
403
404 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
405 $out->mBodytext .= $printfooter . $this->generateDebugHTML();
406 $tpl->setRef( 'bodytext', $out->mBodytext );
407
408 # Language links
409 $language_urls = array();
410
411 if ( !$wgHideInterlanguageLinks ) {
412 foreach( $out->getLanguageLinks() as $l ) {
413 $tmp = explode( ':', $l, 2 );
414 $class = 'interwiki-' . $tmp[0];
415 unset($tmp);
416 $nt = Title::newFromText( $l );
417 if ( $nt ) {
418 $language_urls[] = array(
419 'href' => $nt->getFullURL(),
420 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
421 'class' => $class
422 );
423 }
424 }
425 }
426 if(count($language_urls)) {
427 $tpl->setRef( 'language_urls', $language_urls);
428 } else {
429 $tpl->set('language_urls', false);
430 }
431 wfProfileOut( __METHOD__."-stuff4" );
432
433 wfProfileIn( __METHOD__."-stuff5" );
434 # Personal toolbar
435 $tpl->set('personal_urls', $this->buildPersonalUrls());
436 $content_actions = $this->buildContentActionUrls();
437 $tpl->setRef('content_actions', $content_actions);
438
439 // XXX: attach this from javascript, same with section editing
440 if($this->iseditable && $wgUser->getOption("editondblclick") )
441 {
442 $encEditUrl = Xml::escapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
443 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
444 } else {
445 $tpl->set('body_ondblclick', false);
446 }
447 $tpl->set( 'body_onload', false );
448 $tpl->set( 'sidebar', $this->buildSidebar() );
449 $tpl->set( 'nav_urls', $this->buildNavUrls() );
450
451 // original version by hansm
452 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
453 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
454 }
455
456 // allow extensions adding stuff after the page content.
457 // See Skin::afterContentHook() for further documentation.
458 $tpl->set ('dataAfterContent', $this->afterContentHook());
459 wfProfileOut( __METHOD__."-stuff5" );
460
461 // execute template
462 wfProfileIn( __METHOD__."-execute" );
463 $res = $tpl->execute();
464 wfProfileOut( __METHOD__."-execute" );
465
466 // result may be an error
467 $this->printOrError( $res );
468 wfProfileOut( __METHOD__ );
469 }
470
471 /**
472 * Output the string, or print error message if it's
473 * an error object of the appropriate type.
474 * For the base class, assume strings all around.
475 *
476 * @param mixed $str
477 * @private
478 */
479 function printOrError( $str ) {
480 echo $str;
481 }
482
483 /**
484 * build array of urls for personal toolbar
485 * @return array
486 * @private
487 */
488 function buildPersonalUrls() {
489 global $wgTitle, $wgRequest;
490
491 $pageurl = $wgTitle->getLocalURL();
492 wfProfileIn( __METHOD__ );
493
494 /* set up the default links for the personal toolbar */
495 $personal_urls = array();
496 if ($this->loggedin) {
497 $personal_urls['userpage'] = array(
498 'text' => $this->username,
499 'href' => &$this->userpageUrlDetails['href'],
500 'class' => $this->userpageUrlDetails['exists']?false:'new',
501 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
502 );
503 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
504 $personal_urls['mytalk'] = array(
505 'text' => wfMsg('mytalk'),
506 'href' => &$usertalkUrlDetails['href'],
507 'class' => $usertalkUrlDetails['exists']?false:'new',
508 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
509 );
510 $href = self::makeSpecialUrl( 'Preferences' );
511 $personal_urls['preferences'] = array(
512 'text' => wfMsg( 'mypreferences' ),
513 'href' => $href,
514 'active' => ( $href == $pageurl )
515 );
516 $href = self::makeSpecialUrl( 'Watchlist' );
517 $personal_urls['watchlist'] = array(
518 'text' => wfMsg( 'mywatchlist' ),
519 'href' => $href,
520 'active' => ( $href == $pageurl )
521 );
522
523 # We need to do an explicit check for Special:Contributions, as we
524 # have to match both the title, and the target (which could come
525 # from request values or be specified in "sub page" form. The plot
526 # thickens, because $wgTitle is altered for special pages, so doesn't
527 # contain the original alias-with-subpage.
528 $title = Title::newFromText( $wgRequest->getText( 'title' ) );
529 if( $title instanceof Title && $title->getNamespace() == NS_SPECIAL ) {
530 list( $spName, $spPar ) =
531 SpecialPage::resolveAliasWithSubpage( $title->getText() );
532 $active = $spName == 'Contributions'
533 && ( ( $spPar && $spPar == $this->username )
534 || $wgRequest->getText( 'target' ) == $this->username );
535 } else {
536 $active = false;
537 }
538
539 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
540 $personal_urls['mycontris'] = array(
541 'text' => wfMsg( 'mycontris' ),
542 'href' => $href,
543 'active' => $active
544 );
545 $personal_urls['logout'] = array(
546 'text' => wfMsg( 'userlogout' ),
547 'href' => self::makeSpecialUrl( 'Userlogout',
548 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
549 ),
550 'active' => false
551 );
552 } else {
553 global $wgUser;
554 $loginlink = $wgUser->isAllowed( 'createaccount' )
555 ? 'nav-login-createaccount'
556 : 'login';
557 if( $this->showIPinHeader() ) {
558 $href = &$this->userpageUrlDetails['href'];
559 $personal_urls['anonuserpage'] = array(
560 'text' => $this->username,
561 'href' => $href,
562 'class' => $this->userpageUrlDetails['exists']?false:'new',
563 'active' => ( $pageurl == $href )
564 );
565 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
566 $href = &$usertalkUrlDetails['href'];
567 $personal_urls['anontalk'] = array(
568 'text' => wfMsg('anontalk'),
569 'href' => $href,
570 'class' => $usertalkUrlDetails['exists']?false:'new',
571 'active' => ( $pageurl == $href )
572 );
573 $personal_urls['anonlogin'] = array(
574 'text' => wfMsg( $loginlink ),
575 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
576 'active' => $wgTitle->isSpecial( 'Userlogin' )
577 );
578 } else {
579
580 $personal_urls['login'] = array(
581 'text' => wfMsg( $loginlink ),
582 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
583 'active' => $wgTitle->isSpecial( 'Userlogin' )
584 );
585 }
586 }
587
588 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
589 wfProfileOut( __METHOD__ );
590 return $personal_urls;
591 }
592
593 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
594 $classes = array();
595 if( $selected ) {
596 $classes[] = 'selected';
597 }
598 if( $checkEdit && !$title->isKnown() ) {
599 $classes[] = 'new';
600 $query = 'action=edit&redlink=1';
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, $wgUser, $wgRequest;
652
653 wfProfileIn( __METHOD__ );
654
655 $action = $wgRequest->getVal( 'action', 'view' );
656 $section = $wgRequest->getVal( '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->isKnown() ) {
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 'rel' => 'archives',
716 );
717
718 if( $wgUser->isAllowed('delete') ) {
719 $content_actions['delete'] = array(
720 'class' => ($action == 'delete') ? 'selected' : false,
721 'text' => wfMsg('delete'),
722 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
723 );
724 }
725 if ( $this->mTitle->quickUserCan( 'move' ) ) {
726 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
727 $content_actions['move'] = array(
728 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
729 'text' => wfMsg('move'),
730 'href' => $moveTitle->getLocalUrl()
731 );
732 }
733
734 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
735 if( !$this->mTitle->isProtected() ){
736 $content_actions['protect'] = array(
737 'class' => ($action == 'protect') ? 'selected' : false,
738 'text' => wfMsg('protect'),
739 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
740 );
741
742 } else {
743 $content_actions['unprotect'] = array(
744 'class' => ($action == 'unprotect') ? 'selected' : false,
745 'text' => wfMsg('unprotect'),
746 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
747 );
748 }
749 }
750 } else {
751 //article doesn't exist or is deleted
752 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
753 if( $n = $this->mTitle->isDeleted() ) {
754 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
755 $content_actions['undelete'] = array(
756 'class' => false,
757 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
758 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
759 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
760 );
761 }
762 }
763
764 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
765 if( !$this->mTitle->getRestrictions( 'create' ) ) {
766 $content_actions['protect'] = array(
767 'class' => ($action == 'protect') ? 'selected' : false,
768 'text' => wfMsg('protect'),
769 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
770 );
771
772 } else {
773 $content_actions['unprotect'] = array(
774 'class' => ($action == 'unprotect') ? 'selected' : false,
775 'text' => wfMsg('unprotect'),
776 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
777 );
778 }
779 }
780 }
781
782 wfProfileOut( __METHOD__."-live" );
783
784 if( $this->loggedin ) {
785 if( !$this->mTitle->userIsWatching()) {
786 $content_actions['watch'] = array(
787 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
788 'text' => wfMsg('watch'),
789 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
790 );
791 } else {
792 $content_actions['unwatch'] = array(
793 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
794 'text' => wfMsg('unwatch'),
795 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
796 );
797 }
798 }
799
800
801 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
802 } else {
803 /* show special page tab */
804
805 $content_actions[$this->mTitle->getNamespaceKey()] = array(
806 'class' => 'selected',
807 'text' => wfMsg('nstab-special'),
808 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
809 );
810
811 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
812 }
813
814 /* show links to different language variants */
815 global $wgDisableLangConversion;
816 $variants = $wgContLang->getVariants();
817 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
818 $preferred = $wgContLang->getPreferredVariant();
819 $vcount=0;
820 foreach( $variants as $code ) {
821 $varname = $wgContLang->getVariantname( $code );
822 if( $varname == 'disable' )
823 continue;
824 $selected = ( $code == $preferred )? 'selected' : false;
825 $content_actions['varlang-' . $vcount] = array(
826 'class' => $selected,
827 'text' => $varname,
828 'href' => $this->mTitle->getLocalURL('',$code)
829 );
830 $vcount ++;
831 }
832 }
833
834 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
835
836 wfProfileOut( __METHOD__ );
837 return $content_actions;
838 }
839
840
841
842 /**
843 * build array of common navigation links
844 * @return array
845 * @private
846 */
847 function buildNavUrls() {
848 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
849 global $wgEnableUploads, $wgUploadNavigationUrl;
850
851 wfProfileIn( __METHOD__ );
852
853 $action = $wgRequest->getVal( 'action', 'view' );
854
855 $nav_urls = array();
856 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
857 if( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
858 if ($wgUploadNavigationUrl) {
859 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
860 } else {
861 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
862 }
863 } else {
864 if ($wgUploadNavigationUrl)
865 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
866 else
867 $nav_urls['upload'] = false;
868 }
869 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
870
871 // default permalink to being off, will override it as required below.
872 $nav_urls['permalink'] = false;
873
874 // A print stylesheet is attached to all pages, but nobody ever
875 // figures that out. :) Add a link...
876 if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
877 $nav_urls['print'] = array(
878 'text' => wfMsg( 'printableversion' ),
879 'href' => $wgRequest->appendQuery( 'printable=yes' )
880 );
881
882 // Also add a "permalink" while we're at it
883 if ( $this->mRevisionId ) {
884 $nav_urls['permalink'] = array(
885 'text' => wfMsg( 'permalink' ),
886 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
887 );
888 }
889
890 // Copy in case this undocumented, shady hook tries to mess with internals
891 $revid = $this->mRevisionId;
892 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
893 }
894
895 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
896 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
897 $nav_urls['whatlinkshere'] = array(
898 'href' => $wlhTitle->getLocalUrl()
899 );
900 if( $this->mTitle->getArticleId() ) {
901 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
902 $nav_urls['recentchangeslinked'] = array(
903 'href' => $rclTitle->getLocalUrl()
904 );
905 } else {
906 $nav_urls['recentchangeslinked'] = false;
907 }
908 if ($wgUseTrackbacks)
909 $nav_urls['trackbacklink'] = array(
910 'href' => $wgTitle->trackbackURL()
911 );
912 }
913
914 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
915 $id = User::idFromName($this->mTitle->getText());
916 $ip = User::isIP($this->mTitle->getText());
917 } else {
918 $id = 0;
919 $ip = false;
920 }
921
922 if($id || $ip) { # both anons and non-anons have contribs list
923 $nav_urls['contributions'] = array(
924 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
925 );
926
927 if( $id ) {
928 $logPage = SpecialPage::getTitleFor( 'Log' );
929 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
930 . $this->mTitle->getPartialUrl() ) );
931 } else {
932 $nav_urls['log'] = false;
933 }
934
935 if ( $wgUser->isAllowed( 'block' ) ) {
936 $nav_urls['blockip'] = array(
937 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
938 );
939 } else {
940 $nav_urls['blockip'] = false;
941 }
942 } else {
943 $nav_urls['contributions'] = false;
944 $nav_urls['log'] = false;
945 $nav_urls['blockip'] = false;
946 }
947 $nav_urls['emailuser'] = false;
948 if( $this->showEmailUser( $id ) ) {
949 $nav_urls['emailuser'] = array(
950 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
951 );
952 }
953 wfProfileOut( __METHOD__ );
954 return $nav_urls;
955 }
956
957 /**
958 * Generate strings used for xml 'id' names
959 * @return string
960 * @private
961 */
962 function getNameSpaceKey() {
963 return $this->mTitle->getNamespaceKey();
964 }
965
966 /**
967 * @private
968 */
969 function setupUserJs( $allowUserJs ) {
970 global $wgRequest, $wgJsMimeType;
971
972 wfProfileIn( __METHOD__ );
973
974 $action = $wgRequest->getVal( 'action', 'view' );
975
976 if( $allowUserJs && $this->loggedin ) {
977 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
978 # XXX: additional security check/prompt?
979 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
980 } else {
981 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType);
982 }
983 }
984 wfProfileOut( __METHOD__ );
985 }
986
987 /**
988 * Code for extensions to hook into to provide per-page CSS, see
989 * extensions/PageCSS/PageCSS.php for an implementation of this.
990 *
991 * @private
992 */
993 function setupPageCss() {
994 wfProfileIn( __METHOD__ );
995 $out = false;
996 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
997 wfProfileOut( __METHOD__ );
998 return $out;
999 }
1000 }
1001
1002 /**
1003 * Generic wrapper for template functions, with interface
1004 * compatible with what we use of PHPTAL 0.7.
1005 * @ingroup Skins
1006 */
1007 class QuickTemplate {
1008 /**
1009 * @public
1010 */
1011 function QuickTemplate() {
1012 $this->data = array();
1013 $this->translator = new MediaWiki_I18N();
1014 }
1015
1016 /**
1017 * @public
1018 */
1019 function set( $name, $value ) {
1020 $this->data[$name] = $value;
1021 }
1022
1023 /**
1024 * @public
1025 */
1026 function setRef($name, &$value) {
1027 $this->data[$name] =& $value;
1028 }
1029
1030 /**
1031 * @public
1032 */
1033 function setTranslator( &$t ) {
1034 $this->translator = &$t;
1035 }
1036
1037 /**
1038 * @public
1039 */
1040 function execute() {
1041 echo "Override this function.";
1042 }
1043
1044
1045 /**
1046 * @private
1047 */
1048 function text( $str ) {
1049 echo htmlspecialchars( $this->data[$str] );
1050 }
1051
1052 /**
1053 * @private
1054 */
1055 function jstext( $str ) {
1056 echo Xml::escapeJsString( $this->data[$str] );
1057 }
1058
1059 /**
1060 * @private
1061 */
1062 function html( $str ) {
1063 echo $this->data[$str];
1064 }
1065
1066 /**
1067 * @private
1068 */
1069 function msg( $str ) {
1070 echo htmlspecialchars( $this->translator->translate( $str ) );
1071 }
1072
1073 /**
1074 * @private
1075 */
1076 function msgHtml( $str ) {
1077 echo $this->translator->translate( $str );
1078 }
1079
1080 /**
1081 * An ugly, ugly hack.
1082 * @private
1083 */
1084 function msgWiki( $str ) {
1085 global $wgParser, $wgTitle, $wgOut;
1086
1087 $text = $this->translator->translate( $str );
1088 $parserOutput = $wgParser->parse( $text, $wgTitle,
1089 $wgOut->parserOptions(), true );
1090 echo $parserOutput->getText();
1091 }
1092
1093 /**
1094 * @private
1095 */
1096 function haveData( $str ) {
1097 return isset( $this->data[$str] );
1098 }
1099
1100 /**
1101 * @private
1102 */
1103 function haveMsg( $str ) {
1104 $msg = $this->translator->translate( $str );
1105 return ($msg != '-') && ($msg != ''); # ????
1106 }
1107 }