Removed SkinTemplateSetupPageCss hook and SkinTemplate::setupPageCss(), no extension...
[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;
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 $this->setupUserCss( $out );
188
189 $tpl->set( 'pagecss', false );
190 $tpl->set( 'usercss', false );
191
192 $this->userjs = $this->userjsprev = false;
193 # @todo FIXME: This is the only use of OutputPage::isUserJsAllowed() anywhere; can we
194 # get rid of it? For that matter, why is any of this here at all?
195 $this->setupUserJs( $out->isUserJsAllowed() );
196 $tpl->setRef( 'userjs', $this->userjs );
197 $tpl->setRef( 'userjsprev', $this->userjsprev );
198
199 if( $wgUseSiteJs ) {
200 $jsCache = $this->loggedin ? '&smaxage=0' : '';
201 $tpl->set( 'jsvarurl',
202 self::makeUrl( '-',
203 "action=raw$jsCache&gen=js&useskin=" .
204 urlencode( $this->getSkinName() ) ) );
205 } else {
206 $tpl->set( 'jsvarurl', false );
207 }
208
209 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
210 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
211 $tpl->set( 'html5version', $wgHtml5Version );
212 $tpl->set( 'headlinks', $out->getHeadLinks( $this ) );
213 $tpl->set( 'csslinks', $out->buildCssLinks( $this ) );
214
215 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
216 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
217 } else {
218 $tpl->set( 'trackbackhtml', null );
219 }
220 }
221 wfProfileOut( __METHOD__ . '-stuff-head' );
222
223 wfProfileIn( __METHOD__ . '-stuff2' );
224 $tpl->set( 'title', $out->getPageTitle() );
225 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
226 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
227 $tpl->set( 'pageclass', $this->getPageClasses( $this->getTitle() ) );
228 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
229
230 $nsname = MWNamespace::exists( $this->getTitle()->getNamespace() ) ?
231 MWNamespace::getCanonicalName( $this->getTitle()->getNamespace() ) :
232 $this->getTitle()->getNsText();
233
234 $tpl->set( 'nscanonical', $nsname );
235 $tpl->set( 'nsnumber', $this->getTitle()->getNamespace() );
236 $tpl->set( 'titleprefixeddbkey', $this->getTitle()->getPrefixedDBKey() );
237 $tpl->set( 'titletext', $this->getTitle()->getText() );
238 $tpl->set( 'articleid', $this->getTitle()->getArticleId() );
239 $tpl->set( 'currevisionid', $this->getTitle()->getLatestRevID() );
240
241 $tpl->set( 'isarticle', $out->isArticle() );
242
243 $tpl->setRef( 'thispage', $this->thispage );
244 $subpagestr = $this->subPageSubtitle();
245 $tpl->set(
246 'subtitle', !empty( $subpagestr ) ?
247 '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() :
248 $out->getSubtitle()
249 );
250 $undelete = $this->getUndeleteLink();
251 $tpl->set(
252 'undelete', !empty( $undelete ) ?
253 '<span class="subpages">' . $undelete . '</span>' :
254 ''
255 );
256
257 $tpl->set( 'catlinks', $this->getCategories() );
258 if( $out->isSyndicated() ) {
259 $feeds = array();
260 foreach( $out->getSyndicationLinks() as $format => $link ) {
261 $feeds[$format] = array(
262 'text' => wfMsg( "feed-$format" ),
263 'href' => $link
264 );
265 }
266 $tpl->setRef( 'feeds', $feeds );
267 } else {
268 $tpl->set( 'feeds', false );
269 }
270
271 $tpl->setRef( 'mimetype', $wgMimeType );
272 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
273 $tpl->set( 'charset', 'UTF-8' );
274 $tpl->setRef( 'wgScript', $wgScript );
275 $tpl->setRef( 'skinname', $this->skinname );
276 $tpl->set( 'skinclass', get_class( $this ) );
277 $tpl->setRef( 'stylename', $this->stylename );
278 $tpl->set( 'printable', $out->isPrintable() );
279 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
280 $tpl->setRef( 'loggedin', $this->loggedin );
281 $tpl->set( 'notspecialpage', $this->getTitle()->getNamespace() != NS_SPECIAL );
282 /* XXX currently unused, might get useful later
283 $tpl->set( 'editable', ( $this->getTitle()->getNamespace() != NS_SPECIAL ) );
284 $tpl->set( 'exists', $this->getTitle()->getArticleID() != 0 );
285 $tpl->set( 'watch', $this->getTitle()->userIsWatching() ? 'unwatch' : 'watch' );
286 $tpl->set( 'protect', count( $this->getTitle()->isProtected() ) ? 'unprotect' : 'protect' );
287 $tpl->set( 'helppage', wfMsg( 'helppage' ) );
288 */
289 $tpl->set( 'searchaction', $this->escapeSearchLink() );
290 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBKey() );
291 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
292 $tpl->setRef( 'stylepath', $wgStylePath );
293 $tpl->setRef( 'articlepath', $wgArticlePath );
294 $tpl->setRef( 'scriptpath', $wgScriptPath );
295 $tpl->setRef( 'serverurl', $wgServer );
296 $tpl->setRef( 'logopath', $wgLogo );
297
298 $contentlang = $wgContLang->getCode();
299 $contentdir = $wgContLang->getDir();
300 $userlang = $wgLang->getCode();
301 $userdir = $wgLang->getDir();
302
303 $tpl->set( 'lang', $userlang );
304 $tpl->set( 'dir', $userdir );
305 $tpl->set( 'rtl', $wgLang->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', $userlang );
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', '' ); # obsolete
319
320 if ( $userlang !== $contentlang || $userdir !== $contentdir ) {
321 $attrs = " lang='$userlang' dir='$userdir'";
322 $tpl->set( 'userlangattributes', $attrs );
323 }
324
325 $newtalks = $this->getNewtalks( $out );
326
327 wfProfileOut( __METHOD__ . '-stuff2' );
328
329 wfProfileIn( __METHOD__ . '-stuff3' );
330 $tpl->setRef( 'newtalk', $newtalks );
331 $tpl->setRef( 'skin', $this );
332 $tpl->set( 'logo', $this->logoText() );
333 if ( $out->isArticle() && ( !isset( $oldid ) || isset( $diff ) ) &&
334 $this->getTitle()->exists() )
335 {
336 $article = new Article( $this->getTitle(), 0 );
337 if ( !$wgDisableCounters ) {
338 $viewcount = $wgLang->formatNum( $article->getCount() );
339 if ( $viewcount ) {
340 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
341 } else {
342 $tpl->set( 'viewcount', false );
343 }
344 } else {
345 $tpl->set( 'viewcount', false );
346 }
347
348 if( $wgPageShowWatchingUsers ) {
349 $dbr = wfGetDB( DB_SLAVE );
350 $res = $dbr->select( 'watchlist',
351 array( 'COUNT(*) AS n' ),
352 array( 'wl_title' => $dbr->strencode( $this->getTitle()->getDBkey() ), 'wl_namespace' => $this->getTitle()->getNamespace() ),
353 __METHOD__
354 );
355 $x = $dbr->fetchObject( $res );
356 $numberofwatchingusers = $x->n;
357 if( $numberofwatchingusers > 0 ) {
358 $tpl->set( 'numberofwatchingusers',
359 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
360 $wgLang->formatNum( $numberofwatchingusers ) )
361 );
362 } else {
363 $tpl->set( 'numberofwatchingusers', false );
364 }
365 } else {
366 $tpl->set( 'numberofwatchingusers', false );
367 }
368
369 $tpl->set( 'copyright', $this->getCopyright() );
370
371 $this->credits = false;
372
373 if( $wgMaxCredits != 0 ){
374 $this->credits = Action::factory( 'credits', $article )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax );
375 } else {
376 $tpl->set( 'lastmod', $this->lastModified( $article ) );
377 }
378
379 $tpl->setRef( 'credits', $this->credits );
380
381 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
382 $tpl->set( 'copyright', $this->getCopyright() );
383 $tpl->set( 'viewcount', false );
384 $tpl->set( 'lastmod', false );
385 $tpl->set( 'credits', false );
386 $tpl->set( 'numberofwatchingusers', false );
387 } else {
388 $tpl->set( 'copyright', false );
389 $tpl->set( 'viewcount', false );
390 $tpl->set( 'lastmod', false );
391 $tpl->set( 'credits', false );
392 $tpl->set( 'numberofwatchingusers', false );
393 }
394 wfProfileOut( __METHOD__ . '-stuff3' );
395
396 wfProfileIn( __METHOD__ . '-stuff4' );
397 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
398 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
399 $tpl->set( 'disclaimer', $this->disclaimerLink() );
400 $tpl->set( 'privacy', $this->privacyLink() );
401 $tpl->set( 'about', $this->aboutLink() );
402
403 $tpl->set( 'footerlinks', array(
404 'info' => array(
405 'lastmod',
406 'viewcount',
407 'numberofwatchingusers',
408 'credits',
409 'copyright',
410 ),
411 'places' => array(
412 'privacy',
413 'about',
414 'disclaimer',
415 ),
416 ) );
417
418 global $wgFooterIcons;
419 $tpl->set( 'footericons', $wgFooterIcons );
420 foreach ( $tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
421 if ( count( $footerIconsBlock ) > 0 ) {
422 foreach ( $footerIconsBlock as &$footerIcon ) {
423 if ( isset( $footerIcon['src'] ) ) {
424 if ( !isset( $footerIcon['width'] ) ) {
425 $footerIcon['width'] = 88;
426 }
427 if ( !isset( $footerIcon['height'] ) ) {
428 $footerIcon['height'] = 31;
429 }
430 }
431 }
432 } else {
433 unset( $tpl->data['footericons'][$footerIconsKey] );
434 }
435 }
436
437 if ( $wgDebugComments ) {
438 $tpl->setRef( 'debug', $out->mDebugtext );
439 } else {
440 $tpl->set( 'debug', '' );
441 }
442
443 $tpl->set( 'reporttime', wfReportTime() );
444 $tpl->set( 'sitenotice', $this->getSiteNotice() );
445 $tpl->set( 'bottomscripts', $this->bottomScripts( $out ) );
446 $tpl->set( 'printfooter', $this->printSource() );
447
448 # Add a <div class="mw-content-ltr/rtl"> around the body text
449 # not for special pages or file pages AND only when viewing AND if the page exists
450 # (or is in MW namespace, because that has default content)
451 if( !in_array( $this->getTitle()->getNamespace(), array( NS_SPECIAL, NS_FILE ) ) &&
452 in_array( $action, array( 'view', 'historysubmit' ) ) &&
453 ( $this->getTitle()->exists() || $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) ) {
454 $pageLang = $this->getTitle()->getPageLanguage();
455 $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
456 'class' => 'mw-content-'.$pageLang->getDir() );
457 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
458 }
459
460 $tpl->setRef( 'bodytext', $out->mBodytext );
461
462 # Language links
463 $language_urls = array();
464
465 if ( !$wgHideInterlanguageLinks ) {
466 foreach( $out->getLanguageLinks() as $l ) {
467 $tmp = explode( ':', $l, 2 );
468 $class = 'interwiki-' . $tmp[0];
469 unset( $tmp );
470 $nt = Title::newFromText( $l );
471 if ( $nt ) {
472 $language_urls[] = array(
473 'href' => $nt->getFullURL(),
474 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
475 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
476 'title' => $nt->getText(),
477 'class' => $class
478 );
479 }
480 }
481 }
482 if( count( $language_urls ) ) {
483 $tpl->setRef( 'language_urls', $language_urls );
484 } else {
485 $tpl->set( 'language_urls', false );
486 }
487 wfProfileOut( __METHOD__ . '-stuff4' );
488
489 wfProfileIn( __METHOD__ . '-stuff5' );
490 # Personal toolbar
491 $tpl->set( 'personal_urls', $this->buildPersonalUrls( $out ) );
492 $content_navigation = $this->buildContentNavigationUrls( $out );
493 $content_actions = $this->buildContentActionUrls( $content_navigation );
494 $tpl->setRef( 'content_navigation', $content_navigation );
495 $tpl->setRef( 'content_actions', $content_actions );
496
497 $tpl->set( 'sidebar', $this->buildSidebar() );
498 $tpl->set( 'nav_urls', $this->buildNavUrls( $out ) );
499
500 // Set the head scripts near the end, in case the above actions resulted in added scripts
501 if ( $this->useHeadElement ) {
502 $tpl->set( 'headelement', $out->headElement( $this ) );
503 } else {
504 $tpl->set( 'headscripts', $out->getScript() );
505 }
506
507 $tpl->set( 'debughtml', $this->generateDebugHTML() );
508
509 // original version by hansm
510 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
511 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
512 }
513
514 // allow extensions adding stuff after the page content.
515 // See Skin::afterContentHook() for further documentation.
516 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
517 wfProfileOut( __METHOD__ . '-stuff5' );
518
519 // execute template
520 wfProfileIn( __METHOD__ . '-execute' );
521 $res = $tpl->execute();
522 wfProfileOut( __METHOD__ . '-execute' );
523
524 // result may be an error
525 $this->printOrError( $res );
526 wfProfileOut( __METHOD__ );
527 }
528
529 /**
530 * Output the string, or print error message if it's
531 * an error object of the appropriate type.
532 * For the base class, assume strings all around.
533 *
534 * @param $str Mixed
535 * @private
536 */
537 function printOrError( $str ) {
538 echo $str;
539 }
540
541 /**
542 * Output a boolean indiciating if buildPersonalUrls should output separate
543 * login and create account links or output a combined link
544 * By default we simply return a global config setting that affects most skins
545 * This is setup as a method so that like with $wgLogo and getLogo() a skin
546 * can override this setting and always output one or the other if it has
547 * a reason it can't output one of the two modes.
548 */
549 function useCombinedLoginLink() {
550 global $wgUseCombinedLoginLink;
551 return $wgUseCombinedLoginLink;
552 }
553
554 /**
555 * build array of urls for personal toolbar
556 * @return array
557 */
558 protected function buildPersonalUrls( OutputPage $out ) {
559 global $wgRequest;
560
561 $title = $out->getTitle();
562 $pageurl = $title->getLocalURL();
563 wfProfileIn( __METHOD__ );
564
565 /* set up the default links for the personal toolbar */
566 $personal_urls = array();
567
568 // Get the returnto and returntoquery parameters from the query string
569 // or fall back on $this->thisurl or $this->thisquery
570 // We can't use getVal()'s default value feature here because
571 // stuff from $wgRequest needs to be escaped, but thisurl and thisquery
572 // are already escaped.
573 $page = $wgRequest->getVal( 'returnto' );
574 if ( !is_null( $page ) ) {
575 $page = wfUrlencode( $page );
576 } else {
577 $page = $this->thisurl;
578 }
579 $query = $wgRequest->getVal( 'returntoquery' );
580 if ( !is_null( $query ) ) {
581 $query = wfUrlencode( $query );
582 } else {
583 $query = $this->thisquery;
584 }
585 $returnto = "returnto=$page";
586 if( $query != '' ) {
587 $returnto .= "&returntoquery=$query";
588 }
589 if( $this->loggedin ) {
590 $personal_urls['userpage'] = array(
591 'text' => $this->username,
592 'href' => &$this->userpageUrlDetails['href'],
593 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
594 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
595 );
596 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
597 $personal_urls['mytalk'] = array(
598 'text' => wfMsg( 'mytalk' ),
599 'href' => &$usertalkUrlDetails['href'],
600 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
601 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
602 );
603 $href = self::makeSpecialUrl( 'Preferences' );
604 $personal_urls['preferences'] = array(
605 'text' => wfMsg( 'mypreferences' ),
606 'href' => $href,
607 'active' => ( $href == $pageurl )
608 );
609 $href = self::makeSpecialUrl( 'Watchlist' );
610 $personal_urls['watchlist'] = array(
611 'text' => wfMsg( 'mywatchlist' ),
612 'href' => $href,
613 'active' => ( $href == $pageurl )
614 );
615
616 # We need to do an explicit check for Special:Contributions, as we
617 # have to match both the title, and the target (which could come
618 # from request values or be specified in "sub page" form. The plot
619 # thickens, because $wgTitle is altered for special pages, so doesn't
620 # contain the original alias-with-subpage.
621 $origTitle = Title::newFromText( $wgRequest->getText( 'title' ) );
622 if( $origTitle instanceof Title && $origTitle->getNamespace() == NS_SPECIAL ) {
623 list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() );
624 $active = $spName == 'Contributions'
625 && ( ( $spPar && $spPar == $this->username )
626 || $wgRequest->getText( 'target' ) == $this->username );
627 } else {
628 $active = false;
629 }
630
631 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
632 $personal_urls['mycontris'] = array(
633 'text' => wfMsg( 'mycontris' ),
634 'href' => $href,
635 'active' => $active
636 );
637 $personal_urls['logout'] = array(
638 'text' => wfMsg( 'userlogout' ),
639 'href' => self::makeSpecialUrl( 'Userlogout',
640 // userlogout link must always contain an & character, otherwise we might not be able
641 // to detect a buggy precaching proxy (bug 17790)
642 $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto
643 ),
644 'active' => false
645 );
646 } else {
647 global $wgUser;
648 $useCombinedLoginLink = $this->useCombinedLoginLink();
649 $loginlink = $wgUser->isAllowed( 'createaccount' ) && $useCombinedLoginLink
650 ? 'nav-login-createaccount'
651 : 'login';
652 $is_signup = $wgRequest->getText('type') == "signup";
653
654 # anonlogin & login are the same
655 $login_url = array(
656 'text' => wfMsg( $loginlink ),
657 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
658 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" || !$is_signup )
659 );
660 if ( $wgUser->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
661 $createaccount_url = array(
662 'text' => wfMsg( 'createaccount' ),
663 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
664 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
665 );
666 }
667 global $wgServer, $wgSecureLogin;
668 if( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) {
669 $title = SpecialPage::getTitleFor( 'Userlogin' );
670 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
671 $login_url['href'] = $https_url;
672 # @todo FIXME: Class depends on skin
673 $login_url['class'] = 'link-https';
674 if ( isset($createaccount_url) ) {
675 $https_url = preg_replace( '/^http:/', 'https:',
676 $title->getFullURL("type=signup") );
677 $createaccount_url['href'] = $https_url;
678 # @todo FIXME: Class depends on skin
679 $createaccount_url['class'] = 'link-https';
680 }
681 }
682
683
684 if( $this->showIPinHeader() ) {
685 $href = &$this->userpageUrlDetails['href'];
686 $personal_urls['anonuserpage'] = array(
687 'text' => $this->username,
688 'href' => $href,
689 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
690 'active' => ( $pageurl == $href )
691 );
692 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
693 $href = &$usertalkUrlDetails['href'];
694 $personal_urls['anontalk'] = array(
695 'text' => wfMsg( 'anontalk' ),
696 'href' => $href,
697 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
698 'active' => ( $pageurl == $href )
699 );
700 $personal_urls['anonlogin'] = $login_url;
701 } else {
702 $personal_urls['login'] = $login_url;
703 }
704 if ( isset($createaccount_url) ) {
705 $personal_urls['createaccount'] = $createaccount_url;
706 }
707 }
708
709 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
710 wfProfileOut( __METHOD__ );
711 return $personal_urls;
712 }
713
714 /**
715 * TODO document
716 * @param $title Title
717 * @param $message String message key
718 * @param $selected Bool
719 * @param $query String
720 * @param $checkEdit Bool
721 * @return array
722 */
723 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
724 $classes = array();
725 if( $selected ) {
726 $classes[] = 'selected';
727 }
728 if( $checkEdit && !$title->isKnown() ) {
729 $classes[] = 'new';
730 $query = 'action=edit&redlink=1';
731 }
732
733 // wfMessageFallback will nicely accept $message as an array of fallbacks
734 // or just a single key
735 $msg = wfMessageFallback( $message );
736 if ( is_array($message) ) {
737 // for hook compatibility just keep the last message name
738 $message = end($message);
739 }
740 if ( $msg->exists() ) {
741 $text = $msg->text();
742 } else {
743 global $wgContLang;
744 $text = $wgContLang->getFormattedNsText(
745 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 && $title->getDefaultMessageText() !== false ) ?
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 $includeSuppressed = $wgUser->isAllowed( 'suppressrevision' );
982 $n = $title->isDeleted( $includeSuppressed );
983 if( $n ) {
984 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
985 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
986 $msgKey = $wgUser->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
987 $content_navigation['actions']['undelete'] = array(
988 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
989 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
990 ->params( $wgLang->formatNum( $n ) )->text(),
991 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
992 );
993 }
994 }
995
996 if ( $title->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
997 $mode = !$title->getRestrictions( 'create' ) ? 'protect' : 'unprotect';
998 $content_navigation['actions'][$mode] = array(
999 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
1000 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
1001 'href' => $title->getLocalURL( "action=$mode" )
1002 );
1003 }
1004 }
1005 wfProfileOut( __METHOD__ . '-live' );
1006
1007 // Checks if the user is logged in
1008 if ( $this->loggedin ) {
1009 /**
1010 * The following actions use messages which, if made particular to
1011 * the any specific skins, would break the Ajax code which makes this
1012 * action happen entirely inline. Skin::makeGlobalVariablesScript
1013 * defines a set of messages in a javascript object - and these
1014 * messages are assumed to be global for all skins. Without making
1015 * a change to that procedure these messages will have to remain as
1016 * the global versions.
1017 */
1018 $mode = $title->userIsWatching() ? 'unwatch' : 'watch';
1019 $token = WatchAction::getWatchToken( $title, $wgUser, $mode );
1020 $content_navigation['actions'][$mode] = array(
1021 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
1022 'text' => wfMsg( $mode ), // uses 'watch' or 'unwatch' message
1023 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1024 );
1025 }
1026
1027 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1028 } else {
1029 // If it's not content, it's got to be a special page
1030 $content_navigation['namespaces']['special'] = array(
1031 'class' => 'selected',
1032 'text' => wfMsg( 'nstab-special' ),
1033 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
1034 'context' => 'subject'
1035 );
1036
1037 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1038 array( &$this, &$content_navigation ) );
1039 }
1040
1041 // Gets list of language variants
1042 $variants = $wgContLang->getVariants();
1043 // Checks that language conversion is enabled and variants exist
1044 if( !$wgDisableLangConversion && count( $variants ) > 1 ) {
1045 // Gets preferred variant
1046 $preferred = $wgContLang->getPreferredVariant();
1047 // Loops over each variant
1048 foreach( $variants as $code ) {
1049 // Gets variant name from language code
1050 $varname = $wgContLang->getVariantname( $code );
1051 // Checks if the variant is marked as disabled
1052 if( $varname == 'disable' ) {
1053 // Skips this variant
1054 continue;
1055 }
1056 // Appends variant link
1057 $content_navigation['variants'][] = array(
1058 'class' => ( $code == $preferred ) ? 'selected' : false,
1059 'text' => $varname,
1060 'href' => $title->getLocalURL( '', $code )
1061 );
1062 }
1063 }
1064
1065 // Equiv to SkinTemplateContentActions
1066 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1067
1068 // Setup xml ids and tooltip info
1069 foreach ( $content_navigation as $section => &$links ) {
1070 foreach ( $links as $key => &$link ) {
1071 $xmlID = $key;
1072 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1073 $xmlID = 'ca-nstab-' . $xmlID;
1074 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1075 $xmlID = 'ca-talk';
1076 } elseif ( $section == "variants" ) {
1077 $xmlID = 'ca-varlang-' . $xmlID;
1078 } else {
1079 $xmlID = 'ca-' . $xmlID;
1080 }
1081 $link['id'] = $xmlID;
1082 }
1083 }
1084
1085 # We don't want to give the watch tab an accesskey if the
1086 # page is being edited, because that conflicts with the
1087 # accesskey on the watch checkbox. We also don't want to
1088 # give the edit tab an accesskey, because that's fairly su-
1089 # perfluous and conflicts with an accesskey (Ctrl-E) often
1090 # used for editing in Safari.
1091 if( in_array( $action, array( 'edit', 'submit' ) ) ) {
1092 if ( isset($content_navigation['views']['edit']) ) {
1093 $content_navigation['views']['edit']['tooltiponly'] = true;
1094 }
1095 if ( isset($content_navigation['actions']['watch']) ) {
1096 $content_navigation['actions']['watch']['tooltiponly'] = true;
1097 }
1098 if ( isset($content_navigation['actions']['unwatch']) ) {
1099 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1100 }
1101 }
1102
1103 wfProfileOut( __METHOD__ );
1104
1105 return $content_navigation;
1106 }
1107
1108 /**
1109 * an array of edit links by default used for the tabs
1110 * @return array
1111 * @private
1112 */
1113 function buildContentActionUrls( $content_navigation ) {
1114
1115 wfProfileIn( __METHOD__ );
1116
1117 // content_actions has been replaced with content_navigation for backwards
1118 // compatibility and also for skins that just want simple tabs content_actions
1119 // is now built by flattening the content_navigation arrays into one
1120
1121 $content_actions = array();
1122
1123 foreach ( $content_navigation as $links ) {
1124
1125 foreach ( $links as $key => $value ) {
1126
1127 if ( isset($value["redundant"]) && $value["redundant"] ) {
1128 // Redundant tabs are dropped from content_actions
1129 continue;
1130 }
1131
1132 // content_actions used to have ids built using the "ca-$key" pattern
1133 // so the xmlID based id is much closer to the actual $key that we want
1134 // for that reason we'll just strip out the ca- if present and use
1135 // the latter potion of the "id" as the $key
1136 if ( isset($value["id"]) && substr($value["id"], 0, 3) == "ca-" ) {
1137 $key = substr($value["id"], 3);
1138 }
1139
1140 if ( isset($content_actions[$key]) ) {
1141 wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1142 continue;
1143 }
1144
1145 $content_actions[$key] = $value;
1146
1147 }
1148
1149 }
1150
1151 wfProfileOut( __METHOD__ );
1152
1153 return $content_actions;
1154 }
1155
1156 /**
1157 * build array of common navigation links
1158 * @return array
1159 * @private
1160 */
1161 protected function buildNavUrls( OutputPage $out ) {
1162 global $wgUseTrackbacks, $wgUser, $wgRequest;
1163 global $wgUploadNavigationUrl;
1164
1165 wfProfileIn( __METHOD__ );
1166
1167 $action = $wgRequest->getVal( 'action', 'view' );
1168
1169 $nav_urls = array();
1170 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
1171 if( $wgUploadNavigationUrl ) {
1172 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1173 } elseif( UploadBase::isEnabled() && UploadBase::isAllowed( $wgUser ) === true ) {
1174 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
1175 } else {
1176 $nav_urls['upload'] = false;
1177 }
1178 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
1179
1180 // default permalink to being off, will override it as required below.
1181 $nav_urls['permalink'] = false;
1182
1183 // A print stylesheet is attached to all pages, but nobody ever
1184 // figures that out. :) Add a link...
1185 if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
1186 if ( !$out->isPrintable() ) {
1187 $nav_urls['print'] = array(
1188 'text' => wfMsg( 'printableversion' ),
1189 'href' => $this->getTitle()->getLocalURL(
1190 $wgRequest->appendQueryValue( 'printable', 'yes', true ) )
1191 );
1192 }
1193
1194 // Also add a "permalink" while we're at it
1195 $revid = $this->getRevisionId();
1196 if ( $revid ) {
1197 $nav_urls['permalink'] = array(
1198 'text' => wfMsg( 'permalink' ),
1199 'href' => $out->getTitle()->getLocalURL( "oldid=$revid" )
1200 );
1201 }
1202
1203 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1204 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1205 array( &$this, &$nav_urls, &$revid, &$revid ) );
1206 }
1207
1208 if( $this->getTitle()->getNamespace() != NS_SPECIAL ) {
1209 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
1210 $nav_urls['whatlinkshere'] = array(
1211 'href' => $wlhTitle->getLocalUrl()
1212 );
1213 if( $this->getTitle()->getArticleId() ) {
1214 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
1215 $nav_urls['recentchangeslinked'] = array(
1216 'href' => $rclTitle->getLocalUrl()
1217 );
1218 } else {
1219 $nav_urls['recentchangeslinked'] = false;
1220 }
1221 if( $wgUseTrackbacks )
1222 $nav_urls['trackbacklink'] = array(
1223 'href' => $out->getTitle()->trackbackURL()
1224 );
1225 }
1226
1227 $user = $this->getRelevantUser();
1228 if ( $user ) {
1229 $id = $user->getID();
1230 $ip = $user->isAnon();
1231 $rootUser = $user->getName();
1232 } else {
1233 $id = 0;
1234 $ip = false;
1235 $rootUser = null;
1236 }
1237
1238 if( $id || $ip ) { # both anons and non-anons have contribs list
1239 $nav_urls['contributions'] = array(
1240 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1241 );
1242
1243 if( $id ) {
1244 $logPage = SpecialPage::getTitleFor( 'Log' );
1245 $nav_urls['log'] = array(
1246 'href' => $logPage->getLocalUrl(
1247 array(
1248 'user' => $rootUser
1249 )
1250 )
1251 );
1252 } else {
1253 $nav_urls['log'] = false;
1254 }
1255
1256 if ( $wgUser->isAllowed( 'block' ) ) {
1257 $nav_urls['blockip'] = array(
1258 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
1259 );
1260 } else {
1261 $nav_urls['blockip'] = false;
1262 }
1263 } else {
1264 $nav_urls['contributions'] = false;
1265 $nav_urls['log'] = false;
1266 $nav_urls['blockip'] = false;
1267 }
1268 $nav_urls['emailuser'] = false;
1269 if( $this->showEmailUser( $id ) ) {
1270 $nav_urls['emailuser'] = array(
1271 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1272 );
1273 }
1274 wfProfileOut( __METHOD__ );
1275 return $nav_urls;
1276 }
1277
1278 /**
1279 * Generate strings used for xml 'id' names
1280 * @return string
1281 * @private
1282 */
1283 function getNameSpaceKey() {
1284 return $this->getTitle()->getNamespaceKey();
1285 }
1286
1287 /**
1288 * @private
1289 * @todo FIXME: Why is this duplicated in/from OutputPage::getHeadScripts()??
1290 */
1291 function setupUserJs( $allowUserJs ) {
1292 global $wgRequest, $wgJsMimeType;
1293 wfProfileIn( __METHOD__ );
1294
1295 if( $allowUserJs && $this->loggedin ) {
1296 if( $this->getTitle()->isJsSubpage() and $this->userCanPreview() ) {
1297 # XXX: additional security check/prompt?
1298 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1299 } else {
1300 $this->userjs = self::makeUrl( $this->userpage . '/' . $this->skinname . '.js', 'action=raw&ctype=' . $wgJsMimeType );
1301 }
1302 }
1303 wfProfileOut( __METHOD__ );
1304 }
1305
1306 public function commonPrintStylesheet() {
1307 return false;
1308 }
1309 }
1310
1311 /**
1312 * Generic wrapper for template functions, with interface
1313 * compatible with what we use of PHPTAL 0.7.
1314 * @ingroup Skins
1315 */
1316 abstract class QuickTemplate {
1317 /**
1318 * Constructor
1319 */
1320 public function QuickTemplate() {
1321 $this->data = array();
1322 $this->translator = new MediaWiki_I18N();
1323 }
1324
1325 /**
1326 * Sets the value $value to $name
1327 * @param $name
1328 * @param $value
1329 */
1330 public function set( $name, $value ) {
1331 $this->data[$name] = $value;
1332 }
1333
1334 /**
1335 * @param $name
1336 * @param $value
1337 */
1338 public function setRef( $name, &$value ) {
1339 $this->data[$name] =& $value;
1340 }
1341
1342 /**
1343 * @param $t
1344 */
1345 public function setTranslator( &$t ) {
1346 $this->translator = &$t;
1347 }
1348
1349 /**
1350 * Main function, used by classes that subclass QuickTemplate
1351 * to show the actual HTML output
1352 */
1353 abstract public function execute();
1354
1355 /**
1356 * @private
1357 */
1358 function text( $str ) {
1359 echo htmlspecialchars( $this->data[$str] );
1360 }
1361
1362 /**
1363 * @private
1364 */
1365 function jstext( $str ) {
1366 echo Xml::escapeJsString( $this->data[$str] );
1367 }
1368
1369 /**
1370 * @private
1371 */
1372 function html( $str ) {
1373 echo $this->data[$str];
1374 }
1375
1376 /**
1377 * @private
1378 */
1379 function msg( $str ) {
1380 echo htmlspecialchars( $this->translator->translate( $str ) );
1381 }
1382
1383 /**
1384 * @private
1385 */
1386 function msgHtml( $str ) {
1387 echo $this->translator->translate( $str );
1388 }
1389
1390 /**
1391 * An ugly, ugly hack.
1392 * @private
1393 */
1394 function msgWiki( $str ) {
1395 global $wgParser, $wgOut;
1396
1397 $text = $this->translator->translate( $str );
1398 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1399 $wgOut->parserOptions(), true );
1400 echo $parserOutput->getText();
1401 }
1402
1403 /**
1404 * @private
1405 */
1406 function haveData( $str ) {
1407 return isset( $this->data[$str] );
1408 }
1409
1410 /**
1411 * @private
1412 *
1413 * @return bool
1414 */
1415 function haveMsg( $str ) {
1416 $msg = $this->translator->translate( $str );
1417 return ( $msg != '-' ) && ( $msg != '' ); # ????
1418 }
1419
1420 /**
1421 * Get the Skin object related to this object
1422 *
1423 * @return Skin object
1424 */
1425 public function getSkin() {
1426 return $this->data['skin'];
1427 }
1428 }
1429
1430 /**
1431 * New base template for a skin's template extended from QuickTemplate
1432 * this class features helper methods that provide common ways of interacting
1433 * with the data stored in the QuickTemplate
1434 */
1435 abstract class BaseTemplate extends QuickTemplate {
1436
1437 /**
1438 * Create an array of common toolbox items from the data in the quicktemplate
1439 * stored by SkinTemplate.
1440 * The resulting array is built acording to a format intended to be passed
1441 * through makeListItem to generate the html.
1442 */
1443 function getToolbox() {
1444 wfProfileIn( __METHOD__ );
1445
1446 $toolbox = array();
1447 if ( $this->data['notspecialpage'] ) {
1448 $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
1449 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1450 if ( $this->data['nav_urls']['recentchangeslinked'] ) {
1451 $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
1452 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1453 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1454 }
1455 }
1456 if( isset( $this->data['nav_urls']['trackbacklink'] ) && $this->data['nav_urls']['trackbacklink'] ) {
1457 $toolbox['trackbacklink'] = $this->data['nav_urls']['trackbacklink'];
1458 $toolbox['trackbacklink']['id'] = 't-trackbacklink';
1459 }
1460 if ( $this->data['feeds'] ) {
1461 $toolbox['feeds']['id'] = 'feedlinks';
1462 $toolbox['feeds']['links'] = array();
1463 foreach ( $this->data['feeds'] as $key => $feed ) {
1464 $toolbox['feeds']['links'][$key] = $feed;
1465 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1466 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1467 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1468 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1469 }
1470 }
1471 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1472 if ( $this->data['nav_urls'][$special] ) {
1473 $toolbox[$special] = $this->data['nav_urls'][$special];
1474 $toolbox[$special]['id'] = "t-$special";
1475 }
1476 }
1477 if ( !empty( $this->data['nav_urls']['print']['href'] ) ) {
1478 $toolbox['print'] = $this->data['nav_urls']['print'];
1479 $toolbox['print']['rel'] = 'alternate';
1480 $toolbox['print']['msg'] = 'printableversion';
1481 }
1482 if( $this->data['nav_urls']['permalink'] ) {
1483 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
1484 if( $toolbox['permalink']['href'] === '' ) {
1485 unset( $toolbox['permalink']['href'] );
1486 $toolbox['ispermalink']['tooltiponly'] = true;
1487 $toolbox['ispermalink']['id'] = 't-ispermalink';
1488 $toolbox['ispermalink']['msg'] = 'permalink';
1489 } else {
1490 $toolbox['permalink']['id'] = 't-permalink';
1491 }
1492 }
1493 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1494 wfProfileOut( __METHOD__ );
1495 return $toolbox;
1496 }
1497
1498 /**
1499 * Create an array of personal tools items from the data in the quicktemplate
1500 * stored by SkinTemplate.
1501 * The resulting array is built acording to a format intended to be passed
1502 * through makeListItem to generate the html.
1503 * This is in reality the same list as already stored in personal_urls
1504 * however it is reformatted so that you can just pass the individual items
1505 * to makeListItem instead of hardcoding the element creation boilerplate.
1506 */
1507 function getPersonalTools() {
1508 $personal_tools = array();
1509 foreach( $this->data['personal_urls'] as $key => $ptool ) {
1510 # The class on a personal_urls item is meant to go on the <a> instead
1511 # of the <li> so we have to use a single item "links" array instead
1512 # of using most of the personal_url's keys directly
1513 $personal_tools[$key] = array();
1514 $personal_tools[$key]["links"][] = array();
1515 $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key";
1516 if ( isset($ptool["active"]) ) {
1517 $personal_tools[$key]["active"] = $ptool["active"];
1518 }
1519 foreach ( array("href", "class", "text") as $k ) {
1520 if ( isset($ptool[$k]) )
1521 $personal_tools[$key]["links"][0][$k] = $ptool[$k];
1522 }
1523 }
1524 return $personal_tools;
1525 }
1526
1527 /**
1528 * Makes a link, usually used by makeListItem to generate a link for an item
1529 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1530 *
1531 * $key is a string, usually a key from the list you are generating this link from
1532 * $item is an array containing some of a specific set of keys.
1533 * The text of the link will be generated either from the contents of the "text"
1534 * key in the $item array, if a "msg" key is present a message by that name will
1535 * be used, and if neither of those are set the $key will be used as a message name.
1536 * If a "href" key is not present makeLink will just output htmlescaped text.
1537 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1538 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1539 * is present it will be used to generate a tooltip and accesskey for the link.
1540 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1541 */
1542 function makeLink( $key, $item ) {
1543 if ( isset( $item['text'] ) ) {
1544 $text = $item['text'];
1545 } else {
1546 $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key );
1547 }
1548
1549 if ( !isset( $item['href'] ) ) {
1550 return htmlspecialchars( $text );
1551 }
1552
1553 $attrs = array();
1554 foreach ( array( 'href', 'id', 'class', 'rel', 'type', 'target') as $attr ) {
1555 if ( isset( $item[$attr] ) ) {
1556 $attrs[$attr] = $item[$attr];
1557 }
1558 }
1559
1560 if ( isset( $item['id'] ) ) {
1561 $item['single-id'] = $item['id'];
1562 }
1563 if ( isset( $item['single-id'] ) ) {
1564 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1565 $attrs['title'] = $this->skin->titleAttrib( $item['single-id'] );
1566 if ( $attrs['title'] === false ) {
1567 unset( $attrs['title'] );
1568 }
1569 } else {
1570 $attrs = array_merge(
1571 $attrs,
1572 Linker::tooltipAndAccesskeyAttribs( $item['single-id'] )
1573 );
1574 }
1575 }
1576
1577 return Html::element( 'a', $attrs, $text );
1578 }
1579
1580 /**
1581 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1582 * $key is a string, usually a key from the list you are generating this link from
1583 * $item is an array of list item data containing some of a specific set of keys.
1584 * The "id" and "class" keys will be used as attributes for the list item,
1585 * if "active" contains a value of true a "active" class will also be appended to class.
1586 * If you want something other than a <li> you can pass a tag name such as
1587 * "tag" => "span" in the $options array to change the tag used.
1588 * link/content data for the list item may come in one of two forms
1589 * A "links" key may be used, in which case it should contain an array with
1590 * a list of links to include inside the list item, see makeLink for the format
1591 * of individual links array items.
1592 * Otherwise the relevant keys from the list item $item array will be passed
1593 * to makeLink instead. Note however that "id" and "class" are used by the
1594 * list item directly so they will not be passed to makeLink
1595 * (however the link will still support a tooltip and accesskey from it)
1596 * If you need an id or class on a single link you should include a "links"
1597 * array with just one link item inside of it.
1598 */
1599 function makeListItem( $key, $item, $options = array() ) {
1600 if ( isset( $item['links'] ) ) {
1601 $html = '';
1602 foreach ( $item['links'] as $linkKey => $link ) {
1603 $html .= $this->makeLink( $linkKey, $link );
1604 }
1605 } else {
1606 $link = array();
1607 foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly', 'target' ) as $k ) {
1608 if ( isset( $item[$k] ) ) {
1609 $link[$k] = $item[$k];
1610 }
1611 }
1612 if ( isset( $item['id'] ) ) {
1613 // The id goes on the <li> not on the <a> for single links
1614 // but makeSidebarLink still needs to know what id to use when
1615 // generating tooltips and accesskeys.
1616 $link['single-id'] = $item['id'];
1617 }
1618 $html = $this->makeLink( $key, $link );
1619 }
1620
1621 $attrs = array();
1622 foreach ( array( 'id', 'class' ) as $attr ) {
1623 if ( isset( $item[$attr] ) ) {
1624 $attrs[$attr] = $item[$attr];
1625 }
1626 }
1627 if ( isset( $item['active'] ) && $item['active'] ) {
1628 if ( !isset( $attrs['class'] ) ) {
1629 $attrs['class'] = '';
1630 }
1631 $attrs['class'] .= ' active';
1632 $attrs['class'] = trim( $attrs['class'] );
1633 }
1634 return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
1635 }
1636
1637 function makeSearchInput( $attrs = array() ) {
1638 $realAttrs = array(
1639 'type' => 'search',
1640 'name' => 'search',
1641 'value' => isset( $this->data['search'] ) ? $this->data['search'] : '',
1642 );
1643 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1644 return Html::element( 'input', $realAttrs );
1645 }
1646
1647 function makeSearchButton( $mode, $attrs = array() ) {
1648 switch( $mode ) {
1649 case 'go':
1650 case 'fulltext':
1651 $realAttrs = array(
1652 'type' => 'submit',
1653 'name' => $mode,
1654 'value' => $this->translator->translate(
1655 $mode == 'go' ? 'searcharticle' : 'searchbutton' ),
1656 );
1657 $realAttrs = array_merge(
1658 $realAttrs,
1659 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
1660 $attrs
1661 );
1662 return Html::element( 'input', $realAttrs );
1663 case 'image':
1664 $buttonAttrs = array(
1665 'type' => 'submit',
1666 'name' => 'button',
1667 );
1668 $buttonAttrs = array_merge(
1669 $buttonAttrs,
1670 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1671 $attrs
1672 );
1673 unset( $buttonAttrs['src'] );
1674 unset( $buttonAttrs['alt'] );
1675 $imgAttrs = array(
1676 'src' => $attrs['src'],
1677 'alt' => isset( $attrs['alt'] )
1678 ? $attrs['alt']
1679 : $this->translator->translate( 'searchbutton' ),
1680 );
1681 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
1682 default:
1683 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1684 }
1685 }
1686
1687 /**
1688 * Returns an array of footerlinks trimmed down to only those footer links that
1689 * are valid.
1690 * If you pass "flat" as an option then the returned array will be a flat array
1691 * of footer icons instead of a key/value array of footerlinks arrays broken
1692 * up into categories.
1693 */
1694 function getFooterLinks( $option = null ) {
1695 $footerlinks = $this->data['footerlinks'];
1696
1697 // Reduce footer links down to only those which are being used
1698 $validFooterLinks = array();
1699 foreach( $footerlinks as $category => $links ) {
1700 $validFooterLinks[$category] = array();
1701 foreach( $links as $link ) {
1702 if( isset( $this->data[$link] ) && $this->data[$link] ) {
1703 $validFooterLinks[$category][] = $link;
1704 }
1705 }
1706 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1707 unset( $validFooterLinks[$category] );
1708 }
1709 }
1710
1711 if ( $option == 'flat' ) {
1712 // fold footerlinks into a single array using a bit of trickery
1713 $validFooterLinks = call_user_func_array(
1714 'array_merge',
1715 array_values( $validFooterLinks )
1716 );
1717 }
1718
1719 return $validFooterLinks;
1720 }
1721
1722 /**
1723 * Returns an array of footer icons filtered down by options relevant to how
1724 * the skin wishes to display them.
1725 * If you pass "icononly" as the option all footer icons which do not have an
1726 * image icon set will be filtered out.
1727 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1728 * in the list of footer icons. This is mostly useful for skins which only
1729 * display the text from footericons instead of the images and don't want a
1730 * duplicate copyright statement because footerlinks already rendered one.
1731 */
1732 function getFooterIcons( $option = null ) {
1733 // Generate additional footer icons
1734 $footericons = $this->data['footericons'];
1735
1736 if ( $option == 'icononly' ) {
1737 // Unset any icons which don't have an image
1738 foreach ( $footericons as &$footerIconsBlock ) {
1739 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1740 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1741 unset( $footerIconsBlock[$footerIconKey] );
1742 }
1743 }
1744 }
1745 // Redo removal of any empty blocks
1746 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1747 if ( count( $footerIconsBlock ) <= 0 ) {
1748 unset( $footericons[$footerIconsKey] );
1749 }
1750 }
1751 } elseif ( $option == 'nocopyright' ) {
1752 unset( $footericons['copyright']['copyright'] );
1753 if ( count( $footericons['copyright'] ) <= 0 ) {
1754 unset( $footericons['copyright'] );
1755 }
1756 }
1757
1758 return $footericons;
1759 }
1760
1761 /**
1762 * Output the basic end-page trail including bottomscripts, reporttime, and
1763 * debug stuff. This should be called right before outputting the closing
1764 * body and html tags.
1765 */
1766 function printTrail() { ?>
1767 <?php $this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?>
1768 <?php $this->html('reporttime') ?>
1769 <?php if ( $this->data['debug'] ): ?>
1770 <!-- Debug output:
1771 <?php $this->text( 'debug' ); ?>
1772
1773 -->
1774 <?php endif;
1775 }
1776
1777 }
1778