Some escaping fixes and related readability changes
[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 $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, $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 }
229 $tpl->setRef( 'feeds', $feeds );
230 } else {
231 $tpl->set( 'feeds', false );
232 }
233 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
234 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
235 } else {
236 $tpl->set( 'trackbackhtml', null );
237 }
238
239 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
240 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
241 $tpl->setRef( 'mimetype', $wgMimeType );
242 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
243 $tpl->setRef( 'charset', $wgOutputEncoding );
244 $tpl->set( 'headlinks', $out->getHeadLinks() );
245 $tpl->set( 'headscripts', $out->getScript() );
246 $tpl->set( 'csslinks', $out->buildCssLinks() );
247 $tpl->setRef( 'wgScript', $wgScript );
248 $tpl->setRef( 'skinname', $this->skinname );
249 $tpl->set( 'skinclass', get_class( $this ) );
250 $tpl->setRef( 'stylename', $this->stylename );
251 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
252 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
253 $tpl->setRef( 'loggedin', $this->loggedin );
254 $tpl->set( 'notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL );
255 /* XXX currently unused, might get useful later
256 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
257 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
258 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
259 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
260 $tpl->set( "helppage", wfMsg('helppage'));
261 */
262 $tpl->set( 'searchaction', $this->escapeSearchLink() );
263 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBKey() );
264 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
265 $tpl->setRef( 'stylepath', $wgStylePath );
266 $tpl->setRef( 'articlepath', $wgArticlePath );
267 $tpl->setRef( 'scriptpath', $wgScriptPath );
268 $tpl->setRef( 'serverurl', $wgServer );
269 $tpl->setRef( 'logopath', $wgLogo );
270 $tpl->setRef( 'lang', $wgContLanguageCode );
271 $tpl->set( 'dir', $wgContLang->isRTL() ? 'rtl' : 'ltr' );
272 $tpl->set( 'rtl', $wgContLang->isRTL() );
273 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
274 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
275 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
276 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
277 $tpl->setRef( 'userpage', $this->userpage );
278 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
279 $tpl->set( 'userlang', $wgLang->getCode() );
280 $tpl->set( 'userlangattributes', 'lang="' . $wgLang->getCode() . '" xml:lang="' . $wgLang->getCode() . '"' );
281 $tpl->set( 'pagecss', $this->setupPageCss() );
282 $tpl->setRef( 'usercss', $this->usercss );
283 $tpl->setRef( 'userjs', $this->userjs );
284 $tpl->setRef( 'userjsprev', $this->userjsprev );
285 if( $wgUseSiteJs ) {
286 $jsCache = $this->loggedin ? '&smaxage=0' : '';
287 $tpl->set( 'jsvarurl',
288 self::makeUrl( '-',
289 "action=raw$jsCache&gen=js&useskin=" .
290 urlencode( $this->getSkinName() ) ) );
291 } else {
292 $tpl->set( 'jsvarurl', false );
293 }
294
295 $newtalks = $wgUser->getNewMessageLinks();
296
297 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
298 $usertitle = $this->mUser->getUserPage();
299 $usertalktitle = $usertitle->getTalkPage();
300
301 if( !$usertalktitle->equals( $this->mTitle ) ) {
302 $newmessageslink = $this->link(
303 $usertalktitle,
304 wfMsgHtml( 'newmessageslink' ),
305 array(),
306 array( 'redirect' => 'no' ),
307 array( 'known', 'noclasses' )
308 );
309
310 $newmessagesdifflink = $this->link(
311 $usertalktitle,
312 wfMsgHtml( 'newmessagesdifflink' ),
313 array(),
314 array( 'diff' => 'cur' ),
315 array( 'known', 'noclasses' )
316 );
317
318 $ntl = wfMsg(
319 'youhavenewmessages',
320 $newmessageslink,
321 $newmessagesdifflink
322 );
323 # Disable Cache
324 $out->setSquidMaxage( 0 );
325 }
326 } else if( count( $newtalks ) ) {
327 // _>" " for BC <= 1.16
328 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
329 $msgs = array();
330 foreach( $newtalks as $newtalk ) {
331 $msgs[] = Xml::element('a',
332 array( 'href' => $newtalk['link'] ), $newtalk['wiki'] );
333 }
334 $parts = implode( $sep, $msgs );
335 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
336 $out->setSquidMaxage( 0 );
337 } else {
338 $ntl = '';
339 }
340 wfProfileOut( __METHOD__ . '-stuff2' );
341
342 wfProfileIn( __METHOD__ . '-stuff3' );
343 $tpl->setRef( 'newtalk', $ntl );
344 $tpl->setRef( 'skin', $this );
345 $tpl->set( 'logo', $this->logoText() );
346 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
347 $wgArticle and 0 != $wgArticle->getID() ){
348 if ( !$wgDisableCounters ) {
349 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
350 if ( $viewcount ) {
351 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
352 } else {
353 $tpl->set( 'viewcount', false );
354 }
355 } else {
356 $tpl->set( 'viewcount', false );
357 }
358
359 if( $wgPageShowWatchingUsers ) {
360 $dbr = wfGetDB( DB_SLAVE );
361 $watchlist = $dbr->tableName( 'watchlist' );
362 $res = $dbr->select( 'watchlist',
363 array( 'COUNT(*) AS n' ),
364 array( 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ), 'wl_namespace' => $this->mTitle->getNamespace() ),
365 __METHOD__
366 );
367 $x = $dbr->fetchObject( $res );
368 $numberofwatchingusers = $x->n;
369 if( $numberofwatchingusers > 0 ) {
370 $tpl->set( 'numberofwatchingusers',
371 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
372 $wgLang->formatNum( $numberofwatchingusers ) )
373 );
374 } else {
375 $tpl->set( 'numberofwatchingusers', false );
376 }
377 } else {
378 $tpl->set( 'numberofwatchingusers', false );
379 }
380
381 $tpl->set( 'copyright', $this->getCopyright() );
382
383 $this->credits = false;
384
385 if( $wgMaxCredits != 0 ){
386 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
387 } else {
388 $tpl->set( 'lastmod', $this->lastModified() );
389 }
390
391 $tpl->setRef( 'credits', $this->credits );
392
393 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
394 $tpl->set( 'copyright', $this->getCopyright() );
395 $tpl->set( 'viewcount', false );
396 $tpl->set( 'lastmod', false );
397 $tpl->set( 'credits', false );
398 $tpl->set( 'numberofwatchingusers', false );
399 } else {
400 $tpl->set( 'copyright', false );
401 $tpl->set( 'viewcount', false );
402 $tpl->set( 'lastmod', false );
403 $tpl->set( 'credits', false );
404 $tpl->set( 'numberofwatchingusers', false );
405 }
406 wfProfileOut( __METHOD__ . '-stuff3' );
407
408 wfProfileIn( __METHOD__ . '-stuff4' );
409 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
410 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
411 $tpl->set( 'disclaimer', $this->disclaimerLink() );
412 $tpl->set( 'privacy', $this->privacyLink() );
413 $tpl->set( 'about', $this->aboutLink() );
414
415 $tpl->setRef( 'debug', $out->mDebugtext );
416 $tpl->set( 'reporttime', wfReportTime() );
417 $tpl->set( 'sitenotice', wfGetSiteNotice() );
418 $tpl->set( 'bottomscripts', $this->bottomScripts() );
419
420 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
421 $out->mBodytext .= $printfooter . $this->generateDebugHTML();
422 $tpl->setRef( 'bodytext', $out->mBodytext );
423
424 # Language links
425 $language_urls = array();
426
427 if ( !$wgHideInterlanguageLinks ) {
428 foreach( $out->getLanguageLinks() as $l ) {
429 $tmp = explode( ':', $l, 2 );
430 $class = 'interwiki-' . $tmp[0];
431 unset( $tmp );
432 $nt = Title::newFromText( $l );
433 if ( $nt ) {
434 $language_urls[] = array(
435 'href' => $nt->getFullURL(),
436 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
437 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
438 'class' => $class
439 );
440 }
441 }
442 }
443 if( count( $language_urls ) ) {
444 $tpl->setRef( 'language_urls', $language_urls );
445 } else {
446 $tpl->set( 'language_urls', false );
447 }
448 wfProfileOut( __METHOD__ . '-stuff4' );
449
450 wfProfileIn( __METHOD__ . '-stuff5' );
451 # Personal toolbar
452 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
453 $content_actions = $this->buildContentActionUrls();
454 $tpl->setRef( 'content_actions', $content_actions );
455
456 // XXX: attach this from javascript, same with section editing
457 if( $this->iseditable && $wgUser->getOption( 'editondblclick' ) ){
458 $encEditUrl = Xml::escapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
459 $tpl->set( 'body_ondblclick', 'document.location = "' . $encEditUrl . '";' );
460 } else {
461 $tpl->set( 'body_ondblclick', false );
462 }
463 $tpl->set( 'body_onload', false );
464 $tpl->set( 'sidebar', $this->buildSidebar() );
465 $tpl->set( 'nav_urls', $this->buildNavUrls() );
466
467 // original version by hansm
468 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
469 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
470 }
471
472 // allow extensions adding stuff after the page content.
473 // See Skin::afterContentHook() for further documentation.
474 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
475 wfProfileOut( __METHOD__ . '-stuff5' );
476
477 // execute template
478 wfProfileIn( __METHOD__ . '-execute' );
479 $res = $tpl->execute();
480 wfProfileOut( __METHOD__ . '-execute' );
481
482 // result may be an error
483 $this->printOrError( $res );
484 wfProfileOut( __METHOD__ );
485 }
486
487 /**
488 * Output the string, or print error message if it's
489 * an error object of the appropriate type.
490 * For the base class, assume strings all around.
491 *
492 * @param mixed $str
493 * @private
494 */
495 function printOrError( $str ) {
496 echo $str;
497 }
498
499 /**
500 * build array of urls for personal toolbar
501 * @return array
502 * @private
503 */
504 function buildPersonalUrls() {
505 global $wgOut, $wgRequest;
506
507 $title = $wgOut->getTitle();
508 $pageurl = $title->getLocalURL();
509 wfProfileIn( __METHOD__ );
510
511 /* set up the default links for the personal toolbar */
512 $personal_urls = array();
513 if( $this->loggedin ) {
514 $personal_urls['userpage'] = array(
515 'text' => $this->username,
516 'href' => &$this->userpageUrlDetails['href'],
517 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
518 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
519 );
520 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
521 $personal_urls['mytalk'] = array(
522 'text' => wfMsg( 'mytalk' ),
523 'href' => &$usertalkUrlDetails['href'],
524 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
525 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
526 );
527 $href = self::makeSpecialUrl( 'Preferences' );
528 $personal_urls['preferences'] = array(
529 'text' => wfMsg( 'mypreferences' ),
530 'href' => $href,
531 'active' => ( $href == $pageurl )
532 );
533 $href = self::makeSpecialUrl( 'Watchlist' );
534 $personal_urls['watchlist'] = array(
535 'text' => wfMsg( 'mywatchlist' ),
536 'href' => $href,
537 'active' => ( $href == $pageurl )
538 );
539
540 # We need to do an explicit check for Special:Contributions, as we
541 # have to match both the title, and the target (which could come
542 # from request values or be specified in "sub page" form. The plot
543 # thickens, because $wgTitle is altered for special pages, so doesn't
544 # contain the original alias-with-subpage.
545 $origTitle = Title::newFromText( $wgRequest->getText( 'title' ) );
546 if( $origTitle instanceof Title && $origTitle->getNamespace() == NS_SPECIAL ) {
547 list( $spName, $spPar ) =
548 SpecialPage::resolveAliasWithSubpage( $origTitle->getText() );
549 $active = $spName == 'Contributions'
550 && ( ( $spPar && $spPar == $this->username )
551 || $wgRequest->getText( 'target' ) == $this->username );
552 } else {
553 $active = false;
554 }
555
556 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
557 $personal_urls['mycontris'] = array(
558 'text' => wfMsg( 'mycontris' ),
559 'href' => $href,
560 'active' => $active
561 );
562 $personal_urls['logout'] = array(
563 'text' => wfMsg( 'userlogout' ),
564 'href' => self::makeSpecialUrl( 'Userlogout',
565 $title->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
566 ),
567 'active' => false
568 );
569 } else {
570 global $wgUser;
571 $loginlink = $wgUser->isAllowed( 'createaccount' )
572 ? 'nav-login-createaccount'
573 : 'login';
574 if( $this->showIPinHeader() ) {
575 $href = &$this->userpageUrlDetails['href'];
576 $personal_urls['anonuserpage'] = array(
577 'text' => $this->username,
578 'href' => $href,
579 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
580 'active' => ( $pageurl == $href )
581 );
582 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
583 $href = &$usertalkUrlDetails['href'];
584 $personal_urls['anontalk'] = array(
585 'text' => wfMsg( 'anontalk' ),
586 'href' => $href,
587 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
588 'active' => ( $pageurl == $href )
589 );
590 $personal_urls['anonlogin'] = array(
591 'text' => wfMsg( $loginlink ),
592 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
593 'active' => $title->isSpecial( 'Userlogin' )
594 );
595 } else {
596 $personal_urls['login'] = array(
597 'text' => wfMsg( $loginlink ),
598 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
599 'active' => $title->isSpecial( 'Userlogin' )
600 );
601 }
602 }
603
604 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
605 wfProfileOut( __METHOD__ );
606 return $personal_urls;
607 }
608
609 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
610 $classes = array();
611 if( $selected ) {
612 $classes[] = 'selected';
613 }
614 if( $checkEdit && !$title->isKnown() ) {
615 $classes[] = 'new';
616 $query = 'action=edit&redlink=1';
617 }
618
619 $text = wfMsg( $message );
620 if ( wfEmptyMsg( $message, $text ) ) {
621 global $wgContLang;
622 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
623 }
624
625 $result = array();
626 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
627 $title, $message, $selected, $checkEdit,
628 &$classes, &$query, &$text, &$result ) ) ) {
629 return $result;
630 }
631
632 return array(
633 'class' => implode( ' ', $classes ),
634 'text' => $text,
635 'href' => $title->getLocalUrl( $query ) );
636 }
637
638 function makeTalkUrlDetails( $name, $urlaction = '' ) {
639 $title = Title::newFromText( $name );
640 if( !is_object( $title ) ) {
641 throw new MWException( __METHOD__ . " given invalid pagename $name" );
642 }
643 $title = $title->getTalkPage();
644 self::checkTitle( $title, $name );
645 return array(
646 'href' => $title->getLocalURL( $urlaction ),
647 'exists' => $title->getArticleID() != 0 ? true : false
648 );
649 }
650
651 function makeArticleUrlDetails( $name, $urlaction = '' ) {
652 $title = Title::newFromText( $name );
653 $title= $title->getSubjectPage();
654 self::checkTitle( $title, $name );
655 return array(
656 'href' => $title->getLocalURL( $urlaction ),
657 'exists' => $title->getArticleID() != 0 ? true : false
658 );
659 }
660
661 /**
662 * an array of edit links by default used for the tabs
663 * @return array
664 * @private
665 */
666 function buildContentActionUrls() {
667 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
668
669 wfProfileIn( __METHOD__ );
670
671 $action = $wgRequest->getVal( 'action', 'view' );
672 $section = $wgRequest->getVal( 'section' );
673 $content_actions = array();
674
675 $prevent_active_tabs = false;
676 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
677
678 if( $this->iscontent ) {
679 $subjpage = $this->mTitle->getSubjectPage();
680 $talkpage = $this->mTitle->getTalkPage();
681
682 $nskey = $this->mTitle->getNamespaceKey();
683 $content_actions[$nskey] = $this->tabAction(
684 $subjpage,
685 $nskey,
686 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
687 '', true
688 );
689
690 $content_actions['talk'] = $this->tabAction(
691 $talkpage,
692 'talk',
693 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
694 '',
695 true
696 );
697
698 wfProfileIn( __METHOD__ . '-edit' );
699 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
700 $istalk = $this->mTitle->isTalkPage();
701 $istalkclass = $istalk?' istalk':'';
702 $content_actions['edit'] = array(
703 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ? 'selected' : '' ) . $istalkclass,
704 'text' => $this->mTitle->exists()
705 ? wfMsg( 'edit' )
706 : wfMsg( 'create' ),
707 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
708 );
709
710 // adds new section link if page is a current revision of a talk page or
711 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) || $wgOut->showNewSectionLink() ) {
712 if ( !$wgOut->forceHideNewSectionLink() ) {
713 $content_actions['addsection'] = array(
714 'class' => $section == 'new' ? 'selected' : false,
715 'text' => wfMsg( 'addsection' ),
716 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
717 );
718 }
719 }
720 } elseif ( $this->mTitle->isKnown() ) {
721 $content_actions['viewsource'] = array(
722 'class' => ($action == 'edit') ? 'selected' : false,
723 'text' => wfMsg( 'viewsource' ),
724 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
725 );
726 }
727 wfProfileOut( __METHOD__ . '-edit' );
728
729 wfProfileIn( __METHOD__ . '-live' );
730 if ( $this->mTitle->exists() ) {
731
732 $content_actions['history'] = array(
733 'class' => ($action == 'history') ? 'selected' : false,
734 'text' => wfMsg( 'history_short' ),
735 'href' => $this->mTitle->getLocalUrl( 'action=history' ),
736 'rel' => 'archives',
737 );
738
739 if( $wgUser->isAllowed( 'delete' ) ) {
740 $content_actions['delete'] = array(
741 'class' => ($action == 'delete') ? 'selected' : false,
742 'text' => wfMsg( 'delete' ),
743 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
744 );
745 }
746 if ( $this->mTitle->quickUserCan( 'move' ) ) {
747 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
748 $content_actions['move'] = array(
749 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
750 'text' => wfMsg( 'move' ),
751 'href' => $moveTitle->getLocalUrl()
752 );
753 }
754
755 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
756 if( !$this->mTitle->isProtected() ){
757 $content_actions['protect'] = array(
758 'class' => ($action == 'protect') ? 'selected' : false,
759 'text' => wfMsg( 'protect' ),
760 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
761 );
762
763 } else {
764 $content_actions['unprotect'] = array(
765 'class' => ($action == 'unprotect') ? 'selected' : false,
766 'text' => wfMsg( 'unprotect' ),
767 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
768 );
769 }
770 }
771 } else {
772 //article doesn't exist or is deleted
773 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
774 if( $n = $this->mTitle->isDeleted() ) {
775 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
776 $content_actions['undelete'] = array(
777 'class' => false,
778 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
779 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
780 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
781 );
782 }
783 }
784
785 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
786 if( !$this->mTitle->getRestrictions( 'create' ) ) {
787 $content_actions['protect'] = array(
788 'class' => ($action == 'protect') ? 'selected' : false,
789 'text' => wfMsg( 'protect' ),
790 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
791 );
792
793 } else {
794 $content_actions['unprotect'] = array(
795 'class' => ($action == 'unprotect') ? 'selected' : false,
796 'text' => wfMsg( 'unprotect' ),
797 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
798 );
799 }
800 }
801 }
802
803 wfProfileOut( __METHOD__ . '-live' );
804
805 if( $this->loggedin ) {
806 if( !$this->mTitle->userIsWatching()) {
807 $content_actions['watch'] = array(
808 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
809 'text' => wfMsg( 'watch' ),
810 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
811 );
812 } else {
813 $content_actions['unwatch'] = array(
814 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
815 'text' => wfMsg( 'unwatch' ),
816 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
817 );
818 }
819 }
820
821
822 wfRunHooks( 'SkinTemplateTabs', array( &$this, &$content_actions ) );
823 } else {
824 /* show special page tab */
825
826 $content_actions[$this->mTitle->getNamespaceKey()] = array(
827 'class' => 'selected',
828 'text' => wfMsg('nstab-special'),
829 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
830 );
831
832 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
833 }
834
835 /* show links to different language variants */
836 global $wgDisableLangConversion;
837 $variants = $wgContLang->getVariants();
838 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
839 $preferred = $wgContLang->getPreferredVariant();
840 $vcount=0;
841 foreach( $variants as $code ) {
842 $varname = $wgContLang->getVariantname( $code );
843 if( $varname == 'disable' )
844 continue;
845 $selected = ( $code == $preferred )? 'selected' : false;
846 $content_actions['varlang-' . $vcount] = array(
847 'class' => $selected,
848 'text' => $varname,
849 'href' => $this->mTitle->getLocalURL( '', $code )
850 );
851 $vcount ++;
852 }
853 }
854
855 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
856
857 wfProfileOut( __METHOD__ );
858 return $content_actions;
859 }
860
861 /**
862 * build array of common navigation links
863 * @return array
864 * @private
865 */
866 function buildNavUrls() {
867 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
868 global $wgEnableUploads, $wgUploadNavigationUrl;
869
870 wfProfileIn( __METHOD__ );
871
872 $action = $wgRequest->getVal( 'action', 'view' );
873
874 $nav_urls = array();
875 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
876 if( $wgUploadNavigationUrl ) {
877 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
878 } elseif( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
879 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
880 } else {
881 $nav_urls['upload'] = false;
882 }
883 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
884
885 // default permalink to being off, will override it as required below.
886 $nav_urls['permalink'] = false;
887
888 // A print stylesheet is attached to all pages, but nobody ever
889 // figures that out. :) Add a link...
890 if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
891 if ( !$wgRequest->getBool( 'printable' ) ) {
892 $nav_urls['print'] = array(
893 'text' => wfMsg( 'printableversion' ),
894 'href' => $wgRequest->appendQuery( 'printable=yes' )
895 );
896 }
897
898 // Also add a "permalink" while we're at it
899 if ( $this->mRevisionId ) {
900 $nav_urls['permalink'] = array(
901 'text' => wfMsg( 'permalink' ),
902 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
903 );
904 }
905
906 // Copy in case this undocumented, shady hook tries to mess with internals
907 $revid = $this->mRevisionId;
908 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
909 }
910
911 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
912 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
913 $nav_urls['whatlinkshere'] = array(
914 'href' => $wlhTitle->getLocalUrl()
915 );
916 if( $this->mTitle->getArticleId() ) {
917 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
918 $nav_urls['recentchangeslinked'] = array(
919 'href' => $rclTitle->getLocalUrl()
920 );
921 } else {
922 $nav_urls['recentchangeslinked'] = false;
923 }
924 if( $wgUseTrackbacks )
925 $nav_urls['trackbacklink'] = array(
926 'href' => $wgOut->getTitle()->trackbackURL()
927 );
928 }
929
930 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
931 $id = User::idFromName( $this->mTitle->getText() );
932 $ip = User::isIP( $this->mTitle->getText() );
933 } else {
934 $id = 0;
935 $ip = false;
936 }
937
938 if( $id || $ip ) { # both anons and non-anons have contribs list
939 $nav_urls['contributions'] = array(
940 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
941 );
942
943 if( $id ) {
944 $logPage = SpecialPage::getTitleFor( 'Log' );
945 $nav_urls['log'] = array(
946 'href' => $logPage->getLocalUrl(
947 array(
948 'user' => $this->mTitle->getText()
949 )
950 )
951 );
952 } else {
953 $nav_urls['log'] = false;
954 }
955
956 if ( $wgUser->isAllowed( 'block' ) ) {
957 $nav_urls['blockip'] = array(
958 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
959 );
960 } else {
961 $nav_urls['blockip'] = false;
962 }
963 } else {
964 $nav_urls['contributions'] = false;
965 $nav_urls['log'] = false;
966 $nav_urls['blockip'] = false;
967 }
968 $nav_urls['emailuser'] = false;
969 if( $this->showEmailUser( $id ) ) {
970 $nav_urls['emailuser'] = array(
971 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
972 );
973 }
974 wfProfileOut( __METHOD__ );
975 return $nav_urls;
976 }
977
978 /**
979 * Builds a structured array of links used for tabs and menus
980 * @return array
981 * @private
982 */
983 function buildNavigationUrls() {
984 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
985 global $wgDisableLangConversion;
986
987 wfProfileIn( __METHOD__ );
988
989 $links = array(
990 'namespaces' => array(),
991 'views' => array(),
992 'actions' => array(),
993 'variants' => array()
994 );
995
996 // Detects parameters
997 $action = $wgRequest->getVal( 'action', 'view' );
998 $section = $wgRequest->getVal( 'section' );
999
1000 // Checks if page is some kind of content
1001 if( $this->iscontent ) {
1002
1003 // Gets page objects for the related namespaces
1004 $subjectPage = $this->mTitle->getSubjectPage();
1005 $talkPage = $this->mTitle->getTalkPage();
1006
1007 // Determines if this is a talk page
1008 $isTalk = $this->mTitle->isTalkPage();
1009
1010 // Generates XML IDs from namespace names
1011 $subjectId = $this->mTitle->getNamespaceKey( '' );
1012
1013 if ( $subjectId == 'main' ) {
1014 $talkId = 'talk';
1015 } else {
1016 $talkId = "{$subjectId}_talk";
1017 }
1018 $currentId = $isTalk ? $talkId : $subjectId;
1019
1020 // Adds namespace links
1021 $links['namespaces'][$subjectId] = $this->tabAction(
1022 $subjectPage, 'vector-namespace-' . $subjectId, !$isTalk, '', true
1023 );
1024 $links['namespaces'][$subjectId]['context'] = 'subject';
1025 $links['namespaces'][$talkId] = $this->tabAction(
1026 $talkPage, 'vector-namespace-talk', $isTalk, '', true
1027 );
1028 $links['namespaces'][$talkId]['context'] = 'talk';
1029
1030 // Adds view view link
1031 if ( $this->mTitle->exists() ) {
1032 $links['views']['view'] = $this->tabAction(
1033 $isTalk ? $talkPage : $subjectPage,
1034 'vector-view-view', ( $action == 'view' ), '', true
1035 );
1036 }
1037
1038 wfProfileIn( __METHOD__ . '-edit' );
1039
1040 // Checks if user can...
1041 if (
1042 // edit the current page
1043 $this->mTitle->quickUserCan( 'edit' ) &&
1044 (
1045 // if it exists
1046 $this->mTitle->exists() ||
1047 // or they can create one here
1048 $this->mTitle->quickUserCan( 'create' )
1049 )
1050 ) {
1051 // Builds CSS class for talk page links
1052 $isTalkClass = $isTalk ? ' istalk' : '';
1053
1054 // Determines if we're in edit mode
1055 $selected = (
1056 ( $action == 'edit' || $action == 'submit' ) &&
1057 ( $section != 'new' )
1058 );
1059 $links['views']['edit'] = array(
1060 'class' => ( $selected ? 'selected' : '' ) . $isTalkClass,
1061 'text' => $this->mTitle->exists()
1062 ? wfMsg( 'vector-view-edit' )
1063 : wfMsg( 'vector-view-create' ),
1064 'href' =>
1065 $this->mTitle->getLocalUrl( $this->editUrlOptions() )
1066 );
1067 // Checks if this is a current rev of talk page and we should show a new
1068 // section link
1069 if ( ( $isTalk && $wgArticle->isCurrent() ) || ( $wgOut->showNewSectionLink() ) ) {
1070 // Checks if we should ever show a new section link
1071 if ( !$wgOut->forceHideNewSectionLink() ) {
1072 // Adds new section link
1073 $links['actions']['addsection'] = array(
1074 'class' => $section == 'new' ? 'selected' : false,
1075 'text' => wfMsg( 'vector-action-addsection' ),
1076 'href' => $this->mTitle->getLocalUrl(
1077 'action=edit&section=new'
1078 )
1079 );
1080 }
1081 }
1082 // Checks if the page is known (some kind of viewable content)
1083 } elseif ( $this->mTitle->isKnown() ) {
1084 // Adds view source view link
1085 $links['views']['viewsource'] = array(
1086 'class' => ( $action == 'edit' ) ? 'selected' : false,
1087 'text' => wfMsg( 'vector-view-viewsource' ),
1088 'href' =>
1089 $this->mTitle->getLocalUrl( $this->editUrlOptions() )
1090 );
1091 }
1092 wfProfileOut( __METHOD__ . '-edit' );
1093
1094 wfProfileIn( __METHOD__ . '-live' );
1095
1096 // Checks if the page exists
1097 if ( $this->mTitle->exists() ) {
1098 // Adds history view link
1099 $links['views']['history'] = array(
1100 'class' => ($action == 'history') ? 'selected' : false,
1101 'text' => wfMsg( 'vector-view-history' ),
1102 'href' => $this->mTitle->getLocalUrl( 'action=history' ),
1103 'rel' => 'archives',
1104 );
1105
1106 if( $wgUser->isAllowed( 'delete' ) ) {
1107 $links['actions']['delete'] = array(
1108 'class' => ($action == 'delete') ? 'selected' : false,
1109 'text' => wfMsg( 'vector-action-delete' ),
1110 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
1111 );
1112 }
1113 if ( $this->mTitle->quickUserCan( 'move' ) ) {
1114 $moveTitle = SpecialPage::getTitleFor(
1115 'Movepage', $this->thispage
1116 );
1117 $links['actions']['move'] = array(
1118 'class' => $this->mTitle->isSpecial( 'Movepage' ) ?
1119 'selected' : false,
1120 'text' => wfMsg( 'vector-action-move' ),
1121 'href' => $moveTitle->getLocalUrl()
1122 );
1123 }
1124
1125 if (
1126 $this->mTitle->getNamespace() !== NS_MEDIAWIKI &&
1127 $wgUser->isAllowed( 'protect' )
1128 ) {
1129 if ( !$this->mTitle->isProtected() ){
1130 $links['actions']['protect'] = array(
1131 'class' => ($action == 'protect') ?
1132 'selected' : false,
1133 'text' => wfMsg( 'vector-action-protect' ),
1134 'href' =>
1135 $this->mTitle->getLocalUrl( 'action=protect' )
1136 );
1137
1138 } else {
1139 $links['actions']['unprotect'] = array(
1140 'class' => ($action == 'unprotect') ?
1141 'selected' : false,
1142 'text' => wfMsg( 'vector-action-unprotect' ),
1143 'href' =>
1144 $this->mTitle->getLocalUrl( 'action=unprotect' )
1145 );
1146 }
1147 }
1148 } else {
1149 // article doesn't exist or is deleted
1150 if (
1151 $wgUser->isAllowed( 'deletedhistory' ) &&
1152 $wgUser->isAllowed( 'undelete' )
1153 ) {
1154 if( $n = $this->mTitle->isDeleted() ) {
1155 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
1156 $links['actions']['undelete'] = array(
1157 'class' => false,
1158 'text' => wfMsgExt(
1159 'vector-action-undelete',
1160 array( 'parsemag' ),
1161 $wgLang->formatNum( $n )
1162 ),
1163 'href' => $undelTitle->getLocalUrl(
1164 'target=' . urlencode( $this->thispage )
1165 )
1166 );
1167 }
1168 }
1169
1170 if (
1171 $this->mTitle->getNamespace() !== NS_MEDIAWIKI &&
1172 $wgUser->isAllowed( 'protect' )
1173 ) {
1174 if ( !$this->mTitle->getRestrictions( 'create' ) ) {
1175 $links['actions']['protect'] = array(
1176 'class' => ($action == 'protect') ?
1177 'selected' : false,
1178 'text' => wfMsg( 'vector-action-protect' ),
1179 'href' =>
1180 $this->mTitle->getLocalUrl( 'action=protect' )
1181 );
1182
1183 } else {
1184 $links['actions']['unprotect'] = array(
1185 'class' => ($action == 'unprotect') ?
1186 'selected' : false,
1187 'text' => wfMsg( 'vector-action-unprotect' ),
1188 'href' =>
1189 $this->mTitle->getLocalUrl( 'action=unprotect' )
1190 );
1191 }
1192 }
1193 }
1194 wfProfileOut( __METHOD__ . '-live' );
1195
1196 /**
1197 * The following actions use messages which, if made particular to
1198 * the Vector skin, would break the Ajax code which makes this
1199 * action happen entirely inline. Skin::makeGlobalVariablesScript
1200 * defines a set of messages in a javascript object - and these
1201 * messages are assumed to be global for all skins. Without making
1202 * a change to that procedure these messages will have to remain as
1203 * the global versions.
1204 */
1205 // Checks if the user is logged in
1206 if( $this->loggedin ) {
1207 // Checks if the user is watching this page
1208 if( !$this->mTitle->userIsWatching() ) {
1209 // Adds watch action link
1210 $links['actions']['watch'] = array(
1211 'class' =>
1212 ( $action == 'watch' or $action == 'unwatch' ) ?
1213 'selected' : false,
1214 'text' => wfMsg( 'watch' ),
1215 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
1216 );
1217 } else {
1218 // Adds unwatch action link
1219 $links['actions']['unwatch'] = array(
1220 'class' =>
1221 ($action == 'unwatch' or $action == 'watch') ?
1222 'selected' : false,
1223 'text' => wfMsg( 'unwatch' ),
1224 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
1225 );
1226 }
1227 }
1228
1229 // This is instead of SkinTemplateTabs - which uses a flat array
1230 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$links ) );
1231
1232 // If it's not content, it's got to be a special page
1233 } else {
1234 $links['namespaces']['special'] = array(
1235 'class' => 'selected',
1236 'text' => wfMsg( 'vector-namespace-special' ),
1237 'href' => $wgRequest->getRequestURL()
1238 );
1239 }
1240
1241 // Gets list of language variants
1242 $variants = $wgContLang->getVariants();
1243 // Checks that language conversion is enabled and variants exist
1244 if( !$wgDisableLangConversion && count( $variants ) > 1 ) {
1245 // Gets preferred variant
1246 $preferred = $wgContLang->getPreferredVariant();
1247 // Loops over each variant
1248 foreach( $variants as $code ) {
1249 // Gets variant name from language code
1250 $varname = $wgContLang->getVariantname( $code );
1251 // Checks if the variant is marked as disabled
1252 if( $varname == 'disable' ) {
1253 // Skips this variant
1254 continue;
1255 }
1256 // Appends variant link
1257 $links['variants'][] = array(
1258 'class' => ( $code == $preferred ) ? 'selected' : false,
1259 'text' => $varname,
1260 'href' => $this->mTitle->getLocalURL( '', $code )
1261 );
1262 }
1263 }
1264
1265 wfProfileOut( __METHOD__ );
1266
1267 return $links;
1268 }
1269
1270 /**
1271 * Generate strings used for xml 'id' names
1272 * @return string
1273 * @private
1274 */
1275 function getNameSpaceKey() {
1276 return $this->mTitle->getNamespaceKey();
1277 }
1278
1279 /**
1280 * @private
1281 */
1282 function setupUserJs( $allowUserJs ) {
1283 global $wgRequest, $wgJsMimeType;
1284
1285 wfProfileIn( __METHOD__ );
1286
1287 $action = $wgRequest->getVal( 'action', 'view' );
1288
1289 if( $allowUserJs && $this->loggedin ) {
1290 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
1291 # XXX: additional security check/prompt?
1292 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1293 } else {
1294 $this->userjs = self::makeUrl( $this->userpage . '/' . $this->skinname . '.js', 'action=raw&ctype=' . $wgJsMimeType );
1295 }
1296 }
1297 wfProfileOut( __METHOD__ );
1298 }
1299
1300 /**
1301 * Code for extensions to hook into to provide per-page CSS, see
1302 * extensions/PageCSS/PageCSS.php for an implementation of this.
1303 *
1304 * @private
1305 */
1306 function setupPageCss() {
1307 wfProfileIn( __METHOD__ );
1308 $out = false;
1309 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1310 wfProfileOut( __METHOD__ );
1311 return $out;
1312 }
1313
1314 public function commonPrintStylesheet() {
1315 return false;
1316 }
1317 }
1318
1319 /**
1320 * Generic wrapper for template functions, with interface
1321 * compatible with what we use of PHPTAL 0.7.
1322 * @ingroup Skins
1323 */
1324 class QuickTemplate {
1325 /**
1326 * Constructor
1327 */
1328 public function QuickTemplate() {
1329 $this->data = array();
1330 $this->translator = new MediaWiki_I18N();
1331 }
1332
1333 /**
1334 * Sets the value $value to $name
1335 * @param $name
1336 * @param $value
1337 */
1338 public function set( $name, $value ) {
1339 $this->data[$name] = $value;
1340 }
1341
1342 /**
1343 * @param $name
1344 * @param $value
1345 */
1346 public function setRef( $name, &$value ) {
1347 $this->data[$name] =& $value;
1348 }
1349
1350 /**
1351 * @param $t
1352 */
1353 public function setTranslator( &$t ) {
1354 $this->translator = &$t;
1355 }
1356
1357 /**
1358 * Main function, used by classes that subclass QuickTemplate
1359 * to show the actual HTML output
1360 */
1361 public function execute() {
1362 echo 'Override this function.';
1363 }
1364
1365 /**
1366 * @private
1367 */
1368 function text( $str ) {
1369 echo htmlspecialchars( $this->data[$str] );
1370 }
1371
1372 /**
1373 * @private
1374 */
1375 function jstext( $str ) {
1376 echo Xml::escapeJsString( $this->data[$str] );
1377 }
1378
1379 /**
1380 * @private
1381 */
1382 function html( $str ) {
1383 echo $this->data[$str];
1384 }
1385
1386 /**
1387 * @private
1388 */
1389 function msg( $str ) {
1390 echo htmlspecialchars( $this->translator->translate( $str ) );
1391 }
1392
1393 /**
1394 * @private
1395 */
1396 function msgHtml( $str ) {
1397 echo $this->translator->translate( $str );
1398 }
1399
1400 /**
1401 * An ugly, ugly hack.
1402 * @private
1403 */
1404 function msgWiki( $str ) {
1405 global $wgParser, $wgOut;
1406
1407 $text = $this->translator->translate( $str );
1408 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1409 $wgOut->parserOptions(), true );
1410 echo $parserOutput->getText();
1411 }
1412
1413 /**
1414 * @private
1415 */
1416 function haveData( $str ) {
1417 return isset( $this->data[$str] );
1418 }
1419
1420 /**
1421 * @private
1422 */
1423 function haveMsg( $str ) {
1424 $msg = $this->translator->translate( $str );
1425 return ( $msg != '-' ) && ( $msg != '' ); # ????
1426 }
1427 }