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