(bug 6100; follow-up to r91315) Being bold and removing $wgBetterDirectionality ...
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 /**
3 * Base class for template-based skins
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 * @file
21 */
22
23 if ( !defined( 'MEDIAWIKI' ) ) {
24 die( 1 );
25 }
26
27 /**
28 * Wrapper object for MediaWiki's localization functions,
29 * to be passed to the template engine.
30 *
31 * @private
32 * @ingroup Skins
33 */
34 class MediaWiki_I18N {
35 var $_context = array();
36
37 function set( $varName, $value ) {
38 $this->_context[$varName] = $value;
39 }
40
41 function translate( $value ) {
42 wfProfileIn( __METHOD__ );
43
44 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
45 $value = preg_replace( '/^string:/', '', $value );
46
47 $value = wfMsg( $value );
48 // interpolate variables
49 $m = array();
50 while( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
51 list( $src, $var ) = $m;
52 wfSuppressWarnings();
53 $varValue = $this->_context[$var];
54 wfRestoreWarnings();
55 $value = str_replace( $src, $varValue, $value );
56 }
57 wfProfileOut( __METHOD__ );
58 return $value;
59 }
60 }
61
62 /**
63 * Template-filler skin base class
64 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
65 * Based on Brion's smarty skin
66 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
67 *
68 * @todo Needs some serious refactoring into functions that correspond
69 * to the computations individual esi snippets need. Most importantly no body
70 * parsing for most of those of course.
71 *
72 * @ingroup Skins
73 */
74 class SkinTemplate extends Skin {
75 /**#@+
76 * @private
77 */
78
79 /**
80 * Name of our skin, it probably needs to be all lower case. Child classes
81 * should override the default.
82 */
83 var $skinname = 'monobook';
84
85 /**
86 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
87 * are located. Child classes should override the default.
88 */
89 var $stylename = 'monobook';
90
91 /**
92 * For QuickTemplate, the name of the subclass which will actually fill the
93 * template. Child classes should override the default.
94 */
95 var $template = 'QuickTemplate';
96
97 /**
98 * Whether this skin use OutputPage::headElement() to generate the <head>
99 * tag
100 */
101 var $useHeadElement = false;
102
103 /**#@-*/
104
105 /**
106 * Add specific styles for this skin
107 *
108 * @param $out OutputPage
109 */
110 function setupSkinUserCss( OutputPage $out ){
111 $out->addModuleStyles( array( 'mediawiki.legacy.shared', 'mediawiki.legacy.commonPrint' ) );
112 }
113
114 /**
115 * Create the template engine object; we feed it a bunch of data
116 * and eventually it spits out some HTML. Should have interface
117 * roughly equivalent to PHPTAL 0.7.
118 *
119 * @param $classname String
120 * @param $repository string: subdirectory where we keep template files
121 * @param $cache_dir string
122 * @return QuickTemplate
123 * @private
124 */
125 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
126 return new $classname();
127 }
128
129 /**
130 * initialize various variables and generate the template
131 *
132 * @param $out OutputPage
133 */
134 function outputPage( OutputPage $out ) {
135 global $wgUser, $wgLang, $wgContLang;
136 global $wgScript, $wgStylePath, $wgLanguageCode;
137 global $wgMimeType, $wgJsMimeType, $wgRequest;
138 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
139 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
143 global $wgArticlePath, $wgScriptPath, $wgServer;
144
145 wfProfileIn( __METHOD__ );
146 Profiler::instance()->setTemplated( true );
147
148 $oldid = $wgRequest->getVal( 'oldid' );
149 $diff = $wgRequest->getVal( 'diff' );
150 $action = $wgRequest->getVal( 'action', 'view' );
151
152 wfProfileIn( __METHOD__ . '-init' );
153 $this->initPage( $out );
154
155 $tpl = $this->setupTemplate( $this->template, 'skins' );
156 wfProfileOut( __METHOD__ . '-init' );
157
158 wfProfileIn( __METHOD__ . '-stuff' );
159 $this->thispage = $this->getTitle()->getPrefixedDBkey();
160 $this->thisurl = $this->getTitle()->getPrefixedURL();
161 $query = array();
162 if ( !$wgRequest->wasPosted() ) {
163 $query = $wgRequest->getValues();
164 unset( $query['title'] );
165 unset( $query['returnto'] );
166 unset( $query['returntoquery'] );
167 }
168 $this->thisquery = wfUrlencode( wfArrayToCGI( $query ) );
169 $this->loggedin = $wgUser->isLoggedIn();
170 $this->iscontent = ( $this->getTitle()->getNamespace() != NS_SPECIAL );
171 $this->iseditable = ( $this->iscontent and !( $action == 'edit' or $action == 'submit' ) );
172 $this->username = $wgUser->getName();
173
174 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
175 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
176 } else {
177 # This won't be used in the standard skins, but we define it to preserve the interface
178 # To save time, we check for existence
179 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
180 }
181
182 $this->titletxt = $this->getTitle()->getPrefixedText();
183 wfProfileOut( __METHOD__ . '-stuff' );
184
185 wfProfileIn( __METHOD__ . '-stuff-head' );
186 if ( $this->useHeadElement ) {
187 $pagecss = $this->setupPageCss();
188 if( $pagecss )
189 $out->addInlineStyle( $pagecss );
190 } else {
191 $this->setupUserCss( $out );
192
193 $tpl->set( 'pagecss', $this->setupPageCss() );
194 $tpl->set( 'usercss', false );
195
196 $this->userjs = $this->userjsprev = false;
197 # @todo FIXME: This is the only use of OutputPage::isUserJsAllowed() anywhere; can we
198 # get rid of it? For that matter, why is any of this here at all?
199 $this->setupUserJs( $out->isUserJsAllowed() );
200 $tpl->setRef( 'userjs', $this->userjs );
201 $tpl->setRef( 'userjsprev', $this->userjsprev );
202
203 if( $wgUseSiteJs ) {
204 $jsCache = $this->loggedin ? '&smaxage=0' : '';
205 $tpl->set( 'jsvarurl',
206 self::makeUrl( '-',
207 "action=raw$jsCache&gen=js&useskin=" .
208 urlencode( $this->getSkinName() ) ) );
209 } else {
210 $tpl->set( 'jsvarurl', false );
211 }
212
213 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
214 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
215 $tpl->set( 'html5version', $wgHtml5Version );
216 $tpl->set( 'headlinks', $out->getHeadLinks( $this ) );
217 $tpl->set( 'csslinks', $out->buildCssLinks( $this ) );
218
219 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
220 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
221 } else {
222 $tpl->set( 'trackbackhtml', null );
223 }
224 }
225 wfProfileOut( __METHOD__ . '-stuff-head' );
226
227 wfProfileIn( __METHOD__ . '-stuff2' );
228 $tpl->set( 'title', $out->getPageTitle() );
229 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
230 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
231 $tpl->set( 'pageclass', $this->getPageClasses( $this->getTitle() ) );
232 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
233
234 $nsname = MWNamespace::exists( $this->getTitle()->getNamespace() ) ?
235 MWNamespace::getCanonicalName( $this->getTitle()->getNamespace() ) :
236 $this->getTitle()->getNsText();
237
238 $tpl->set( 'nscanonical', $nsname );
239 $tpl->set( 'nsnumber', $this->getTitle()->getNamespace() );
240 $tpl->set( 'titleprefixeddbkey', $this->getTitle()->getPrefixedDBKey() );
241 $tpl->set( 'titletext', $this->getTitle()->getText() );
242 $tpl->set( 'articleid', $this->getTitle()->getArticleId() );
243 $tpl->set( 'currevisionid', $this->getTitle()->getLatestRevID() );
244
245 $tpl->set( 'isarticle', $out->isArticle() );
246
247 $tpl->setRef( 'thispage', $this->thispage );
248 $subpagestr = $this->subPageSubtitle();
249 $tpl->set(
250 'subtitle', !empty( $subpagestr ) ?
251 '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() :
252 $out->getSubtitle()
253 );
254 $undelete = $this->getUndeleteLink();
255 $tpl->set(
256 'undelete', !empty( $undelete ) ?
257 '<span class="subpages">' . $undelete . '</span>' :
258 ''
259 );
260
261 $tpl->set( 'catlinks', $this->getCategories() );
262 if( $out->isSyndicated() ) {
263 $feeds = array();
264 foreach( $out->getSyndicationLinks() as $format => $link ) {
265 $feeds[$format] = array(
266 'text' => wfMsg( "feed-$format" ),
267 'href' => $link
268 );
269 }
270 $tpl->setRef( 'feeds', $feeds );
271 } else {
272 $tpl->set( 'feeds', false );
273 }
274
275 $tpl->setRef( 'mimetype', $wgMimeType );
276 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
277 $tpl->set( 'charset', 'UTF-8' );
278 $tpl->setRef( 'wgScript', $wgScript );
279 $tpl->setRef( 'skinname', $this->skinname );
280 $tpl->set( 'skinclass', get_class( $this ) );
281 $tpl->setRef( 'stylename', $this->stylename );
282 $tpl->set( 'printable', $out->isPrintable() );
283 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
284 $tpl->setRef( 'loggedin', $this->loggedin );
285 $tpl->set( 'notspecialpage', $this->getTitle()->getNamespace() != NS_SPECIAL );
286 /* XXX currently unused, might get useful later
287 $tpl->set( 'editable', ( $this->getTitle()->getNamespace() != NS_SPECIAL ) );
288 $tpl->set( 'exists', $this->getTitle()->getArticleID() != 0 );
289 $tpl->set( 'watch', $this->getTitle()->userIsWatching() ? 'unwatch' : 'watch' );
290 $tpl->set( 'protect', count( $this->getTitle()->isProtected() ) ? 'unprotect' : 'protect' );
291 $tpl->set( 'helppage', wfMsg( 'helppage' ) );
292 */
293 $tpl->set( 'searchaction', $this->escapeSearchLink() );
294 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBKey() );
295 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
296 $tpl->setRef( 'stylepath', $wgStylePath );
297 $tpl->setRef( 'articlepath', $wgArticlePath );
298 $tpl->setRef( 'scriptpath', $wgScriptPath );
299 $tpl->setRef( 'serverurl', $wgServer );
300 $tpl->setRef( 'logopath', $wgLogo );
301
302 $contentlang = $wgContLang->getCode();
303 $contentdir = $wgContLang->getDir();
304 $userlang = $wgLang->getCode();
305 $userdir = $wgLang->getDir();
306
307 $tpl->set( 'lang', $userlang );
308 $tpl->set( 'dir', $userdir );
309 $tpl->set( 'rtl', $wgLang->isRTL() );
310
311 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
312 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
313 $tpl->set( 'username', $wgUser->isAnon() ? null : $this->username );
314 $tpl->setRef( 'userpage', $this->userpage );
315 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
316 $tpl->set( 'userlang', $userlang );
317
318 // Users can have their language set differently than the
319 // content of the wiki. For these users, tell the web browser
320 // that interface elements are in a different language.
321 $tpl->set( 'userlangattributes', '' );
322 $tpl->set( 'specialpageattributes', '' ); # obsolete
323
324 if ( $userlang !== $contentlang || $userdir !== $contentdir ) {
325 $attrs = " lang='$userlang' dir='$userdir'";
326 $tpl->set( 'userlangattributes', $attrs );
327 }
328
329 $newtalks = $this->getNewtalks( $out );
330
331 wfProfileOut( __METHOD__ . '-stuff2' );
332
333 wfProfileIn( __METHOD__ . '-stuff3' );
334 $tpl->setRef( 'newtalk', $newtalks );
335 $tpl->setRef( 'skin', $this );
336 $tpl->set( 'logo', $this->logoText() );
337 if ( $out->isArticle() && ( !isset( $oldid ) || isset( $diff ) ) &&
338 $this->getTitle()->exists() )
339 {
340 $article = new Article( $this->getTitle(), 0 );
341 if ( !$wgDisableCounters ) {
342 $viewcount = $wgLang->formatNum( $article->getCount() );
343 if ( $viewcount ) {
344 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
345 } else {
346 $tpl->set( 'viewcount', false );
347 }
348 } else {
349 $tpl->set( 'viewcount', false );
350 }
351
352 if( $wgPageShowWatchingUsers ) {
353 $dbr = wfGetDB( DB_SLAVE );
354 $res = $dbr->select( 'watchlist',
355 array( 'COUNT(*) AS n' ),
356 array( 'wl_title' => $dbr->strencode( $this->getTitle()->getDBkey() ), 'wl_namespace' => $this->getTitle()->getNamespace() ),
357 __METHOD__
358 );
359 $x = $dbr->fetchObject( $res );
360 $numberofwatchingusers = $x->n;
361 if( $numberofwatchingusers > 0 ) {
362 $tpl->set( 'numberofwatchingusers',
363 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
364 $wgLang->formatNum( $numberofwatchingusers ) )
365 );
366 } else {
367 $tpl->set( 'numberofwatchingusers', false );
368 }
369 } else {
370 $tpl->set( 'numberofwatchingusers', false );
371 }
372
373 $tpl->set( 'copyright', $this->getCopyright() );
374
375 $this->credits = false;
376
377 if( $wgMaxCredits != 0 ){
378 $this->credits = Action::factory( 'credits', $article )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax );
379 } else {
380 $tpl->set( 'lastmod', $this->lastModified( $article ) );
381 }
382
383 $tpl->setRef( 'credits', $this->credits );
384
385 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
386 $tpl->set( 'copyright', $this->getCopyright() );
387 $tpl->set( 'viewcount', false );
388 $tpl->set( 'lastmod', false );
389 $tpl->set( 'credits', false );
390 $tpl->set( 'numberofwatchingusers', false );
391 } else {
392 $tpl->set( 'copyright', false );
393 $tpl->set( 'viewcount', false );
394 $tpl->set( 'lastmod', false );
395 $tpl->set( 'credits', false );
396 $tpl->set( 'numberofwatchingusers', false );
397 }
398 wfProfileOut( __METHOD__ . '-stuff3' );
399
400 wfProfileIn( __METHOD__ . '-stuff4' );
401 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
402 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
403 $tpl->set( 'disclaimer', $this->disclaimerLink() );
404 $tpl->set( 'privacy', $this->privacyLink() );
405 $tpl->set( 'about', $this->aboutLink() );
406
407 $tpl->set( 'footerlinks', array(
408 'info' => array(
409 'lastmod',
410 'viewcount',
411 'numberofwatchingusers',
412 'credits',
413 'copyright',
414 ),
415 'places' => array(
416 'privacy',
417 'about',
418 'disclaimer',
419 ),
420 ) );
421
422 global $wgFooterIcons;
423 $tpl->set( 'footericons', $wgFooterIcons );
424 foreach ( $tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
425 if ( count( $footerIconsBlock ) > 0 ) {
426 foreach ( $footerIconsBlock as &$footerIcon ) {
427 if ( isset( $footerIcon['src'] ) ) {
428 if ( !isset( $footerIcon['width'] ) ) {
429 $footerIcon['width'] = 88;
430 }
431 if ( !isset( $footerIcon['height'] ) ) {
432 $footerIcon['height'] = 31;
433 }
434 }
435 }
436 } else {
437 unset( $tpl->data['footericons'][$footerIconsKey] );
438 }
439 }
440
441 if ( $wgDebugComments ) {
442 $tpl->setRef( 'debug', $out->mDebugtext );
443 } else {
444 $tpl->set( 'debug', '' );
445 }
446
447 $tpl->set( 'reporttime', wfReportTime() );
448 $tpl->set( 'sitenotice', $this->getSiteNotice() );
449 $tpl->set( 'bottomscripts', $this->bottomScripts( $out ) );
450 $tpl->set( 'printfooter', $this->printSource() );
451
452 # Add a <div class="mw-content-ltr/rtl"> around the body text
453 # not for special pages or file pages AND only when viewing AND if the page exists
454 # (or is in MW namespace, because that has default content)
455 if( !in_array( $this->getTitle()->getNamespace(), array( NS_SPECIAL, NS_FILE ) ) &&
456 in_array( $action, array( 'view', 'render', 'print' ) ) &&
457 ( $this->getTitle()->exists() || $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) ) {
458 $pageLang = $this->getTitle()->getPageLanguage();
459 $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
460 'class' => 'mw-content-'.$pageLang->getDir() );
461 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
462 }
463
464 $tpl->setRef( 'bodytext', $out->mBodytext );
465
466 # Language links
467 $language_urls = array();
468
469 if ( !$wgHideInterlanguageLinks ) {
470 foreach( $out->getLanguageLinks() as $l ) {
471 $tmp = explode( ':', $l, 2 );
472 $class = 'interwiki-' . $tmp[0];
473 unset( $tmp );
474 $nt = Title::newFromText( $l );
475 if ( $nt ) {
476 $language_urls[] = array(
477 'href' => $nt->getFullURL(),
478 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
479 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
480 'title' => $nt->getText(),
481 'class' => $class
482 );
483 }
484 }
485 }
486 if( count( $language_urls ) ) {
487 $tpl->setRef( 'language_urls', $language_urls );
488 } else {
489 $tpl->set( 'language_urls', false );
490 }
491 wfProfileOut( __METHOD__ . '-stuff4' );
492
493 wfProfileIn( __METHOD__ . '-stuff5' );
494 # Personal toolbar
495 $tpl->set( 'personal_urls', $this->buildPersonalUrls( $out ) );
496 $content_navigation = $this->buildContentNavigationUrls( $out );
497 $content_actions = $this->buildContentActionUrls( $content_navigation );
498 $tpl->setRef( 'content_navigation', $content_navigation );
499 $tpl->setRef( 'content_actions', $content_actions );
500
501 $tpl->set( 'sidebar', $this->buildSidebar() );
502 $tpl->set( 'nav_urls', $this->buildNavUrls( $out ) );
503
504 // Set the head scripts near the end, in case the above actions resulted in added scripts
505 if ( $this->useHeadElement ) {
506 $tpl->set( 'headelement', $out->headElement( $this ) );
507 } else {
508 $tpl->set( 'headscripts', $out->getScript() );
509 }
510
511 $tpl->set( 'debughtml', $this->generateDebugHTML() );
512
513 // original version by hansm
514 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
515 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
516 }
517
518 // allow extensions adding stuff after the page content.
519 // See Skin::afterContentHook() for further documentation.
520 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
521 wfProfileOut( __METHOD__ . '-stuff5' );
522
523 // execute template
524 wfProfileIn( __METHOD__ . '-execute' );
525 $res = $tpl->execute();
526 wfProfileOut( __METHOD__ . '-execute' );
527
528 // result may be an error
529 $this->printOrError( $res );
530 wfProfileOut( __METHOD__ );
531 }
532
533 /**
534 * Output the string, or print error message if it's
535 * an error object of the appropriate type.
536 * For the base class, assume strings all around.
537 *
538 * @param $str Mixed
539 * @private
540 */
541 function printOrError( $str ) {
542 echo $str;
543 }
544
545 /**
546 * Output a boolean indiciating if buildPersonalUrls should output separate
547 * login and create account links or output a combined link
548 * By default we simply return a global config setting that affects most skins
549 * This is setup as a method so that like with $wgLogo and getLogo() a skin
550 * can override this setting and always output one or the other if it has
551 * a reason it can't output one of the two modes.
552 */
553 function useCombinedLoginLink() {
554 global $wgUseCombinedLoginLink;
555 return $wgUseCombinedLoginLink;
556 }
557
558 /**
559 * build array of urls for personal toolbar
560 * @return array
561 */
562 protected function buildPersonalUrls( OutputPage $out ) {
563 global $wgRequest;
564
565 $title = $out->getTitle();
566 $pageurl = $title->getLocalURL();
567 wfProfileIn( __METHOD__ );
568
569 /* set up the default links for the personal toolbar */
570 $personal_urls = array();
571
572 // Get the returnto and returntoquery parameters from the query string
573 // or fall back on $this->thisurl or $this->thisquery
574 // We can't use getVal()'s default value feature here because
575 // stuff from $wgRequest needs to be escaped, but thisurl and thisquery
576 // are already escaped.
577 $page = $wgRequest->getVal( 'returnto' );
578 if ( !is_null( $page ) ) {
579 $page = wfUrlencode( $page );
580 } else {
581 $page = $this->thisurl;
582 }
583 $query = $wgRequest->getVal( 'returntoquery' );
584 if ( !is_null( $query ) ) {
585 $query = wfUrlencode( $query );
586 } else {
587 $query = $this->thisquery;
588 }
589 $returnto = "returnto=$page";
590 if( $query != '' ) {
591 $returnto .= "&returntoquery=$query";
592 }
593 if( $this->loggedin ) {
594 $personal_urls['userpage'] = array(
595 'text' => $this->username,
596 'href' => &$this->userpageUrlDetails['href'],
597 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
598 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
599 );
600 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
601 $personal_urls['mytalk'] = array(
602 'text' => wfMsg( 'mytalk' ),
603 'href' => &$usertalkUrlDetails['href'],
604 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
605 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
606 );
607 $href = self::makeSpecialUrl( 'Preferences' );
608 $personal_urls['preferences'] = array(
609 'text' => wfMsg( 'mypreferences' ),
610 'href' => $href,
611 'active' => ( $href == $pageurl )
612 );
613 $href = self::makeSpecialUrl( 'Watchlist' );
614 $personal_urls['watchlist'] = array(
615 'text' => wfMsg( 'mywatchlist' ),
616 'href' => $href,
617 'active' => ( $href == $pageurl )
618 );
619
620 # We need to do an explicit check for Special:Contributions, as we
621 # have to match both the title, and the target (which could come
622 # from request values or be specified in "sub page" form. The plot
623 # thickens, because $wgTitle is altered for special pages, so doesn't
624 # contain the original alias-with-subpage.
625 $origTitle = Title::newFromText( $wgRequest->getText( 'title' ) );
626 if( $origTitle instanceof Title && $origTitle->getNamespace() == NS_SPECIAL ) {
627 list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() );
628 $active = $spName == 'Contributions'
629 && ( ( $spPar && $spPar == $this->username )
630 || $wgRequest->getText( 'target' ) == $this->username );
631 } else {
632 $active = false;
633 }
634
635 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
636 $personal_urls['mycontris'] = array(
637 'text' => wfMsg( 'mycontris' ),
638 'href' => $href,
639 'active' => $active
640 );
641 $personal_urls['logout'] = array(
642 'text' => wfMsg( 'userlogout' ),
643 'href' => self::makeSpecialUrl( 'Userlogout',
644 // userlogout link must always contain an & character, otherwise we might not be able
645 // to detect a buggy precaching proxy (bug 17790)
646 $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto
647 ),
648 'active' => false
649 );
650 } else {
651 global $wgUser;
652 $useCombinedLoginLink = $this->useCombinedLoginLink();
653 $loginlink = $wgUser->isAllowed( 'createaccount' ) && $useCombinedLoginLink
654 ? 'nav-login-createaccount'
655 : 'login';
656 $is_signup = $wgRequest->getText('type') == "signup";
657
658 # anonlogin & login are the same
659 $login_url = array(
660 'text' => wfMsg( $loginlink ),
661 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
662 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" || !$is_signup )
663 );
664 if ( $wgUser->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
665 $createaccount_url = array(
666 'text' => wfMsg( 'createaccount' ),
667 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
668 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
669 );
670 }
671 global $wgServer, $wgSecureLogin;
672 if( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) {
673 $title = SpecialPage::getTitleFor( 'Userlogin' );
674 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
675 $login_url['href'] = $https_url;
676 # @todo FIXME: Class depends on skin
677 $login_url['class'] = 'link-https';
678 if ( isset($createaccount_url) ) {
679 $https_url = preg_replace( '/^http:/', 'https:',
680 $title->getFullURL("type=signup") );
681 $createaccount_url['href'] = $https_url;
682 # @todo FIXME: Class depends on skin
683 $createaccount_url['class'] = 'link-https';
684 }
685 }
686
687
688 if( $this->showIPinHeader() ) {
689 $href = &$this->userpageUrlDetails['href'];
690 $personal_urls['anonuserpage'] = array(
691 'text' => $this->username,
692 'href' => $href,
693 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
694 'active' => ( $pageurl == $href )
695 );
696 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
697 $href = &$usertalkUrlDetails['href'];
698 $personal_urls['anontalk'] = array(
699 'text' => wfMsg( 'anontalk' ),
700 'href' => $href,
701 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
702 'active' => ( $pageurl == $href )
703 );
704 $personal_urls['anonlogin'] = $login_url;
705 } else {
706 $personal_urls['login'] = $login_url;
707 }
708 if ( isset($createaccount_url) ) {
709 $personal_urls['createaccount'] = $createaccount_url;
710 }
711 }
712
713 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
714 wfProfileOut( __METHOD__ );
715 return $personal_urls;
716 }
717
718 /**
719 * TODO document
720 * @param $title Title
721 * @param $message String message key
722 * @param $selected Bool
723 * @param $query String
724 * @param $checkEdit Bool
725 * @return array
726 */
727 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
728 $classes = array();
729 if( $selected ) {
730 $classes[] = 'selected';
731 }
732 if( $checkEdit && !$title->isKnown() ) {
733 $classes[] = 'new';
734 $query = 'action=edit&redlink=1';
735 }
736
737 // wfMessageFallback will nicely accept $message as an array of fallbacks
738 // or just a single key
739 $msg = wfMessageFallback( $message );
740 if ( is_array($message) ) {
741 // for hook compatibility just keep the last message name
742 $message = end($message);
743 }
744 if ( $msg->exists() ) {
745 $text = $msg->text();
746 } else {
747 global $wgContLang;
748 $text = $wgContLang->getFormattedNsText(
749 MWNamespace::getSubject( $title->getNamespace() ) );
750 }
751
752 $result = array();
753 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
754 $title, $message, $selected, $checkEdit,
755 &$classes, &$query, &$text, &$result ) ) ) {
756 return $result;
757 }
758
759 return array(
760 'class' => implode( ' ', $classes ),
761 'text' => $text,
762 'href' => $title->getLocalUrl( $query ),
763 'primary' => true );
764 }
765
766 function makeTalkUrlDetails( $name, $urlaction = '' ) {
767 $title = Title::newFromText( $name );
768 if( !is_object( $title ) ) {
769 throw new MWException( __METHOD__ . " given invalid pagename $name" );
770 }
771 $title = $title->getTalkPage();
772 self::checkTitle( $title, $name );
773 return array(
774 'href' => $title->getLocalURL( $urlaction ),
775 'exists' => $title->getArticleID() != 0,
776 );
777 }
778
779 function makeArticleUrlDetails( $name, $urlaction = '' ) {
780 $title = Title::newFromText( $name );
781 $title= $title->getSubjectPage();
782 self::checkTitle( $title, $name );
783 return array(
784 'href' => $title->getLocalURL( $urlaction ),
785 'exists' => $title->getArticleID() != 0,
786 );
787 }
788
789 /**
790 * a structured array of links usually used for the tabs in a skin
791 *
792 * There are 4 standard sections
793 * namespaces: Used for namespace tabs like special, page, and talk namespaces
794 * views: Used for primary page views like read, edit, history
795 * actions: Used for most extra page actions like deletion, protection, etc...
796 * variants: Used to list the language variants for the page
797 *
798 * Each section's value is a key/value array of links for that section.
799 * The links themseves have these common keys:
800 * - class: The css classes to apply to the tab
801 * - text: The text to display on the tab
802 * - href: The href for the tab to point to
803 * - rel: An optional rel= for the tab's link
804 * - redundant: If true the tab will be dropped in skins using content_actions
805 * this is useful for tabs like "Read" which only have meaning in skins that
806 * take special meaning from the grouped structure of content_navigation
807 *
808 * Views also have an extra key which can be used:
809 * - primary: If this is not true skins like vector may try to hide the tab
810 * when the user has limited space in their browser window
811 *
812 * content_navigation using code also expects these ids to be present on the
813 * links, however these are usually automatically generated by SkinTemplate
814 * itself and are not necessary when using a hook. The only things these may
815 * matter to are people modifying content_navigation after it's initial creation:
816 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
817 * - tooltiponly: This is set to true for some tabs in cases where the system
818 * believes that the accesskey should not be added to the tab.
819 *
820 * @return array
821 */
822 protected function buildContentNavigationUrls( OutputPage $out ) {
823 global $wgContLang, $wgLang, $wgUser, $wgRequest;
824 global $wgDisableLangConversion;
825
826 wfProfileIn( __METHOD__ );
827
828 $title = $this->getRelevantTitle(); // Display tabs for the relevant title rather than always the title itself
829 $onPage = $title->equals($this->getTitle());
830
831 $content_navigation = array(
832 'namespaces' => array(),
833 'views' => array(),
834 'actions' => array(),
835 'variants' => array()
836 );
837
838 // parameters
839 $action = $wgRequest->getVal( 'action', 'view' );
840 $section = $wgRequest->getVal( 'section' );
841
842 $userCanRead = $title->userCanRead();
843 $skname = $this->skinname;
844
845 $preventActiveTabs = false;
846 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
847
848 // Checks if page is some kind of content
849 if( $title->getNamespace() != NS_SPECIAL ) {
850 // Gets page objects for the related namespaces
851 $subjectPage = $title->getSubjectPage();
852 $talkPage = $title->getTalkPage();
853
854 // Determines if this is a talk page
855 $isTalk = $title->isTalkPage();
856
857 // Generates XML IDs from namespace names
858 $subjectId = $title->getNamespaceKey( '' );
859
860 if ( $subjectId == 'main' ) {
861 $talkId = 'talk';
862 } else {
863 $talkId = "{$subjectId}_talk";
864 }
865
866 // Adds namespace links
867 $subjectMsg = array( "nstab-$subjectId" );
868 if ( $subjectPage->isMainPage() ) {
869 array_unshift($subjectMsg, 'mainpage-nstab');
870 }
871 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
872 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
873 );
874 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
875 $content_navigation['namespaces'][$talkId] = $this->tabAction(
876 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
877 );
878 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
879
880 // Adds view view link
881 if ( $title->exists() && $userCanRead ) {
882 $content_navigation['views']['view'] = $this->tabAction(
883 $isTalk ? $talkPage : $subjectPage,
884 array( "$skname-view-view", 'view' ),
885 ( $onPage && ($action == 'view' || $action == 'purge' ) ), '', true
886 );
887 $content_navigation['views']['view']['redundant'] = true; // signal to hide this from simple content_actions
888 }
889
890 wfProfileIn( __METHOD__ . '-edit' );
891
892 // Checks if user can...
893 if (
894 // read and edit the current page
895 $userCanRead && $title->quickUserCan( 'edit' ) &&
896 (
897 // if it exists
898 $title->exists() ||
899 // or they can create one here
900 $title->quickUserCan( 'create' )
901 )
902 ) {
903 // Builds CSS class for talk page links
904 $isTalkClass = $isTalk ? ' istalk' : '';
905
906 // Determines if we're in edit mode
907 $selected = (
908 $onPage &&
909 ( $action == 'edit' || $action == 'submit' ) &&
910 ( $section != 'new' )
911 );
912 $msgKey = $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDefaultMessageText() !== false ) ?
913 "edit" : "create";
914 $content_navigation['views']['edit'] = array(
915 'class' => ( $selected ? 'selected' : '' ) . $isTalkClass,
916 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->text(),
917 'href' => $title->getLocalURL( $this->editUrlOptions() ),
918 'primary' => true, // don't collapse this in vector
919 );
920 // Checks if this is a current rev of talk page and we should show a new
921 // section link
922 if ( ( $isTalk && $this->isRevisionCurrent() ) || ( $out->showNewSectionLink() ) ) {
923 // Checks if we should ever show a new section link
924 if ( !$out->forceHideNewSectionLink() ) {
925 // Adds new section link
926 //$content_navigation['actions']['addsection']
927 $content_navigation['views']['addsection'] = array(
928 'class' => $section == 'new' ? 'selected' : false,
929 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->text(),
930 'href' => $title->getLocalURL( 'action=edit&section=new' )
931 );
932 }
933 }
934 // Checks if the page has some kind of viewable content
935 } elseif ( $title->hasSourceText() && $userCanRead ) {
936 // Adds view source view link
937 $content_navigation['views']['viewsource'] = array(
938 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
939 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->text(),
940 'href' => $title->getLocalURL( $this->editUrlOptions() ),
941 'primary' => true, // don't collapse this in vector
942 );
943 }
944 wfProfileOut( __METHOD__ . '-edit' );
945
946 wfProfileIn( __METHOD__ . '-live' );
947
948 // Checks if the page exists
949 if ( $title->exists() && $userCanRead ) {
950 // Adds history view link
951 $content_navigation['views']['history'] = array(
952 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
953 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->text(),
954 'href' => $title->getLocalURL( 'action=history' ),
955 'rel' => 'archives',
956 );
957
958 if( $wgUser->isAllowed( 'delete' ) ) {
959 $content_navigation['actions']['delete'] = array(
960 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
961 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->text(),
962 'href' => $title->getLocalURL( 'action=delete' )
963 );
964 }
965 if ( $title->quickUserCan( 'move' ) ) {
966 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
967 $content_navigation['actions']['move'] = array(
968 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
969 'text' => wfMessageFallback( "$skname-action-move", 'move' )->text(),
970 'href' => $moveTitle->getLocalURL()
971 );
972 }
973
974 if ( $title->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
975 $mode = !$title->isProtected() ? 'protect' : 'unprotect';
976 $content_navigation['actions'][$mode] = array(
977 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
978 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
979 'href' => $title->getLocalURL( "action=$mode" )
980 );
981 }
982 } else {
983 // article doesn't exist or is deleted
984 if ( $wgUser->isAllowed( 'deletedhistory' ) ) {
985 $n = $title->isDeleted();
986 if( $n ) {
987 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
988 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
989 $msgKey = $wgUser->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
990 $content_navigation['actions']['undelete'] = array(
991 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
992 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
993 ->params( $wgLang->formatNum( $n ) )->text(),
994 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
995 );
996 }
997 }
998
999 if ( $title->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
1000 $mode = !$title->getRestrictions( 'create' ) ? 'protect' : 'unprotect';
1001 $content_navigation['actions'][$mode] = array(
1002 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
1003 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
1004 'href' => $title->getLocalURL( "action=$mode" )
1005 );
1006 }
1007 }
1008 wfProfileOut( __METHOD__ . '-live' );
1009
1010 // Checks if the user is logged in
1011 if ( $this->loggedin ) {
1012 /**
1013 * The following actions use messages which, if made particular to
1014 * the any specific skins, would break the Ajax code which makes this
1015 * action happen entirely inline. Skin::makeGlobalVariablesScript
1016 * defines a set of messages in a javascript object - and these
1017 * messages are assumed to be global for all skins. Without making
1018 * a change to that procedure these messages will have to remain as
1019 * the global versions.
1020 */
1021 $mode = $title->userIsWatching() ? 'unwatch' : 'watch';
1022 $token = WatchAction::getWatchToken( $title, $wgUser, $mode );
1023 $content_navigation['actions'][$mode] = array(
1024 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
1025 'text' => wfMsg( $mode ), // uses 'watch' or 'unwatch' message
1026 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1027 );
1028 }
1029
1030 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1031 } else {
1032 // If it's not content, it's got to be a special page
1033 $content_navigation['namespaces']['special'] = array(
1034 'class' => 'selected',
1035 'text' => wfMsg( 'nstab-special' ),
1036 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
1037 'context' => 'subject'
1038 );
1039
1040 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1041 array( &$this, &$content_navigation ) );
1042 }
1043
1044 // Gets list of language variants
1045 $variants = $wgContLang->getVariants();
1046 // Checks that language conversion is enabled and variants exist
1047 if( !$wgDisableLangConversion && count( $variants ) > 1 ) {
1048 // Gets preferred variant
1049 $preferred = $wgContLang->getPreferredVariant();
1050 // Loops over each variant
1051 foreach( $variants as $code ) {
1052 // Gets variant name from language code
1053 $varname = $wgContLang->getVariantname( $code );
1054 // Checks if the variant is marked as disabled
1055 if( $varname == 'disable' ) {
1056 // Skips this variant
1057 continue;
1058 }
1059 // Appends variant link
1060 $content_navigation['variants'][] = array(
1061 'class' => ( $code == $preferred ) ? 'selected' : false,
1062 'text' => $varname,
1063 'href' => $title->getLocalURL( '', $code )
1064 );
1065 }
1066 }
1067
1068 // Equiv to SkinTemplateContentActions
1069 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1070
1071 // Setup xml ids and tooltip info
1072 foreach ( $content_navigation as $section => &$links ) {
1073 foreach ( $links as $key => &$link ) {
1074 $xmlID = $key;
1075 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1076 $xmlID = 'ca-nstab-' . $xmlID;
1077 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1078 $xmlID = 'ca-talk';
1079 } elseif ( $section == "variants" ) {
1080 $xmlID = 'ca-varlang-' . $xmlID;
1081 } else {
1082 $xmlID = 'ca-' . $xmlID;
1083 }
1084 $link['id'] = $xmlID;
1085 }
1086 }
1087
1088 # We don't want to give the watch tab an accesskey if the
1089 # page is being edited, because that conflicts with the
1090 # accesskey on the watch checkbox. We also don't want to
1091 # give the edit tab an accesskey, because that's fairly su-
1092 # perfluous and conflicts with an accesskey (Ctrl-E) often
1093 # used for editing in Safari.
1094 if( in_array( $action, array( 'edit', 'submit' ) ) ) {
1095 if ( isset($content_navigation['views']['edit']) ) {
1096 $content_navigation['views']['edit']['tooltiponly'] = true;
1097 }
1098 if ( isset($content_navigation['actions']['watch']) ) {
1099 $content_navigation['actions']['watch']['tooltiponly'] = true;
1100 }
1101 if ( isset($content_navigation['actions']['unwatch']) ) {
1102 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1103 }
1104 }
1105
1106 wfProfileOut( __METHOD__ );
1107
1108 return $content_navigation;
1109 }
1110
1111 /**
1112 * an array of edit links by default used for the tabs
1113 * @return array
1114 * @private
1115 */
1116 function buildContentActionUrls( $content_navigation ) {
1117
1118 wfProfileIn( __METHOD__ );
1119
1120 // content_actions has been replaced with content_navigation for backwards
1121 // compatibility and also for skins that just want simple tabs content_actions
1122 // is now built by flattening the content_navigation arrays into one
1123
1124 $content_actions = array();
1125
1126 foreach ( $content_navigation as $links ) {
1127
1128 foreach ( $links as $key => $value ) {
1129
1130 if ( isset($value["redundant"]) && $value["redundant"] ) {
1131 // Redundant tabs are dropped from content_actions
1132 continue;
1133 }
1134
1135 // content_actions used to have ids built using the "ca-$key" pattern
1136 // so the xmlID based id is much closer to the actual $key that we want
1137 // for that reason we'll just strip out the ca- if present and use
1138 // the latter potion of the "id" as the $key
1139 if ( isset($value["id"]) && substr($value["id"], 0, 3) == "ca-" ) {
1140 $key = substr($value["id"], 3);
1141 }
1142
1143 if ( isset($content_actions[$key]) ) {
1144 wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1145 continue;
1146 }
1147
1148 $content_actions[$key] = $value;
1149
1150 }
1151
1152 }
1153
1154 wfProfileOut( __METHOD__ );
1155
1156 return $content_actions;
1157 }
1158
1159 /**
1160 * build array of common navigation links
1161 * @return array
1162 * @private
1163 */
1164 protected function buildNavUrls( OutputPage $out ) {
1165 global $wgUseTrackbacks, $wgUser, $wgRequest;
1166 global $wgUploadNavigationUrl;
1167
1168 wfProfileIn( __METHOD__ );
1169
1170 $action = $wgRequest->getVal( 'action', 'view' );
1171
1172 $nav_urls = array();
1173 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
1174 if( $wgUploadNavigationUrl ) {
1175 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1176 } elseif( UploadBase::isEnabled() && UploadBase::isAllowed( $wgUser ) === true ) {
1177 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
1178 } else {
1179 $nav_urls['upload'] = false;
1180 }
1181 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
1182
1183 // default permalink to being off, will override it as required below.
1184 $nav_urls['permalink'] = false;
1185
1186 // A print stylesheet is attached to all pages, but nobody ever
1187 // figures that out. :) Add a link...
1188 if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
1189 if ( !$out->isPrintable() ) {
1190 $nav_urls['print'] = array(
1191 'text' => wfMsg( 'printableversion' ),
1192 'href' => $this->getTitle()->getLocalURL(
1193 $wgRequest->appendQueryValue( 'printable', 'yes', true ) )
1194 );
1195 }
1196
1197 // Also add a "permalink" while we're at it
1198 $revid = $this->getRevisionId();
1199 if ( $revid ) {
1200 $nav_urls['permalink'] = array(
1201 'text' => wfMsg( 'permalink' ),
1202 'href' => $out->getTitle()->getLocalURL( "oldid=$revid" )
1203 );
1204 }
1205
1206 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1207 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1208 array( &$this, &$nav_urls, &$revid, &$revid ) );
1209 }
1210
1211 if( $this->getTitle()->getNamespace() != NS_SPECIAL ) {
1212 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
1213 $nav_urls['whatlinkshere'] = array(
1214 'href' => $wlhTitle->getLocalUrl()
1215 );
1216 if( $this->getTitle()->getArticleId() ) {
1217 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
1218 $nav_urls['recentchangeslinked'] = array(
1219 'href' => $rclTitle->getLocalUrl()
1220 );
1221 } else {
1222 $nav_urls['recentchangeslinked'] = false;
1223 }
1224 if( $wgUseTrackbacks )
1225 $nav_urls['trackbacklink'] = array(
1226 'href' => $out->getTitle()->trackbackURL()
1227 );
1228 }
1229
1230 $user = $this->getRelevantUser();
1231 if ( $user ) {
1232 $id = $user->getID();
1233 $ip = $user->isAnon();
1234 $rootUser = $user->getName();
1235 } else {
1236 $id = 0;
1237 $ip = false;
1238 $rootUser = null;
1239 }
1240
1241 if( $id || $ip ) { # both anons and non-anons have contribs list
1242 $nav_urls['contributions'] = array(
1243 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1244 );
1245
1246 if( $id ) {
1247 $logPage = SpecialPage::getTitleFor( 'Log' );
1248 $nav_urls['log'] = array(
1249 'href' => $logPage->getLocalUrl(
1250 array(
1251 'user' => $rootUser
1252 )
1253 )
1254 );
1255 } else {
1256 $nav_urls['log'] = false;
1257 }
1258
1259 if ( $wgUser->isAllowed( 'block' ) ) {
1260 $nav_urls['blockip'] = array(
1261 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
1262 );
1263 } else {
1264 $nav_urls['blockip'] = false;
1265 }
1266 } else {
1267 $nav_urls['contributions'] = false;
1268 $nav_urls['log'] = false;
1269 $nav_urls['blockip'] = false;
1270 }
1271 $nav_urls['emailuser'] = false;
1272 if( $this->showEmailUser( $id ) ) {
1273 $nav_urls['emailuser'] = array(
1274 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1275 );
1276 }
1277 wfProfileOut( __METHOD__ );
1278 return $nav_urls;
1279 }
1280
1281 /**
1282 * Generate strings used for xml 'id' names
1283 * @return string
1284 * @private
1285 */
1286 function getNameSpaceKey() {
1287 return $this->getTitle()->getNamespaceKey();
1288 }
1289
1290 /**
1291 * @private
1292 * @todo FIXME: Why is this duplicated in/from OutputPage::getHeadScripts()??
1293 */
1294 function setupUserJs( $allowUserJs ) {
1295 global $wgRequest, $wgJsMimeType;
1296 wfProfileIn( __METHOD__ );
1297
1298 $action = $wgRequest->getVal( 'action', 'view' );
1299
1300 if( $allowUserJs && $this->loggedin ) {
1301 if( $this->getTitle()->isJsSubpage() and $this->userCanPreview( $action ) ) {
1302 # XXX: additional security check/prompt?
1303 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1304 } else {
1305 $this->userjs = self::makeUrl( $this->userpage . '/' . $this->skinname . '.js', 'action=raw&ctype=' . $wgJsMimeType );
1306 }
1307 }
1308 wfProfileOut( __METHOD__ );
1309 }
1310
1311 /**
1312 * Code for extensions to hook into to provide per-page CSS, see
1313 * extensions/PageCSS/PageCSS.php for an implementation of this.
1314 *
1315 * @private
1316 */
1317 function setupPageCss() {
1318 wfProfileIn( __METHOD__ );
1319 $out = false;
1320 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1321 wfProfileOut( __METHOD__ );
1322 return $out;
1323 }
1324
1325 public function commonPrintStylesheet() {
1326 return false;
1327 }
1328 }
1329
1330 /**
1331 * Generic wrapper for template functions, with interface
1332 * compatible with what we use of PHPTAL 0.7.
1333 * @ingroup Skins
1334 */
1335 abstract class QuickTemplate {
1336 /**
1337 * Constructor
1338 */
1339 public function QuickTemplate() {
1340 $this->data = array();
1341 $this->translator = new MediaWiki_I18N();
1342 }
1343
1344 /**
1345 * Sets the value $value to $name
1346 * @param $name
1347 * @param $value
1348 */
1349 public function set( $name, $value ) {
1350 $this->data[$name] = $value;
1351 }
1352
1353 /**
1354 * @param $name
1355 * @param $value
1356 */
1357 public function setRef( $name, &$value ) {
1358 $this->data[$name] =& $value;
1359 }
1360
1361 /**
1362 * @param $t
1363 */
1364 public function setTranslator( &$t ) {
1365 $this->translator = &$t;
1366 }
1367
1368 /**
1369 * Main function, used by classes that subclass QuickTemplate
1370 * to show the actual HTML output
1371 */
1372 abstract public function execute();
1373
1374 /**
1375 * @private
1376 */
1377 function text( $str ) {
1378 echo htmlspecialchars( $this->data[$str] );
1379 }
1380
1381 /**
1382 * @private
1383 */
1384 function jstext( $str ) {
1385 echo Xml::escapeJsString( $this->data[$str] );
1386 }
1387
1388 /**
1389 * @private
1390 */
1391 function html( $str ) {
1392 echo $this->data[$str];
1393 }
1394
1395 /**
1396 * @private
1397 */
1398 function msg( $str ) {
1399 echo htmlspecialchars( $this->translator->translate( $str ) );
1400 }
1401
1402 /**
1403 * @private
1404 */
1405 function msgHtml( $str ) {
1406 echo $this->translator->translate( $str );
1407 }
1408
1409 /**
1410 * An ugly, ugly hack.
1411 * @private
1412 */
1413 function msgWiki( $str ) {
1414 global $wgParser, $wgOut;
1415
1416 $text = $this->translator->translate( $str );
1417 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1418 $wgOut->parserOptions(), true );
1419 echo $parserOutput->getText();
1420 }
1421
1422 /**
1423 * @private
1424 */
1425 function haveData( $str ) {
1426 return isset( $this->data[$str] );
1427 }
1428
1429 /**
1430 * @private
1431 *
1432 * @return bool
1433 */
1434 function haveMsg( $str ) {
1435 $msg = $this->translator->translate( $str );
1436 return ( $msg != '-' ) && ( $msg != '' ); # ????
1437 }
1438
1439 /**
1440 * Get the Skin object related to this object
1441 *
1442 * @return Skin object
1443 */
1444 public function getSkin() {
1445 return $this->data['skin'];
1446 }
1447 }
1448
1449 /**
1450 * New base template for a skin's template extended from QuickTemplate
1451 * this class features helper methods that provide common ways of interacting
1452 * with the data stored in the QuickTemplate
1453 */
1454 abstract class BaseTemplate extends QuickTemplate {
1455
1456 /**
1457 * Create an array of common toolbox items from the data in the quicktemplate
1458 * stored by SkinTemplate.
1459 * The resulting array is built acording to a format intended to be passed
1460 * through makeListItem to generate the html.
1461 */
1462 function getToolbox() {
1463 wfProfileIn( __METHOD__ );
1464
1465 $toolbox = array();
1466 if ( $this->data['notspecialpage'] ) {
1467 $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
1468 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1469 if ( $this->data['nav_urls']['recentchangeslinked'] ) {
1470 $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
1471 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1472 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1473 }
1474 }
1475 if( isset( $this->data['nav_urls']['trackbacklink'] ) && $this->data['nav_urls']['trackbacklink'] ) {
1476 $toolbox['trackbacklink'] = $this->data['nav_urls']['trackbacklink'];
1477 $toolbox['trackbacklink']['id'] = 't-trackbacklink';
1478 }
1479 if ( $this->data['feeds'] ) {
1480 $toolbox['feeds']['id'] = 'feedlinks';
1481 $toolbox['feeds']['links'] = array();
1482 foreach ( $this->data['feeds'] as $key => $feed ) {
1483 $toolbox['feeds']['links'][$key] = $feed;
1484 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1485 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1486 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1487 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1488 }
1489 }
1490 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1491 if ( $this->data['nav_urls'][$special] ) {
1492 $toolbox[$special] = $this->data['nav_urls'][$special];
1493 $toolbox[$special]['id'] = "t-$special";
1494 }
1495 }
1496 if ( !empty( $this->data['nav_urls']['print']['href'] ) ) {
1497 $toolbox['print'] = $this->data['nav_urls']['print'];
1498 $toolbox['print']['rel'] = 'alternate';
1499 $toolbox['print']['msg'] = 'printableversion';
1500 }
1501 if( $this->data['nav_urls']['permalink'] ) {
1502 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
1503 if( $toolbox['permalink']['href'] === '' ) {
1504 unset( $toolbox['permalink']['href'] );
1505 $toolbox['ispermalink']['tooltiponly'] = true;
1506 $toolbox['ispermalink']['id'] = 't-ispermalink';
1507 $toolbox['ispermalink']['msg'] = 'permalink';
1508 } else {
1509 $toolbox['permalink']['id'] = 't-permalink';
1510 }
1511 }
1512 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1513 wfProfileOut( __METHOD__ );
1514 return $toolbox;
1515 }
1516
1517 /**
1518 * Create an array of personal tools items from the data in the quicktemplate
1519 * stored by SkinTemplate.
1520 * The resulting array is built acording to a format intended to be passed
1521 * through makeListItem to generate the html.
1522 * This is in reality the same list as already stored in personal_urls
1523 * however it is reformatted so that you can just pass the individual items
1524 * to makeListItem instead of hardcoding the element creation boilerplate.
1525 */
1526 function getPersonalTools() {
1527 $personal_tools = array();
1528 foreach( $this->data['personal_urls'] as $key => $ptool ) {
1529 # The class on a personal_urls item is meant to go on the <a> instead
1530 # of the <li> so we have to use a single item "links" array instead
1531 # of using most of the personal_url's keys directly
1532 $personal_tools[$key] = array();
1533 $personal_tools[$key]["links"][] = array();
1534 $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key";
1535 if ( isset($ptool["active"]) ) {
1536 $personal_tools[$key]["active"] = $ptool["active"];
1537 }
1538 foreach ( array("href", "class", "text") as $k ) {
1539 if ( isset($ptool[$k]) )
1540 $personal_tools[$key]["links"][0][$k] = $ptool[$k];
1541 }
1542 }
1543 return $personal_tools;
1544 }
1545
1546 /**
1547 * Makes a link, usually used by makeListItem to generate a link for an item
1548 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1549 *
1550 * $key is a string, usually a key from the list you are generating this link from
1551 * $item is an array containing some of a specific set of keys.
1552 * The text of the link will be generated either from the contents of the "text"
1553 * key in the $item array, if a "msg" key is present a message by that name will
1554 * be used, and if neither of those are set the $key will be used as a message name.
1555 * If a "href" key is not present makeLink will just output htmlescaped text.
1556 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1557 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1558 * is present it will be used to generate a tooltip and accesskey for the link.
1559 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1560 */
1561 function makeLink( $key, $item ) {
1562 if ( isset( $item['text'] ) ) {
1563 $text = $item['text'];
1564 } else {
1565 $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key );
1566 }
1567
1568 if ( !isset( $item['href'] ) ) {
1569 return htmlspecialchars( $text );
1570 }
1571
1572 $attrs = array();
1573 foreach ( array( 'href', 'id', 'class', 'rel', 'type', 'target') as $attr ) {
1574 if ( isset( $item[$attr] ) ) {
1575 $attrs[$attr] = $item[$attr];
1576 }
1577 }
1578
1579 if ( isset( $item['id'] ) ) {
1580 $item['single-id'] = $item['id'];
1581 }
1582 if ( isset( $item['single-id'] ) ) {
1583 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1584 $attrs['title'] = $this->skin->titleAttrib( $item['single-id'] );
1585 if ( $attrs['title'] === false ) {
1586 unset( $attrs['title'] );
1587 }
1588 } else {
1589 $attrs = array_merge(
1590 $attrs,
1591 Linker::tooltipAndAccesskeyAttribs( $item['single-id'] )
1592 );
1593 }
1594 }
1595
1596 return Html::element( 'a', $attrs, $text );
1597 }
1598
1599 /**
1600 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1601 * $key is a string, usually a key from the list you are generating this link from
1602 * $item is an array of list item data containing some of a specific set of keys.
1603 * The "id" and "class" keys will be used as attributes for the list item,
1604 * if "active" contains a value of true a "active" class will also be appended to class.
1605 * If you want something other than a <li> you can pass a tag name such as
1606 * "tag" => "span" in the $options array to change the tag used.
1607 * link/content data for the list item may come in one of two forms
1608 * A "links" key may be used, in which case it should contain an array with
1609 * a list of links to include inside the list item, see makeLink for the format
1610 * of individual links array items.
1611 * Otherwise the relevant keys from the list item $item array will be passed
1612 * to makeLink instead. Note however that "id" and "class" are used by the
1613 * list item directly so they will not be passed to makeLink
1614 * (however the link will still support a tooltip and accesskey from it)
1615 * If you need an id or class on a single link you should include a "links"
1616 * array with just one link item inside of it.
1617 */
1618 function makeListItem( $key, $item, $options = array() ) {
1619 if ( isset( $item['links'] ) ) {
1620 $html = '';
1621 foreach ( $item['links'] as $linkKey => $link ) {
1622 $html .= $this->makeLink( $linkKey, $link );
1623 }
1624 } else {
1625 $link = array();
1626 foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly', 'target' ) as $k ) {
1627 if ( isset( $item[$k] ) ) {
1628 $link[$k] = $item[$k];
1629 }
1630 }
1631 if ( isset( $item['id'] ) ) {
1632 // The id goes on the <li> not on the <a> for single links
1633 // but makeSidebarLink still needs to know what id to use when
1634 // generating tooltips and accesskeys.
1635 $link['single-id'] = $item['id'];
1636 }
1637 $html = $this->makeLink( $key, $link );
1638 }
1639
1640 $attrs = array();
1641 foreach ( array( 'id', 'class' ) as $attr ) {
1642 if ( isset( $item[$attr] ) ) {
1643 $attrs[$attr] = $item[$attr];
1644 }
1645 }
1646 if ( isset( $item['active'] ) && $item['active'] ) {
1647 if ( !isset( $attrs['class'] ) ) {
1648 $attrs['class'] = '';
1649 }
1650 $attrs['class'] .= ' active';
1651 $attrs['class'] = trim( $attrs['class'] );
1652 }
1653 return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
1654 }
1655
1656 function makeSearchInput( $attrs = array() ) {
1657 $realAttrs = array(
1658 'type' => 'search',
1659 'name' => 'search',
1660 'value' => isset( $this->data['search'] ) ? $this->data['search'] : '',
1661 );
1662 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1663 return Html::element( 'input', $realAttrs );
1664 }
1665
1666 function makeSearchButton( $mode, $attrs = array() ) {
1667 switch( $mode ) {
1668 case 'go':
1669 case 'fulltext':
1670 $realAttrs = array(
1671 'type' => 'submit',
1672 'name' => $mode,
1673 'value' => $this->translator->translate(
1674 $mode == 'go' ? 'searcharticle' : 'searchbutton' ),
1675 );
1676 $realAttrs = array_merge(
1677 $realAttrs,
1678 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
1679 $attrs
1680 );
1681 return Html::element( 'input', $realAttrs );
1682 case 'image':
1683 $buttonAttrs = array(
1684 'type' => 'submit',
1685 'name' => 'button',
1686 );
1687 $buttonAttrs = array_merge(
1688 $buttonAttrs,
1689 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1690 $attrs
1691 );
1692 unset( $buttonAttrs['src'] );
1693 unset( $buttonAttrs['alt'] );
1694 $imgAttrs = array(
1695 'src' => $attrs['src'],
1696 'alt' => isset( $attrs['alt'] )
1697 ? $attrs['alt']
1698 : $this->translator->translate( 'searchbutton' ),
1699 );
1700 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
1701 default:
1702 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1703 }
1704 }
1705
1706 /**
1707 * Returns an array of footerlinks trimmed down to only those footer links that
1708 * are valid.
1709 * If you pass "flat" as an option then the returned array will be a flat array
1710 * of footer icons instead of a key/value array of footerlinks arrays broken
1711 * up into categories.
1712 */
1713 function getFooterLinks( $option = null ) {
1714 $footerlinks = $this->data['footerlinks'];
1715
1716 // Reduce footer links down to only those which are being used
1717 $validFooterLinks = array();
1718 foreach( $footerlinks as $category => $links ) {
1719 $validFooterLinks[$category] = array();
1720 foreach( $links as $link ) {
1721 if( isset( $this->data[$link] ) && $this->data[$link] ) {
1722 $validFooterLinks[$category][] = $link;
1723 }
1724 }
1725 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1726 unset( $validFooterLinks[$category] );
1727 }
1728 }
1729
1730 if ( $option == 'flat' ) {
1731 // fold footerlinks into a single array using a bit of trickery
1732 $validFooterLinks = call_user_func_array(
1733 'array_merge',
1734 array_values( $validFooterLinks )
1735 );
1736 }
1737
1738 return $validFooterLinks;
1739 }
1740
1741 /**
1742 * Returns an array of footer icons filtered down by options relevant to how
1743 * the skin wishes to display them.
1744 * If you pass "icononly" as the option all footer icons which do not have an
1745 * image icon set will be filtered out.
1746 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1747 * in the list of footer icons. This is mostly useful for skins which only
1748 * display the text from footericons instead of the images and don't want a
1749 * duplicate copyright statement because footerlinks already rendered one.
1750 */
1751 function getFooterIcons( $option = null ) {
1752 // Generate additional footer icons
1753 $footericons = $this->data['footericons'];
1754
1755 if ( $option == 'icononly' ) {
1756 // Unset any icons which don't have an image
1757 foreach ( $footericons as &$footerIconsBlock ) {
1758 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1759 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1760 unset( $footerIconsBlock[$footerIconKey] );
1761 }
1762 }
1763 }
1764 // Redo removal of any empty blocks
1765 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1766 if ( count( $footerIconsBlock ) <= 0 ) {
1767 unset( $footericons[$footerIconsKey] );
1768 }
1769 }
1770 } elseif ( $option == 'nocopyright' ) {
1771 unset( $footericons['copyright']['copyright'] );
1772 if ( count( $footericons['copyright'] ) <= 0 ) {
1773 unset( $footericons['copyright'] );
1774 }
1775 }
1776
1777 return $footericons;
1778 }
1779
1780 /**
1781 * Output the basic end-page trail including bottomscripts, reporttime, and
1782 * debug stuff. This should be called right before outputting the closing
1783 * body and html tags.
1784 */
1785 function printTrail() { ?>
1786 <?php $this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?>
1787 <?php $this->html('reporttime') ?>
1788 <?php if ( $this->data['debug'] ): ?>
1789 <!-- Debug output:
1790 <?php $this->text( 'debug' ); ?>
1791
1792 -->
1793 <?php endif;
1794 }
1795
1796 }
1797