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