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