Don't add empty title attributes to anchor links
[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 }
229 $tpl->setRef( 'feeds', $feeds );
230 } else {
231 $tpl->set( 'feeds', false );
232 }
233 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
234 $tpl->set( 'trackbackhtml', $wgTitle->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( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
274 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
275 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
276 $tpl->setRef( 'userpage', $this->userpage );
277 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
278 $tpl->set( 'userlang', $wgLang->getCode() );
279 $tpl->set( 'pagecss', $this->setupPageCss() );
280 $tpl->setRef( 'usercss', $this->usercss );
281 $tpl->setRef( 'userjs', $this->userjs );
282 $tpl->setRef( 'userjsprev', $this->userjsprev );
283 if( $wgUseSiteJs ) {
284 $jsCache = $this->loggedin ? '&smaxage=0' : '';
285 $tpl->set( 'jsvarurl',
286 self::makeUrl( '-',
287 "action=raw$jsCache&gen=js&useskin=" .
288 urlencode( $this->getSkinName() ) ) );
289 } else {
290 $tpl->set( 'jsvarurl', false );
291 }
292 $newtalks = $wgUser->getNewMessageLinks();
293
294 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
295 $usertitle = $this->mUser->getUserPage();
296 $usertalktitle = $usertitle->getTalkPage();
297 if( !$usertalktitle->equals( $this->mTitle ) ) {
298 $ntl = wfMsg( 'youhavenewmessages',
299 $this->makeKnownLinkObj(
300 $usertalktitle,
301 wfMsgHtml( 'newmessageslink' ),
302 'redirect=no'
303 ),
304 $this->makeKnownLinkObj(
305 $usertalktitle,
306 wfMsgHtml( 'newmessagesdifflink' ),
307 'diff=cur'
308 )
309 );
310 # Disable Cache
311 $out->setSquidMaxage( 0 );
312 }
313 } else if( count( $newtalks ) ) {
314 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
315 $msgs = array();
316 foreach( $newtalks as $newtalk ) {
317 $msgs[] = Xml::element('a',
318 array( 'href' => $newtalk['link'] ), $newtalk['wiki'] );
319 }
320 $parts = implode( $sep, $msgs );
321 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
322 $out->setSquidMaxage( 0 );
323 } else {
324 $ntl = '';
325 }
326 wfProfileOut( __METHOD__ . '-stuff2' );
327
328 wfProfileIn( __METHOD__ . '-stuff3' );
329 $tpl->setRef( 'newtalk', $ntl );
330 $tpl->setRef( 'skin', $this );
331 $tpl->set( 'logo', $this->logoText() );
332 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
333 $wgArticle and 0 != $wgArticle->getID() ){
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 $res = $dbr->select( 'watchlist',
349 array( 'COUNT(*) AS n' ),
350 array( 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ), 'wl_namespace' => $this->mTitle->getNamespace() ),
351 __METHOD__
352 );
353 $x = $dbr->fetchObject( $res );
354 $numberofwatchingusers = $x->n;
355 if( $numberofwatchingusers > 0 ) {
356 $tpl->set( 'numberofwatchingusers',
357 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
358 $wgLang->formatNum( $numberofwatchingusers ) )
359 );
360 } else {
361 $tpl->set( 'numberofwatchingusers', false );
362 }
363 } else {
364 $tpl->set( 'numberofwatchingusers', false );
365 }
366
367 $tpl->set( 'copyright', $this->getCopyright() );
368
369 $this->credits = false;
370
371 if( $wgMaxCredits != 0 ){
372 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
373 } else {
374 $tpl->set( 'lastmod', $this->lastModified() );
375 }
376
377 $tpl->setRef( 'credits', $this->credits );
378
379 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
380 $tpl->set( 'copyright', $this->getCopyright() );
381 $tpl->set( 'viewcount', false );
382 $tpl->set( 'lastmod', false );
383 $tpl->set( 'credits', false );
384 $tpl->set( 'numberofwatchingusers', false );
385 } else {
386 $tpl->set( 'copyright', false );
387 $tpl->set( 'viewcount', false );
388 $tpl->set( 'lastmod', false );
389 $tpl->set( 'credits', false );
390 $tpl->set( 'numberofwatchingusers', false );
391 }
392 wfProfileOut( __METHOD__ . '-stuff3' );
393
394 wfProfileIn( __METHOD__ . '-stuff4' );
395 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
396 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
397 $tpl->set( 'disclaimer', $this->disclaimerLink() );
398 $tpl->set( 'privacy', $this->privacyLink() );
399 $tpl->set( 'about', $this->aboutLink() );
400
401 $tpl->setRef( 'debug', $out->mDebugtext );
402 $tpl->set( 'reporttime', wfReportTime() );
403 $tpl->set( 'sitenotice', wfGetSiteNotice() );
404 $tpl->set( 'bottomscripts', $this->bottomScripts() );
405
406 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
407 $out->mBodytext .= $printfooter . $this->generateDebugHTML();
408 $tpl->setRef( 'bodytext', $out->mBodytext );
409
410 # Language links
411 $language_urls = array();
412
413 if ( !$wgHideInterlanguageLinks ) {
414 foreach( $out->getLanguageLinks() as $l ) {
415 $tmp = explode( ':', $l, 2 );
416 $class = 'interwiki-' . $tmp[0];
417 unset( $tmp );
418 $nt = Title::newFromText( $l );
419 if ( $nt ) {
420 $language_urls[] = array(
421 'href' => $nt->getFullURL(),
422 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
423 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
424 'class' => $class
425 );
426 }
427 }
428 }
429 if( count( $language_urls ) ) {
430 $tpl->setRef( 'language_urls', $language_urls );
431 } else {
432 $tpl->set( 'language_urls', false );
433 }
434 wfProfileOut( __METHOD__ . '-stuff4' );
435
436 wfProfileIn( __METHOD__ . '-stuff5' );
437 # Personal toolbar
438 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
439 $content_actions = $this->buildContentActionUrls();
440 $tpl->setRef( 'content_actions', $content_actions );
441
442 // XXX: attach this from javascript, same with section editing
443 if( $this->iseditable && $wgUser->getOption( 'editondblclick' ) ){
444 $encEditUrl = Xml::escapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
445 $tpl->set( 'body_ondblclick', 'document.location = "' . $encEditUrl . '";' );
446 } else {
447 $tpl->set( 'body_ondblclick', false );
448 }
449 $tpl->set( 'body_onload', false );
450 $tpl->set( 'sidebar', $this->buildSidebar() );
451 $tpl->set( 'nav_urls', $this->buildNavUrls() );
452
453 // original version by hansm
454 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
455 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
456 }
457
458 // allow extensions adding stuff after the page content.
459 // See Skin::afterContentHook() for further documentation.
460 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
461 wfProfileOut( __METHOD__ . '-stuff5' );
462
463 // execute template
464 wfProfileIn( __METHOD__ . '-execute' );
465 $res = $tpl->execute();
466 wfProfileOut( __METHOD__ . '-execute' );
467
468 // result may be an error
469 $this->printOrError( $res );
470 wfProfileOut( __METHOD__ );
471 }
472
473 /**
474 * Output the string, or print error message if it's
475 * an error object of the appropriate type.
476 * For the base class, assume strings all around.
477 *
478 * @param mixed $str
479 * @private
480 */
481 function printOrError( $str ) {
482 echo $str;
483 }
484
485 /**
486 * build array of urls for personal toolbar
487 * @return array
488 * @private
489 */
490 function buildPersonalUrls() {
491 global $wgTitle, $wgRequest;
492
493 $pageurl = $wgTitle->getLocalURL();
494 wfProfileIn( __METHOD__ );
495
496 /* set up the default links for the personal toolbar */
497 $personal_urls = array();
498 if( $this->loggedin ) {
499 $personal_urls['userpage'] = array(
500 'text' => $this->username,
501 'href' => &$this->userpageUrlDetails['href'],
502 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
503 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
504 );
505 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
506 $personal_urls['mytalk'] = array(
507 'text' => wfMsg( 'mytalk' ),
508 'href' => &$usertalkUrlDetails['href'],
509 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
510 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
511 );
512 $href = self::makeSpecialUrl( 'Preferences' );
513 $personal_urls['preferences'] = array(
514 'text' => wfMsg( 'mypreferences' ),
515 'href' => $href,
516 'active' => ( $href == $pageurl )
517 );
518 $href = self::makeSpecialUrl( 'Watchlist' );
519 $personal_urls['watchlist'] = array(
520 'text' => wfMsg( 'mywatchlist' ),
521 'href' => $href,
522 'active' => ( $href == $pageurl )
523 );
524
525 # We need to do an explicit check for Special:Contributions, as we
526 # have to match both the title, and the target (which could come
527 # from request values or be specified in "sub page" form. The plot
528 # thickens, because $wgTitle is altered for special pages, so doesn't
529 # contain the original alias-with-subpage.
530 $title = Title::newFromText( $wgRequest->getText( 'title' ) );
531 if( $title instanceof Title && $title->getNamespace() == NS_SPECIAL ) {
532 list( $spName, $spPar ) =
533 SpecialPage::resolveAliasWithSubpage( $title->getText() );
534 $active = $spName == 'Contributions'
535 && ( ( $spPar && $spPar == $this->username )
536 || $wgRequest->getText( 'target' ) == $this->username );
537 } else {
538 $active = false;
539 }
540
541 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
542 $personal_urls['mycontris'] = array(
543 'text' => wfMsg( 'mycontris' ),
544 'href' => $href,
545 'active' => $active
546 );
547 $personal_urls['logout'] = array(
548 'text' => wfMsg( 'userlogout' ),
549 'href' => self::makeSpecialUrl( 'Userlogout',
550 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
551 ),
552 'active' => false
553 );
554 } else {
555 global $wgUser;
556 $loginlink = $wgUser->isAllowed( 'createaccount' )
557 ? 'nav-login-createaccount'
558 : 'login';
559 if( $this->showIPinHeader() ) {
560 $href = &$this->userpageUrlDetails['href'];
561 $personal_urls['anonuserpage'] = array(
562 'text' => $this->username,
563 'href' => $href,
564 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
565 'active' => ( $pageurl == $href )
566 );
567 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
568 $href = &$usertalkUrlDetails['href'];
569 $personal_urls['anontalk'] = array(
570 'text' => wfMsg( 'anontalk' ),
571 'href' => $href,
572 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
573 'active' => ( $pageurl == $href )
574 );
575 $personal_urls['anonlogin'] = array(
576 'text' => wfMsg( $loginlink ),
577 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
578 'active' => $wgTitle->isSpecial( 'Userlogin' )
579 );
580 } else {
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
675 $content_actions['talk'] = $this->tabAction(
676 $talkpage,
677 'talk',
678 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
679 '',
680 true
681 );
682
683 wfProfileIn( __METHOD__ . '-edit' );
684 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
685 $istalk = $this->mTitle->isTalkPage();
686 $istalkclass = $istalk?' istalk':'';
687 $content_actions['edit'] = array(
688 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ? 'selected' : '' ) . $istalkclass,
689 'text' => $this->mTitle->exists()
690 ? wfMsg( 'edit' )
691 : wfMsg( 'create' ),
692 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
693 );
694
695 if ( $istalk || $wgOut->showNewSectionLink() ) {
696 if ( !$wgOut->forceHideNewSectionLink() ) {
697 $content_actions['addsection'] = array(
698 'class' => $section == 'new' ? 'selected' : false,
699 'text' => wfMsg( 'addsection' ),
700 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
701 );
702 }
703 }
704 } elseif ( $this->mTitle->isKnown() ) {
705 $content_actions['viewsource'] = array(
706 'class' => ($action == 'edit') ? 'selected' : false,
707 'text' => wfMsg( 'viewsource' ),
708 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
709 );
710 }
711 wfProfileOut( __METHOD__ . '-edit' );
712
713 wfProfileIn( __METHOD__ . '-live' );
714 if ( $this->mTitle->exists() ) {
715
716 $content_actions['history'] = array(
717 'class' => ($action == 'history') ? 'selected' : false,
718 'text' => wfMsg( 'history_short' ),
719 'href' => $this->mTitle->getLocalUrl( 'action=history' ),
720 'rel' => 'archives',
721 );
722
723 if( $wgUser->isAllowed( 'delete' ) ) {
724 $content_actions['delete'] = array(
725 'class' => ($action == 'delete') ? 'selected' : false,
726 'text' => wfMsg( 'delete' ),
727 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
728 );
729 }
730 if ( $this->mTitle->quickUserCan( 'move' ) ) {
731 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
732 $content_actions['move'] = array(
733 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
734 'text' => wfMsg( 'move' ),
735 'href' => $moveTitle->getLocalUrl()
736 );
737 }
738
739 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
740 if( !$this->mTitle->isProtected() ){
741 $content_actions['protect'] = array(
742 'class' => ($action == 'protect') ? 'selected' : false,
743 'text' => wfMsg( 'protect' ),
744 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
745 );
746
747 } else {
748 $content_actions['unprotect'] = array(
749 'class' => ($action == 'unprotect') ? 'selected' : false,
750 'text' => wfMsg( 'unprotect' ),
751 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
752 );
753 }
754 }
755 } else {
756 //article doesn't exist or is deleted
757 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
758 if( $n = $this->mTitle->isDeleted() ) {
759 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
760 $content_actions['undelete'] = array(
761 'class' => false,
762 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
763 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
764 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
765 );
766 }
767 }
768
769 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
770 if( !$this->mTitle->getRestrictions( 'create' ) ) {
771 $content_actions['protect'] = array(
772 'class' => ($action == 'protect') ? 'selected' : false,
773 'text' => wfMsg( 'protect' ),
774 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
775 );
776
777 } else {
778 $content_actions['unprotect'] = array(
779 'class' => ($action == 'unprotect') ? 'selected' : false,
780 'text' => wfMsg( 'unprotect' ),
781 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
782 );
783 }
784 }
785 }
786
787 wfProfileOut( __METHOD__ . '-live' );
788
789 if( $this->loggedin ) {
790 if( !$this->mTitle->userIsWatching()) {
791 $content_actions['watch'] = array(
792 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
793 'text' => wfMsg( 'watch' ),
794 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
795 );
796 } else {
797 $content_actions['unwatch'] = array(
798 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
799 'text' => wfMsg( 'unwatch' ),
800 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
801 );
802 }
803 }
804
805
806 wfRunHooks( 'SkinTemplateTabs', array( &$this, &$content_actions ) );
807 } else {
808 /* show special page tab */
809
810 $content_actions[$this->mTitle->getNamespaceKey()] = array(
811 'class' => 'selected',
812 'text' => wfMsg('nstab-special'),
813 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
814 );
815
816 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
817 }
818
819 /* show links to different language variants */
820 global $wgDisableLangConversion;
821 $variants = $wgContLang->getVariants();
822 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
823 $preferred = $wgContLang->getPreferredVariant();
824 $vcount=0;
825 foreach( $variants as $code ) {
826 $varname = $wgContLang->getVariantname( $code );
827 if( $varname == 'disable' )
828 continue;
829 $selected = ( $code == $preferred )? 'selected' : false;
830 $content_actions['varlang-' . $vcount] = array(
831 'class' => $selected,
832 'text' => $varname,
833 'href' => $this->mTitle->getLocalURL( '', $code )
834 );
835 $vcount ++;
836 }
837 }
838
839 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
840
841 wfProfileOut( __METHOD__ );
842 return $content_actions;
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 * Constructor
1013 */
1014 public function QuickTemplate() {
1015 $this->data = array();
1016 $this->translator = new MediaWiki_I18N();
1017 }
1018
1019 /**
1020 * Sets the value $value to $name
1021 * @param $name
1022 * @param $value
1023 */
1024 public function set( $name, $value ) {
1025 $this->data[$name] = $value;
1026 }
1027
1028 /**
1029 * @param $name
1030 * @param $value
1031 */
1032 public function setRef( $name, &$value ) {
1033 $this->data[$name] =& $value;
1034 }
1035
1036 /**
1037 * @param $t
1038 */
1039 public function setTranslator( &$t ) {
1040 $this->translator = &$t;
1041 }
1042
1043 /**
1044 * Main function, used by classes that subclass QuickTemplate
1045 * to show the actual HTML output
1046 */
1047 public function execute() {
1048 echo 'Override this function.';
1049 }
1050
1051 /**
1052 * @private
1053 */
1054 function text( $str ) {
1055 echo htmlspecialchars( $this->data[$str] );
1056 }
1057
1058 /**
1059 * @private
1060 */
1061 function jstext( $str ) {
1062 echo Xml::escapeJsString( $this->data[$str] );
1063 }
1064
1065 /**
1066 * @private
1067 */
1068 function html( $str ) {
1069 echo $this->data[$str];
1070 }
1071
1072 /**
1073 * @private
1074 */
1075 function msg( $str ) {
1076 echo htmlspecialchars( $this->translator->translate( $str ) );
1077 }
1078
1079 /**
1080 * @private
1081 */
1082 function msgHtml( $str ) {
1083 echo $this->translator->translate( $str );
1084 }
1085
1086 /**
1087 * An ugly, ugly hack.
1088 * @private
1089 */
1090 function msgWiki( $str ) {
1091 global $wgParser, $wgTitle, $wgOut;
1092
1093 $text = $this->translator->translate( $str );
1094 $parserOutput = $wgParser->parse( $text, $wgTitle,
1095 $wgOut->parserOptions(), true );
1096 echo $parserOutput->getText();
1097 }
1098
1099 /**
1100 * @private
1101 */
1102 function haveData( $str ) {
1103 return isset( $this->data[$str] );
1104 }
1105
1106 /**
1107 * @private
1108 */
1109 function haveMsg( $str ) {
1110 $msg = $this->translator->translate( $str );
1111 return ( $msg != '-' ) && ( $msg != '' ); # ????
1112 }
1113 }