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