(bug 16823) 'Sidebar search form should not use Special:Search view URL as target'
[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( 'searchtitle', SpecialPage::getTitleFor('search')->getPrefixedDBKey() );
263 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
264 $tpl->setRef( 'stylepath', $wgStylePath );
265 $tpl->setRef( 'articlepath', $wgArticlePath );
266 $tpl->setRef( 'scriptpath', $wgScriptPath );
267 $tpl->setRef( 'serverurl', $wgServer );
268 $tpl->setRef( 'logopath', $wgLogo );
269 $tpl->setRef( "lang", $wgContLanguageCode );
270 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
271 $tpl->set( 'rtl', $wgContLang->isRTL() );
272 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
273 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
274 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
275 $tpl->setRef( 'userpage', $this->userpage);
276 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
277 $tpl->set( 'userlang', $wgLang->getCode() );
278 $tpl->set( 'pagecss', $this->setupPageCss() );
279 $tpl->setRef( 'usercss', $this->usercss);
280 $tpl->setRef( 'userjs', $this->userjs);
281 $tpl->setRef( 'userjsprev', $this->userjsprev);
282 if( $wgUseSiteJs ) {
283 $jsCache = $this->loggedin ? '&smaxage=0' : '';
284 $tpl->set( 'jsvarurl',
285 self::makeUrl('-',
286 "action=raw$jsCache&gen=js&useskin=" .
287 urlencode( $this->getSkinName() ) ) );
288 } else {
289 $tpl->set('jsvarurl', false);
290 }
291 $newtalks = $wgUser->getNewMessageLinks();
292
293 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
294 $usertitle = $this->mUser->getUserPage();
295 $usertalktitle = $usertitle->getTalkPage();
296 if( !$usertalktitle->equals( $this->mTitle ) ) {
297 $ntl = wfMsg( 'youhavenewmessages',
298 $this->makeKnownLinkObj(
299 $usertalktitle,
300 wfMsgHtml( 'newmessageslink' ),
301 'redirect=no'
302 ),
303 $this->makeKnownLinkObj(
304 $usertalktitle,
305 wfMsgHtml( 'newmessagesdifflink' ),
306 'diff=cur'
307 )
308 );
309 # Disable Cache
310 $out->setSquidMaxage(0);
311 }
312 } else if (count($newtalks)) {
313 $sep = str_replace("_", " ", wfMsgHtml("newtalkseparator"));
314 $msgs = array();
315 foreach ($newtalks as $newtalk) {
316 $msgs[] = Xml::element("a",
317 array('href' => $newtalk["link"]), $newtalk["wiki"]);
318 }
319 $parts = implode($sep, $msgs);
320 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
321 $out->setSquidMaxage(0);
322 } else {
323 $ntl = '';
324 }
325 wfProfileOut( __METHOD__."-stuff2" );
326
327 wfProfileIn( __METHOD__."-stuff3" );
328 $tpl->setRef( 'newtalk', $ntl );
329 $tpl->setRef( 'skin', $this );
330 $tpl->set( 'logo', $this->logoText() );
331 if ( $out->isArticle() and (!isset( $oldid ) or isset( $diff )) and
332 $wgArticle and 0 != $wgArticle->getID() )
333 {
334 if ( !$wgDisableCounters ) {
335 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
336 if ( $viewcount ) {
337 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
338 } else {
339 $tpl->set('viewcount', false);
340 }
341 } else {
342 $tpl->set('viewcount', false);
343 }
344
345 if ($wgPageShowWatchingUsers) {
346 $dbr = wfGetDB( DB_SLAVE );
347 $watchlist = $dbr->tableName( 'watchlist' );
348 $sql = "SELECT COUNT(*) AS n FROM $watchlist
349 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBkey()) .
350 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
351 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
352 $x = $dbr->fetchObject( $res );
353 $numberofwatchingusers = $x->n;
354 if ($numberofwatchingusers > 0) {
355 $tpl->set('numberofwatchingusers',
356 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
357 $wgLang->formatNum($numberofwatchingusers))
358 );
359 } else {
360 $tpl->set('numberofwatchingusers', false);
361 }
362 } else {
363 $tpl->set('numberofwatchingusers', false);
364 }
365
366 $tpl->set('copyright',$this->getCopyright());
367
368 $this->credits = false;
369
370 if( $wgMaxCredits != 0 ){
371 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
372 } else {
373 $tpl->set( 'lastmod', $this->lastModified() );
374 }
375
376 $tpl->setRef( 'credits', $this->credits );
377
378 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
379 $tpl->set('copyright', $this->getCopyright());
380 $tpl->set('viewcount', false);
381 $tpl->set('lastmod', false);
382 $tpl->set('credits', false);
383 $tpl->set('numberofwatchingusers', false);
384 } else {
385 $tpl->set('copyright', false);
386 $tpl->set('viewcount', false);
387 $tpl->set('lastmod', false);
388 $tpl->set('credits', false);
389 $tpl->set('numberofwatchingusers', false);
390 }
391 wfProfileOut( __METHOD__."-stuff3" );
392
393 wfProfileIn( __METHOD__."-stuff4" );
394 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
395 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
396 $tpl->set( 'disclaimer', $this->disclaimerLink() );
397 $tpl->set( 'privacy', $this->privacyLink() );
398 $tpl->set( 'about', $this->aboutLink() );
399
400 $tpl->setRef( 'debug', $out->mDebugtext );
401 $tpl->set( 'reporttime', wfReportTime() );
402 $tpl->set( 'sitenotice', wfGetSiteNotice() );
403 $tpl->set( 'bottomscripts', $this->bottomScripts() );
404
405 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
406 $out->mBodytext .= $printfooter . $this->generateDebugHTML();
407 $tpl->setRef( 'bodytext', $out->mBodytext );
408
409 # Language links
410 $language_urls = array();
411
412 if ( !$wgHideInterlanguageLinks ) {
413 foreach( $out->getLanguageLinks() as $l ) {
414 $tmp = explode( ':', $l, 2 );
415 $class = 'interwiki-' . $tmp[0];
416 unset($tmp);
417 $nt = Title::newFromText( $l );
418 if ( $nt ) {
419 $language_urls[] = array(
420 'href' => $nt->getFullURL(),
421 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
422 'class' => $class
423 );
424 }
425 }
426 }
427 if(count($language_urls)) {
428 $tpl->setRef( 'language_urls', $language_urls);
429 } else {
430 $tpl->set('language_urls', false);
431 }
432 wfProfileOut( __METHOD__."-stuff4" );
433
434 wfProfileIn( __METHOD__."-stuff5" );
435 # Personal toolbar
436 $tpl->set('personal_urls', $this->buildPersonalUrls());
437 $content_actions = $this->buildContentActionUrls();
438 $tpl->setRef('content_actions', $content_actions);
439
440 // XXX: attach this from javascript, same with section editing
441 if($this->iseditable && $wgUser->getOption("editondblclick") )
442 {
443 $encEditUrl = Xml::escapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
444 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
445 } else {
446 $tpl->set('body_ondblclick', false);
447 }
448 $tpl->set( 'body_onload', false );
449 $tpl->set( 'sidebar', $this->buildSidebar() );
450 $tpl->set( 'nav_urls', $this->buildNavUrls() );
451
452 // original version by hansm
453 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
454 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
455 }
456
457 // allow extensions adding stuff after the page content.
458 // See Skin::afterContentHook() for further documentation.
459 $tpl->set ('dataAfterContent', $this->afterContentHook());
460 wfProfileOut( __METHOD__."-stuff5" );
461
462 // execute template
463 wfProfileIn( __METHOD__."-execute" );
464 $res = $tpl->execute();
465 wfProfileOut( __METHOD__."-execute" );
466
467 // result may be an error
468 $this->printOrError( $res );
469 wfProfileOut( __METHOD__ );
470 }
471
472 /**
473 * Output the string, or print error message if it's
474 * an error object of the appropriate type.
475 * For the base class, assume strings all around.
476 *
477 * @param mixed $str
478 * @private
479 */
480 function printOrError( $str ) {
481 echo $str;
482 }
483
484 /**
485 * build array of urls for personal toolbar
486 * @return array
487 * @private
488 */
489 function buildPersonalUrls() {
490 global $wgTitle, $wgRequest;
491
492 $pageurl = $wgTitle->getLocalURL();
493 wfProfileIn( __METHOD__ );
494
495 /* set up the default links for the personal toolbar */
496 $personal_urls = array();
497 if ($this->loggedin) {
498 $personal_urls['userpage'] = array(
499 'text' => $this->username,
500 'href' => &$this->userpageUrlDetails['href'],
501 'class' => $this->userpageUrlDetails['exists']?false:'new',
502 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
503 );
504 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
505 $personal_urls['mytalk'] = array(
506 'text' => wfMsg('mytalk'),
507 'href' => &$usertalkUrlDetails['href'],
508 'class' => $usertalkUrlDetails['exists']?false:'new',
509 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
510 );
511 $href = self::makeSpecialUrl( 'Preferences' );
512 $personal_urls['preferences'] = array(
513 'text' => wfMsg( 'mypreferences' ),
514 'href' => $href,
515 'active' => ( $href == $pageurl )
516 );
517 $href = self::makeSpecialUrl( 'Watchlist' );
518 $personal_urls['watchlist'] = array(
519 'text' => wfMsg( 'mywatchlist' ),
520 'href' => $href,
521 'active' => ( $href == $pageurl )
522 );
523
524 # We need to do an explicit check for Special:Contributions, as we
525 # have to match both the title, and the target (which could come
526 # from request values or be specified in "sub page" form. The plot
527 # thickens, because $wgTitle is altered for special pages, so doesn't
528 # contain the original alias-with-subpage.
529 $title = Title::newFromText( $wgRequest->getText( 'title' ) );
530 if( $title instanceof Title && $title->getNamespace() == NS_SPECIAL ) {
531 list( $spName, $spPar ) =
532 SpecialPage::resolveAliasWithSubpage( $title->getText() );
533 $active = $spName == 'Contributions'
534 && ( ( $spPar && $spPar == $this->username )
535 || $wgRequest->getText( 'target' ) == $this->username );
536 } else {
537 $active = false;
538 }
539
540 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
541 $personal_urls['mycontris'] = array(
542 'text' => wfMsg( 'mycontris' ),
543 'href' => $href,
544 'active' => $active
545 );
546 $personal_urls['logout'] = array(
547 'text' => wfMsg( 'userlogout' ),
548 'href' => self::makeSpecialUrl( 'Userlogout',
549 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
550 ),
551 'active' => false
552 );
553 } else {
554 global $wgUser;
555 $loginlink = $wgUser->isAllowed( 'createaccount' )
556 ? 'nav-login-createaccount'
557 : 'login';
558 if( $this->showIPinHeader() ) {
559 $href = &$this->userpageUrlDetails['href'];
560 $personal_urls['anonuserpage'] = array(
561 'text' => $this->username,
562 'href' => $href,
563 'class' => $this->userpageUrlDetails['exists']?false:'new',
564 'active' => ( $pageurl == $href )
565 );
566 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
567 $href = &$usertalkUrlDetails['href'];
568 $personal_urls['anontalk'] = array(
569 'text' => wfMsg('anontalk'),
570 'href' => $href,
571 'class' => $usertalkUrlDetails['exists']?false:'new',
572 'active' => ( $pageurl == $href )
573 );
574 $personal_urls['anonlogin'] = array(
575 'text' => wfMsg( $loginlink ),
576 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
577 'active' => $wgTitle->isSpecial( 'Userlogin' )
578 );
579 } else {
580
581 $personal_urls['login'] = array(
582 'text' => wfMsg( $loginlink ),
583 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
584 'active' => $wgTitle->isSpecial( 'Userlogin' )
585 );
586 }
587 }
588
589 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
590 wfProfileOut( __METHOD__ );
591 return $personal_urls;
592 }
593
594 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
595 $classes = array();
596 if( $selected ) {
597 $classes[] = 'selected';
598 }
599 if( $checkEdit && !$title->isKnown() ) {
600 $classes[] = 'new';
601 $query = 'action=edit&redlink=1';
602 }
603
604 $text = wfMsg( $message );
605 if ( wfEmptyMsg( $message, $text ) ) {
606 global $wgContLang;
607 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
608 }
609
610 $result = array();
611 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
612 $title, $message, $selected, $checkEdit,
613 &$classes, &$query, &$text, &$result)) ) {
614 return $result;
615 }
616
617 return array(
618 'class' => implode( ' ', $classes ),
619 'text' => $text,
620 'href' => $title->getLocalUrl( $query ) );
621 }
622
623 function makeTalkUrlDetails( $name, $urlaction = '' ) {
624 $title = Title::newFromText( $name );
625 if( !is_object($title) ) {
626 throw new MWException( __METHOD__." given invalid pagename $name" );
627 }
628 $title = $title->getTalkPage();
629 self::checkTitle( $title, $name );
630 return array(
631 'href' => $title->getLocalURL( $urlaction ),
632 'exists' => $title->getArticleID() != 0 ? true : false
633 );
634 }
635
636 function makeArticleUrlDetails( $name, $urlaction = '' ) {
637 $title = Title::newFromText( $name );
638 $title= $title->getSubjectPage();
639 self::checkTitle( $title, $name );
640 return array(
641 'href' => $title->getLocalURL( $urlaction ),
642 'exists' => $title->getArticleID() != 0 ? true : false
643 );
644 }
645
646 /**
647 * an array of edit links by default used for the tabs
648 * @return array
649 * @private
650 */
651 function buildContentActionUrls() {
652 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest;
653
654 wfProfileIn( __METHOD__ );
655
656 $action = $wgRequest->getVal( 'action', 'view' );
657 $section = $wgRequest->getVal( 'section' );
658 $content_actions = array();
659
660 $prevent_active_tabs = false ;
661 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
662
663 if( $this->iscontent ) {
664 $subjpage = $this->mTitle->getSubjectPage();
665 $talkpage = $this->mTitle->getTalkPage();
666
667 $nskey = $this->mTitle->getNamespaceKey();
668 $content_actions[$nskey] = $this->tabAction(
669 $subjpage,
670 $nskey,
671 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
672 '', true);
673
674 $content_actions['talk'] = $this->tabAction(
675 $talkpage,
676 'talk',
677 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
678 '',
679 true);
680
681 wfProfileIn( __METHOD__."-edit" );
682 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
683 $istalk = $this->mTitle->isTalkPage();
684 $istalkclass = $istalk?' istalk':'';
685 $content_actions['edit'] = array(
686 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
687 'text' => $this->mTitle->exists()
688 ? wfMsg( 'edit' )
689 : wfMsg( 'create' ),
690 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
691 );
692
693 if ( $istalk || $wgOut->showNewSectionLink() ) {
694 if ( !$wgOut->forceHideNewSectionLink() ) {
695 $content_actions['addsection'] = array(
696 'class' => $section == 'new' ? 'selected' : false,
697 'text' => wfMsg('addsection'),
698 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
699 );
700 }
701 }
702 } elseif ( $this->mTitle->isKnown() ) {
703 $content_actions['viewsource'] = array(
704 'class' => ($action == 'edit') ? 'selected' : false,
705 'text' => wfMsg('viewsource'),
706 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
707 );
708 }
709 wfProfileOut( __METHOD__."-edit" );
710
711 wfProfileIn( __METHOD__."-live" );
712 if ( $this->mTitle->exists() ) {
713
714 $content_actions['history'] = array(
715 'class' => ($action == 'history') ? 'selected' : false,
716 'text' => wfMsg('history_short'),
717 'href' => $this->mTitle->getLocalUrl( 'action=history' ),
718 'rel' => 'archives',
719 );
720
721 if( $wgUser->isAllowed('delete') ) {
722 $content_actions['delete'] = array(
723 'class' => ($action == 'delete') ? 'selected' : false,
724 'text' => wfMsg('delete'),
725 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
726 );
727 }
728 if ( $this->mTitle->quickUserCan( 'move' ) ) {
729 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
730 $content_actions['move'] = array(
731 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
732 'text' => wfMsg('move'),
733 'href' => $moveTitle->getLocalUrl()
734 );
735 }
736
737 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
738 if( !$this->mTitle->isProtected() ){
739 $content_actions['protect'] = array(
740 'class' => ($action == 'protect') ? 'selected' : false,
741 'text' => wfMsg('protect'),
742 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
743 );
744
745 } else {
746 $content_actions['unprotect'] = array(
747 'class' => ($action == 'unprotect') ? 'selected' : false,
748 'text' => wfMsg('unprotect'),
749 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
750 );
751 }
752 }
753 } else {
754 //article doesn't exist or is deleted
755 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
756 if( $n = $this->mTitle->isDeleted() ) {
757 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
758 $content_actions['undelete'] = array(
759 'class' => false,
760 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
761 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
762 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
763 );
764 }
765 }
766
767 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
768 if( !$this->mTitle->getRestrictions( 'create' ) ) {
769 $content_actions['protect'] = array(
770 'class' => ($action == 'protect') ? 'selected' : false,
771 'text' => wfMsg('protect'),
772 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
773 );
774
775 } else {
776 $content_actions['unprotect'] = array(
777 'class' => ($action == 'unprotect') ? 'selected' : false,
778 'text' => wfMsg('unprotect'),
779 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
780 );
781 }
782 }
783 }
784
785 wfProfileOut( __METHOD__."-live" );
786
787 if( $this->loggedin ) {
788 if( !$this->mTitle->userIsWatching()) {
789 $content_actions['watch'] = array(
790 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
791 'text' => wfMsg('watch'),
792 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
793 );
794 } else {
795 $content_actions['unwatch'] = array(
796 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
797 'text' => wfMsg('unwatch'),
798 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
799 );
800 }
801 }
802
803
804 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
805 } else {
806 /* show special page tab */
807
808 $content_actions[$this->mTitle->getNamespaceKey()] = array(
809 'class' => 'selected',
810 'text' => wfMsg('nstab-special'),
811 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
812 );
813
814 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
815 }
816
817 /* show links to different language variants */
818 global $wgDisableLangConversion;
819 $variants = $wgContLang->getVariants();
820 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
821 $preferred = $wgContLang->getPreferredVariant();
822 $vcount=0;
823 foreach( $variants as $code ) {
824 $varname = $wgContLang->getVariantname( $code );
825 if( $varname == 'disable' )
826 continue;
827 $selected = ( $code == $preferred )? 'selected' : false;
828 $content_actions['varlang-' . $vcount] = array(
829 'class' => $selected,
830 'text' => $varname,
831 'href' => $this->mTitle->getLocalURL('',$code)
832 );
833 $vcount ++;
834 }
835 }
836
837 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
838
839 wfProfileOut( __METHOD__ );
840 return $content_actions;
841 }
842
843
844
845 /**
846 * build array of common navigation links
847 * @return array
848 * @private
849 */
850 function buildNavUrls() {
851 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
852 global $wgEnableUploads, $wgUploadNavigationUrl;
853
854 wfProfileIn( __METHOD__ );
855
856 $action = $wgRequest->getVal( 'action', 'view' );
857
858 $nav_urls = array();
859 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
860 if( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
861 if ($wgUploadNavigationUrl) {
862 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
863 } else {
864 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
865 }
866 } else {
867 if ($wgUploadNavigationUrl)
868 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
869 else
870 $nav_urls['upload'] = false;
871 }
872 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
873
874 // default permalink to being off, will override it as required below.
875 $nav_urls['permalink'] = false;
876
877 // A print stylesheet is attached to all pages, but nobody ever
878 // figures that out. :) Add a link...
879 if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
880 $nav_urls['print'] = array(
881 'text' => wfMsg( 'printableversion' ),
882 'href' => $wgRequest->appendQuery( 'printable=yes' )
883 );
884
885 // Also add a "permalink" while we're at it
886 if ( $this->mRevisionId ) {
887 $nav_urls['permalink'] = array(
888 'text' => wfMsg( 'permalink' ),
889 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
890 );
891 }
892
893 // Copy in case this undocumented, shady hook tries to mess with internals
894 $revid = $this->mRevisionId;
895 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
896 }
897
898 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
899 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
900 $nav_urls['whatlinkshere'] = array(
901 'href' => $wlhTitle->getLocalUrl()
902 );
903 if( $this->mTitle->getArticleId() ) {
904 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
905 $nav_urls['recentchangeslinked'] = array(
906 'href' => $rclTitle->getLocalUrl()
907 );
908 } else {
909 $nav_urls['recentchangeslinked'] = false;
910 }
911 if ($wgUseTrackbacks)
912 $nav_urls['trackbacklink'] = array(
913 'href' => $wgTitle->trackbackURL()
914 );
915 }
916
917 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
918 $id = User::idFromName($this->mTitle->getText());
919 $ip = User::isIP($this->mTitle->getText());
920 } else {
921 $id = 0;
922 $ip = false;
923 }
924
925 if($id || $ip) { # both anons and non-anons have contribs list
926 $nav_urls['contributions'] = array(
927 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
928 );
929
930 if( $id ) {
931 $logPage = SpecialPage::getTitleFor( 'Log' );
932 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
933 . $this->mTitle->getPartialUrl() ) );
934 } else {
935 $nav_urls['log'] = false;
936 }
937
938 if ( $wgUser->isAllowed( 'block' ) ) {
939 $nav_urls['blockip'] = array(
940 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
941 );
942 } else {
943 $nav_urls['blockip'] = false;
944 }
945 } else {
946 $nav_urls['contributions'] = false;
947 $nav_urls['log'] = false;
948 $nav_urls['blockip'] = false;
949 }
950 $nav_urls['emailuser'] = false;
951 if( $this->showEmailUser( $id ) ) {
952 $nav_urls['emailuser'] = array(
953 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
954 );
955 }
956 wfProfileOut( __METHOD__ );
957 return $nav_urls;
958 }
959
960 /**
961 * Generate strings used for xml 'id' names
962 * @return string
963 * @private
964 */
965 function getNameSpaceKey() {
966 return $this->mTitle->getNamespaceKey();
967 }
968
969 /**
970 * @private
971 */
972 function setupUserJs( $allowUserJs ) {
973 global $wgRequest, $wgJsMimeType;
974
975 wfProfileIn( __METHOD__ );
976
977 $action = $wgRequest->getVal( 'action', 'view' );
978
979 if( $allowUserJs && $this->loggedin ) {
980 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
981 # XXX: additional security check/prompt?
982 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
983 } else {
984 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType);
985 }
986 }
987 wfProfileOut( __METHOD__ );
988 }
989
990 /**
991 * Code for extensions to hook into to provide per-page CSS, see
992 * extensions/PageCSS/PageCSS.php for an implementation of this.
993 *
994 * @private
995 */
996 function setupPageCss() {
997 wfProfileIn( __METHOD__ );
998 $out = false;
999 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1000 wfProfileOut( __METHOD__ );
1001 return $out;
1002 }
1003 }
1004
1005 /**
1006 * Generic wrapper for template functions, with interface
1007 * compatible with what we use of PHPTAL 0.7.
1008 * @ingroup Skins
1009 */
1010 class QuickTemplate {
1011 /**
1012 * @public
1013 */
1014 function QuickTemplate() {
1015 $this->data = array();
1016 $this->translator = new MediaWiki_I18N();
1017 }
1018
1019 /**
1020 * @public
1021 */
1022 function set( $name, $value ) {
1023 $this->data[$name] = $value;
1024 }
1025
1026 /**
1027 * @public
1028 */
1029 function setRef($name, &$value) {
1030 $this->data[$name] =& $value;
1031 }
1032
1033 /**
1034 * @public
1035 */
1036 function setTranslator( &$t ) {
1037 $this->translator = &$t;
1038 }
1039
1040 /**
1041 * @public
1042 */
1043 function execute() {
1044 echo "Override this function.";
1045 }
1046
1047
1048 /**
1049 * @private
1050 */
1051 function text( $str ) {
1052 echo htmlspecialchars( $this->data[$str] );
1053 }
1054
1055 /**
1056 * @private
1057 */
1058 function jstext( $str ) {
1059 echo Xml::escapeJsString( $this->data[$str] );
1060 }
1061
1062 /**
1063 * @private
1064 */
1065 function html( $str ) {
1066 echo $this->data[$str];
1067 }
1068
1069 /**
1070 * @private
1071 */
1072 function msg( $str ) {
1073 echo htmlspecialchars( $this->translator->translate( $str ) );
1074 }
1075
1076 /**
1077 * @private
1078 */
1079 function msgHtml( $str ) {
1080 echo $this->translator->translate( $str );
1081 }
1082
1083 /**
1084 * An ugly, ugly hack.
1085 * @private
1086 */
1087 function msgWiki( $str ) {
1088 global $wgParser, $wgTitle, $wgOut;
1089
1090 $text = $this->translator->translate( $str );
1091 $parserOutput = $wgParser->parse( $text, $wgTitle,
1092 $wgOut->parserOptions(), true );
1093 echo $parserOutput->getText();
1094 }
1095
1096 /**
1097 * @private
1098 */
1099 function haveData( $str ) {
1100 return isset( $this->data[$str] );
1101 }
1102
1103 /**
1104 * @private
1105 */
1106 function haveMsg( $str ) {
1107 $msg = $this->translator->translate( $str );
1108 return ($msg != '-') && ($msg != ''); # ????
1109 }
1110 }