-
Notifications
You must be signed in to change notification settings - Fork 12
/
Monaco.skin.php
executable file
·1823 lines (1603 loc) · 59.2 KB
/
Monaco.skin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Monaco skin
*
* @package MediaWiki
* @subpackage Skins
*
* @author Inez Korczynski <[email protected]>
* @author Christian Williams
* @author Daniel Friesen
*/
if(!defined('MEDIAWIKI')) {
die(-1);
}
define('STAR_RATINGS_WIDTH_MULTIPLIER', 20);
class SkinMonaco extends SkinTemplate {
/**
* Overwrite few SkinTemplate methods which we don't need in Monaco
*/
function buildSidebar() {}
function getCopyrightIcon() {}
function getPoweredBy() {}
function disclaimerLink() {}
function privacyLink() {}
function aboutLink() {}
function getHostedBy() {}
function diggsLink() {}
function deliciousLink() {}
/** Using monaco. */
var $skinname = 'monaco', $stylename = 'monaco',
$template = 'MonacoTemplate', $useHeadElement = true;
/**
* @author Inez Korczynski <[email protected]>
*/
public function initPage( OutputPage $out ) {
wfDebugLog('monaco', '##### SkinMonaco initPage #####');
wfProfileIn(__METHOD__);
global $wgHooks, $wgJsMimeType, $wgStylePath, $wgResourceModules;
SkinTemplate::initPage($out);
/*
$this->skinname = 'monaco';
$this->stylename = 'monaco';
$this->template = 'MonacoTemplate';
*/
// Function addVariables will be called to populate all needed data to render skin
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = array(&$this, 'addVariables');
if ( method_exists( 'OutputPage', 'addModuleStyles' ) ) {
// MediaWiki 1.17 and above, load the bulk of our scripts with the resource loader
$out->addModuleScripts( 'skins.monaco' );
} else {
// MediaWiki 1.16 and below, read our resource loader data and just load
// the individual script.
$out->addScriptFile( preg_replace( '#^skins/#', "{$wgStylePath}/", $wgResourceModules['skins.monaco']['scripts'] ) );
}
$out->addScript(
'<!--[if IE]><script type="' . htmlspecialchars($wgJsMimeType) .
'">\'abbr article aside audio canvas details figcaption figure ' .
'footer header hgroup mark menu meter nav output progress section ' .
'summary time video\'' .
'.replace(/\w+/g,function(n){document.createElement(n)})</script><![endif]-->'
);
wfProfileOut(__METHOD__);
}
/**
* Add specific styles for this skin
*
* Don't add common/shared.css as it's kept in allinone.css
*
* @param $out OutputPage
*/
function setupSkinUserCss( OutputPage $out ){
global $wgMonacoTheme, $wgMonacoAllowUsetheme, $wgRequest, $wgResourceModules;
parent::setupSkinUserCss( $out );
if ( method_exists( 'OutputPage', 'addModuleStyles' ) ) {
// MediaWiki 1.17 and above, load the bulk of our styles with the resource loader
$out->addModuleStyles( 'skins.monaco' );
} else {
// MediaWiki 1.16 and below, read our resource loader array and just load
// the individual stylesheets. We don't really care much about older
// versions of MW when people should be upgrading if they really want
// new features, so anyone not using 1.17 can just deal with the extra
// http requests... if they really care about the requests they can upgrade
// as soon as 1.17 is available to them...
foreach ( $wgResourceModules['skins.monaco']['styles'] as $path => $options ) {
$path = preg_replace( '#^skins/#', '', $path );
$out->addStyle( $path, $options['media'] );
}
}
// ResourceLoader doesn't do ie specific styles that well iirc, so we have
// to do those manually.
$out->addStyle( 'monaco/style/css/monaco_ltie7.css', 'screen', 'lt IE 7' );
$out->addStyle( 'monaco/style/css/monaco_ie7.css', 'screen', 'IE 7' );
$out->addStyle( 'monaco/style/css/monaco_ie8.css', 'screen', 'IE 8' );
// Likewise the masthead is a conditional feature so it's hard to include
// inside of the ResourceLoader.
if ( $this->showMasthead() ) {
$out->addStyle( 'monaco/style/css/masthead.css', 'screen' );
}
$theme = $wgMonacoTheme;
if ( $wgMonacoAllowUsetheme ) {
$theme = $wgRequest->getText('usetheme', $theme);
if ( preg_match('/[^a-z]/', $theme) ) {
$theme = $wgMonacoTheme;
}
}
if ( preg_match('/[^a-z]/', $theme) ) {
$theme = "sapphire";
}
// Theme is another conditional feature, we can't really resource load this
if ( isset($theme) && is_string($theme) && $theme != "sapphire" )
$out->addStyle( "monaco/style/{$theme}/css/main.css", 'screen' );
// rtl... hmm, how do we resource load this?
$out->addStyle( 'monaco/style/rtl.css', 'screen', '', 'rtl' );
// Make sure jQuery is loaded.
if ( method_exists( 'OutputPage', 'includeJQuery' ) ) {
$out->includeJQuery();
}
}
function showMasthead() {
global $wgMonacoUseMasthead;
if ( !$wgMonacoUseMasthead ) {
return false;
}
return !!$this->getMastheadUser();
}
function getMastheadUser() {
global $wgTitle;
if ( !isset($this->mMastheadUser) ) {
$ns = $wgTitle->getNamespace();
if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
$this->mMastheadUser = User::newFromName( strtok( $wgTitle->getText(), '/' ), false );
$this->mMastheadTitleVisible = false;
} else {
$this->mMastheadUser = false;
$this->mMastheadTitleVisible = true; // title is visible anyways if we're not on a masthead using page
}
}
return $this->mMastheadUser;
}
function isMastheadTitleVisible() {
if ( !$this->showMasthead() ) {
return true;
}
$this->getMastheadUser();
return $this->mMastheadTitleVisible;
}
/**
* @author Inez Korczynski <[email protected]>
* @author Christian Williams
* @author Daniel Friesen <http://daniel.friesen.name/>
* Added this functionality to MediaWiki, may need to add a patch to MW 1.16 and older
* This allows the skin to add body attributes while still integrating with
* MediaWiki's new headelement code. I modified the original Monaco code to
* use this cleaner method. I did not port loggedout or mainpage as these are
* generic, I added a separate hook so that a generic extension can be made
* to add those universally to all new skins.
*/
function addToBodyAttributes( $out, &$bodyAttrs ) {
global $wgRequest;
$bodyAttrs['class'] .= ' color2';
$action = $wgRequest->getVal('action');
if (in_array($action, array('edit', 'history', 'diff', 'delete', 'protect', 'unprotect', 'submit'))) {
$bodyAttrs['class'] .= ' action_' . $action;
} else if (empty($action) || in_array($action, array('view', 'purge'))) {
$bodyAttrs['class'] .= ' action_view';
}
if ( $this->showMasthead() ) {
if ( $this->isMastheadTitleVisible() ) {
$bodyAttrs['class'] .= ' masthead-special';
} else {
$bodyAttrs['class'] .= ' masthead-regular';
}
}
$bodyAttrs['id'] = "body";
}
/**
* @author Inez Korczynski <[email protected]>
*/
public function addVariables(&$obj, &$tpl) {
wfProfileIn(__METHOD__);
global $wgLang, $wgContLang, $wgUser, $wgRequest, $wgTitle, $parserMemc;
// We want to cache populated data only if user language is same with wiki language
$cache = $wgLang->getCode() == $wgContLang->getCode();
wfDebugLog('monaco', sprintf('Cache: %s, wgLang: %s, wgContLang %s', (int) $cache, $wgLang->getCode(), $wgContLang->getCode()));
if($cache) {
$key = wfMemcKey('MonacoDataOld');
$data_array = $parserMemc->get($key);
}
if(empty($data_array)) {
wfDebugLog('monaco', 'There is no cached $data_array, let\'s populate');
wfProfileIn(__METHOD__ . ' - DATA ARRAY');
// @kill $data_array['categorylist'] = DataProvider::getCategoryList();
$data_array['toolboxlinks'] = $this->getToolboxLinks();
//$data_array['sidebarmenu'] = $this->getSidebarLinks();
wfProfileOut(__METHOD__ . ' - DATA ARRAY');
if($cache) {
$parserMemc->set($key, $data_array, 4 * 60 * 60 /* 4 hours */);
}
}
if($wgUser->isLoggedIn()) {
if(empty($wgUser->mMonacoData) || ($wgTitle->getNamespace() == NS_USER && $wgRequest->getText('action') == 'delete')) {
wfDebugLog('monaco', 'mMonacoData for user is empty');
$wgUser->mMonacoData = array();
wfProfileIn(__METHOD__ . ' - DATA ARRAY');
/*
$text = $this->getTransformedArticle('User:'.$wgUser->getName().'/Monaco-sidebar', true);
if(empty($text)) {
$wgUser->mMonacoData['sidebarmenu'] = false;
} else {
$wgUser->mMonacoData['sidebarmenu'] = $this->parseSidebarMenu($text);
}
*/
$text = $this->getTransformedArticle('User:'.$wgUser->getName().'/Monaco-toolbox', true);
if(empty($text)) {
$wgUser->mMonacoData['toolboxlinks'] = false;
} else {
$wgUser->mMonacoData['toolboxlinks'] = $this->parseToolboxLinks($text);
}
wfProfileOut(__METHOD__ . ' - DATA ARRAY');
$wgUser->saveToCache();
}
/*
if($wgUser->mMonacoData['sidebarmenu'] !== false && is_array($wgUser->mMonacoData['sidebarmenu'])) {
wfDebugLog('monaco', 'There is user data for sidebarmenu');
$data_array['sidebarmenu'] = $wgUser->mMonacoData['sidebarmenu'];
}
*/
if($wgUser->mMonacoData['toolboxlinks'] !== false && is_array($wgUser->mMonacoData['toolboxlinks'])) {
wfDebugLog('monaco', 'There is user data for toolboxlinks');
$data_array['toolboxlinks'] = $wgUser->mMonacoData['toolboxlinks'];
}
}
foreach($data_array['toolboxlinks'] as $key => $val) {
if(isset($val['org']) && $val['org'] == 'whatlinkshere') {
if(isset($tpl->data['nav_urls']['whatlinkshere'])) {
$data_array['toolboxlinks'][$key]['href'] = $tpl->data['nav_urls']['whatlinkshere']['href'];
} else {
unset($data_array['toolboxlinks'][$key]);
}
}
if(isset($val['org']) && $val['org'] == 'permalink') {
if(isset($tpl->data['nav_urls']['permalink'])) {
$data_array['toolboxlinks'][$key]['href'] = $tpl->data['nav_urls']['permalink']['href'];
} else {
unset($data_array['toolboxlinks'][$key]);
}
}
}
/*
foreach($data_array['sidebarmenu'] as $key => $val) {
if(isset($val['org']) && $val['org'] == 'editthispage') {
if(isset($tpl->data['content_actions']['edit'])) {
$data_array['sidebarmenu'][$key]['href'] = $tpl->data['content_actions']['edit']['href'];
} else {
unset($data_array['sidebarmenu'][$key]);
foreach($data_array['sidebarmenu'] as $key1 => $val1) {
if(isset($val1['children'])) {
foreach($val1['children'] as $key2 => $val2) {
if($key == $val2) {
unset($data_array['sidebarmenu'][$key1]['children'][$key2]);
}
}
}
}
}
}
}
if( $wgUser->isAllowed( 'editinterface' ) ) {
if(isset($data_array['sidebarmenu'])) {
$monacoSidebarUrl = Title::makeTitle(NS_MEDIAWIKI, 'Monaco-sidebar')->getLocalUrl('action=edit');
foreach($data_array['sidebarmenu'] as $nodeKey => $nodeVal) {
if(empty($nodeVal['magic']) && isset($nodeVal['children']) && isset($nodeVal['depth']) && $nodeVal['depth'] === 1) {
$data_array['sidebarmenu'][$nodeKey]['children'][] = $this->lastExtraIndex;
$data_array['sidebarmenu'][$this->lastExtraIndex] = array(
'text' => wfMessage('monaco-edit-this-menu')->text(),
'href' => $monacoSidebarUrl,
'class' => 'Monaco-sidebar_edit'
);
}
}
}
}
*/
$tpl->set('data', $data_array);
// This is for WidgetLanguages
$this->language_urls = $tpl->data['language_urls'];
// Article content links (View, Edit, Delete, Move, etc.)
$tpl->set('articlelinks', $this->getArticleLinks($tpl));
// User actions links
$tpl->set('userlinks', $this->getUserLinks($tpl));
/* @todo Look at this a tiny bit to figure out what js files to load
if ($wgUser->isLoggedIn()) {
$package = 'monaco_loggedin_js';
}
else {
// list of namespaces and actions on which we should load package with YUI
$ns = array(NS_SPECIAL);
$actions = array('edit', 'preview', 'submit');
if ( in_array($wgTitle->getNamespace(), $ns) || in_array($wgRequest->getVal('action', 'view'), $actions) ) {
// edit mode & special/blog pages (package with YUI)
$package = 'monaco_anon_everything_else_js';
}
else {
// view mode (package without YUI)
$package = 'monaco_anon_article_js';
}$this->data['stylepath'].'/monaco/style/images/blank.gif'
}
global $wgStylePath, $wgStyleVersion;
// use WikiaScriptLoader to load StaticChute in parallel with other scripts added by wgOut->addScript
/* wfProfileIn(__METHOD__ . '::JSloader');
$jsReferences = array();
/*if($allinone && $package == 'monaco_anon_article_js') {
global $parserMemc, $wgStyleVersion, $wgEnableViewYUI;
$cb = $parserMemc->get(wfMemcKey('wgMWrevId'));
$addParam = "";
if (!empty($wgEnableViewYUI)) {
$addParam = "&yui=1";
}
global $wgDevelEnvironment;
if(empty($wgDevelEnvironment)){
$prefix = "__wikia_combined/";
} else {
global $wgWikiaCombinedPrefix;
$prefix = $wgWikiaCombinedPrefix;
}
$jsReferences[] = "/{$prefix}cb={$cb}{$wgStyleVersion}&type=CoreJS";
} else {
$jsHtml = $StaticChute->getChuteHtmlForPackage($package);
if ($package == "monaco_anon_article_js") {
$jsHtml .= $StaticChute->getChuteHtmlForPackage("yui");
}
// get URL of StaticChute package (or a list of separated files) and use WSL to load it
preg_match_all("/src=\"([^\"]+)/", $jsHtml, $matches, PREG_SET_ORDER);
foreach($matches as $script) {
$jsReferences[] = str_replace('&', '&', $script[1]);
}
}*/
/*
// scripts from getReferencesLinks() method
foreach($tpl->data['references']['js'] as $script) {
if (!empty($script['url'])) {
$url = $script['url'];
/*if($allinone && $package == 'monaco_anon_article_js' && strpos($url, 'title=-') > 0) {
continue;
}*//*
$jsReferences[] = $url;
}
}
/*
// scripts from $wgOut->mScripts
// <script type="text/javascript" src="URL"></script>
// load them using WSL and remove from $wgOut->mScripts
//
// macbre: Perform only for Monaco skin! New Answers skin does not use WikiaScriptLoader
if ((get_class($this) == 'SkinMonaco') || (get_class($this) == 'SkinAnswers')) {
global $wgJsMimeType;
$headScripts = $tpl->data['headscripts'];
preg_match_all("#<script type=\"{$wgJsMimeType}\" src=\"([^\"]+)\"></script>#", $headScripts, $matches, PREG_SET_ORDER);
foreach($matches as $script) {
$jsReferences[] = str_replace('&', '&', $script[1]);
$headScripts = str_replace($script[0], '', $headScripts);
}
$tpl->data['headscripts'] = $headScripts;
// generate code to load JS files
$jsReferences = Wikia::json_encode($jsReferences);
$jsLoader = <<<EOF
<script type="text/javascript">/*<![CDATA[* /
(function(){
var jsReferences = $jsReferences;
var len = jsReferences.length;
for(var i=0; i<len; i++)
wsl.loadScript(jsReferences[i]);
})();
/*]]>* /</script>
EOF;
$tpl->set('JSloader', $jsLoader);
}
wfProfileOut(__METHOD__ . '::JSloader');
*/
// macbre: move media="print" CSS to bottom (RT #25638)
//global $wgOut;
/*
wfProfileIn(__METHOD__ . '::printCSS');
$tmpOut = new OutputPage();
$printStyles = array();
/*
// let's filter media="print" CSS out
$tmpOut->styles = $wgOut->styles;
foreach($tmpOut->styles as $style => $options) {
if (isset($options['media']) && $options['media'] == 'print') {
unset($tmpOut->styles[$style]);
$printStyles[$style] = $options;
}
}*/
/*
// re-render CSS to be included in head
$tpl->set('csslinks-urls', $tmpOut->styles);
$tpl->set('csslinks', $tmpOut->buildCssLinks());
// render CSS to be included at the bottom
$tmpOut->styles = $printStyles;
$tpl->set('csslinksbottom-urls', $printStyles);
$tpl->set('csslinksbottom', $tmpOut->buildCssLinks());
*/
//wfProfileOut(__METHOD__ . '::printCSS');
wfProfileOut( __METHOD__ );
return true;
}
/**
* @author Inez Korczynski <[email protected]>
*/
private function parseToolboxLinks($lines) {
$nodes = array();
if(is_array($lines)) {
foreach($lines as $line) {
$trimmed = trim($line, ' *');
if (strlen($trimmed) == 0) { # ignore empty lines
continue;
}
$item = MonacoSidebar::parseItem($trimmed);
$nodes[] = $item;
}
}
return $nodes;
}
/**
* @author Inez Korczynski <[email protected]>
*/
private function getLines($message_key) {
$revision = Revision::newFromTitle(Title::newFromText($message_key, NS_MEDIAWIKI));
if(is_object($revision)) {
if(trim($revision->getText()) != '') {
$temp = MonacoSidebar::getMessageAsArray($message_key);
if(count($temp) > 0) {
wfDebugLog('monaco', sprintf('Get LOCAL %s, which contains %s lines', $message_key, count($temp)));
$lines = $temp;
}
}
}
if(empty($lines)) {
$lines = MonacoSidebar::getMessageAsArray($message_key);
wfDebugLog('monaco', sprintf('Get %s, which contains %s lines', $message_key, count($lines)));
}
return $lines;
}
/**
* @author Inez Korczynski <[email protected]>
*/
private function getToolboxLinks() {
return $this->parseToolboxLinks($this->getLines('Monaco-toolbox'));
}
var $lastExtraIndex = 1000;
/**
* @author Inez Korczynski <[email protected]>
*/
private function addExtraItemsToSidebarMenu(&$node, &$nodes) {
wfProfileIn( __METHOD__ );
$extraWords = array(
'#voted#' => array('highest_ratings', 'GetTopVotedArticles'),
'#popular#' => array('most_popular', 'GetMostPopularArticles'),
'#visited#' => array('most_visited', 'GetMostVisitedArticles'),
'#newlychanged#' => array('newly_changed', 'GetNewlyChangedArticles'),
'#topusers#' => array('community', 'GetTopFiveUsers'));
if(isset($extraWords[strtolower($node['org'])])) {
if(substr($node['org'],0,1) == '#') {
if(strtolower($node['org']) == strtolower($node['text'])) {
$node['text'] = wfMessage(trim(strtolower($node['org']), ' *')->text());
}
$node['magic'] = true;
}
$results = DataProvider::$extraWords[strtolower($node['org'])][1]();
$results[] = array('url' => SpecialPage::getTitleFor('Top/'.$extraWords[strtolower($node['org'])][0])->getLocalURL(), 'text' => strtolower(wfMessage('moredotdotdot')->text()), 'class' => 'Monaco-sidebar_more');
global $wgUser;
if( $wgUser->isAllowed( 'editinterface' ) ) {
if(strtolower($node['org']) == '#popular#') {
$results[] = array('url' => Title::makeTitle(NS_MEDIAWIKI, 'Most popular articles')->getLocalUrl(), 'text' => wfMessage('monaco-edit-this-menu')->text(), 'class' => 'Monaco-sidebar_edit');
}
}
foreach($results as $key => $val) {
$node['children'][] = $this->lastExtraIndex;
$nodes[$this->lastExtraIndex]['text'] = $val['text'];
$nodes[$this->lastExtraIndex]['href'] = $val['url'];
if(!empty($val['class'])) {
$nodes[$this->lastExtraIndex]['class'] = $val['class'];
}
$this->lastExtraIndex++;
}
}
wfProfileOut( __METHOD__ );
}
/**
* @author Inez Korczynski <[email protected]>
*/
private function parseSidebarMenu($lines) {
wfProfileIn(__METHOD__);
$nodes = array();
$nodes[] = array();
$lastDepth = 0;
$i = 0;
if(is_array($lines)) {
foreach($lines as $line) {
if (strlen($line) == 0) { # ignore empty lines
continue;
}
$node = MonacoSidebar::parseItem($line);
$node['depth'] = strrpos($line, '*') + 1;
if($node['depth'] == $lastDepth) {
$node['parentIndex'] = $nodes[$i]['parentIndex'];
} else if ($node['depth'] == $lastDepth + 1) {
$node['parentIndex'] = $i;
} else {
for($x = $i; $x >= 0; $x--) {
if($x == 0) {
$node['parentIndex'] = 0;
break;
}
if($nodes[$x]['depth'] == $node['depth'] - 1) {
$node['parentIndex'] = $x;
break;
}
}
}
if(substr($node['org'],0,1) == '#') {
$this->addExtraItemsToSidebarMenu($node, $nodes);
}
$nodes[$i+1] = $node;
$nodes[$node['parentIndex']]['children'][] = $i+1;
$lastDepth = $node['depth'];
$i++;
}
}
wfProfileOut(__METHOD__);
return $nodes;
}
/**
* @author Inez Korczynski <[email protected]>
*/
private function getSidebarLinks() {
return $this->parseSidebarMenu($this->getLines('Monaco-sidebar'));
}
/**
* @author Inez Korczynski <[email protected]>
*/
private function getTransformedArticle($name, $asArray = false) {
wfProfileIn(__METHOD__);
global $wgParser, $wgMessageCache;
$revision = Revision::newFromTitle(Title::newFromText($name));
if(is_object($revision)) {
$text = $revision->getText();
if(!empty($text)) {
$ret = $wgParser->transformMsg($text, $wgMessageCache->getParserOptions());
if($asArray) {
$ret = explode("\n", $ret);
}
wfProfileOut(__METHOD__);
return $ret;
}
}
wfProfileOut(__METHOD__);
return null;
}
/**
* Create arrays containing articles links (separated arrays for left and right part)
* Based on data['content_actions']
*
* @return array
* @author Inez Korczynski <[email protected]>
*/
private function getArticleLinks($tpl) {
wfProfileIn( __METHOD__ );
$links = array();
if ( isset($tpl->data['content_navigation']) ) {
// Use MediaWiki 1.18's better vector based content_navigation structure
// to organize our tabs better
foreach ( $tpl->data['content_navigation'] as $section => $nav ) {
foreach ( $nav as $key => $val ) {
if ( isset($val["redundant"]) && $val["redundant"] ) {
continue;
}
$kk = ( isset($val["id"]) && substr($val["id"], 0, 3) == "ca-" ) ? substr($val["id"], 3) : $key;
$msgKey = $kk;
if ( $kk == "edit" ) {
$title = $this->getRelevantTitle();
$msgKey = $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && wfMessage( $title->getText() )->exists() )
? "edit" : "create";
}
if ( !wfMessage("monaco-tab-$msgKey")->isDisabled() ) {
$val["text"] = wfMessage("monaco-tab-$msgKey")->text();
}
switch($section) {
case "namespaces": $side = 'right'; break;
case "variants": $side = 'variants'; break;
default: $side = 'left'; break;
}
$links[$side][$kk] = $val;
}
}
} else {
// rarely ever happens, but it does
if ( empty( $tpl->data['content_actions'] ) ) {
return $links;
}
# @todo: might actually be useful to move this to a global var and handle this in extension files --TOR
$force_right = array( 'userprofile', 'talk', 'TheoryTab' );
foreach($tpl->data['content_actions'] as $key => $val) {
$msgKey = $key;
if ( $key == "edit" ) {
$msgKey = $this->mTitle->exists() || ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && wfMessage( $this->mTitle->getText() )->exists() )
? "edit" : "create";
}
$tabText = wfMessage("monaco-tab-$msgKey")->text();
if ( $tabText && $tabText != '-' && wfMessage("monaco-tab-$msgKey")->exists() ) {
$val["text"] = $tabText;
}
if ( strpos($key, 'varlang-') === 0 ) {
$links['variants'][$key] = $val;
} else if ( strpos($key, 'nstab-') === 0 || in_array($key, $force_right) ) {
$links['right'][$key] = $val;
} else {
$links['left'][$key] = $val;
}
}
}
if ( isset($links['left']) ) {
foreach ( $links['left'] as $key => &$v ) {
/* Fix icons */
if($key == 'unprotect') {
//unprotect uses the same icon as protect
$v['icon'] = 'protect';
} else if ($key == 'undelete') {
//undelete uses the same icon as delelte
$v['icon'] = 'delete';
} else if ($key == 'purge') {
$v['icon'] = 'refresh';
} else if ($key == 'addsection') {
$v['icon'] = 'talk';
}
}
}
wfProfileOut( __METHOD__ );
return $links;
}
/**
* Generate links for user menu - depends on if user is logged in or not
*
* @return array
* @author Inez Korczynski <[email protected]>
*/
private function getUserLinks($tpl) {
wfProfileIn( __METHOD__ );
global $wgUser, $wgTitle, $wgRequest;
$data = array();
$page = Title::newFromURL( $wgRequest->getVal( 'title', '' ) );
$page = $wgRequest->getVal( 'returnto', $page );
$a = array();
if ( strval( $page ) !== '' ) {
$a['returnto'] = $page;
$query = $wgRequest->getVal( 'returntoquery', $this->thisquery );
if( $query != '' ) {
$a['returntoquery'] = $query;
}
}
$returnto = wfArrayToCGI( $a );
if(!$wgUser->isLoggedIn()) {
$signUpHref = Skin::makeSpecialUrl( 'Userlogin', $returnto );
$data['login'] = array(
'text' => wfMessage('login')->text(),
'href' => $signUpHref . "&type=login"
);
$data['register'] = array(
'text' => wfMessage('nologinlink')->text(),
'href' => $signUpHref . "&type=signup"
);
} else {
$data['userpage'] = array(
'text' => $wgUser->getName(),
'href' => $tpl->data['personal_urls']['userpage']['href']
);
$data['mytalk'] = array(
'text' => $tpl->data['personal_urls']['mytalk']['text'],
'href' => $tpl->data['personal_urls']['mytalk']['href']
);
if (isset($tpl->data['personal_urls']['watchlist'])) {
$data['watchlist'] = array(
/*'text' => $tpl->data['personal_urls']['watchlist']['text'],*/
'text' => wfMessage('prefs-watchlist')->text(),
'href' => $tpl->data['personal_urls']['watchlist']['href']
);
}
// In some cases, logout will be removed explicitly (such as when it is replaced by fblogout).
if(isset($tpl->data['personal_urls']['logout'])){
$data['logout'] = array(
'text' => $tpl->data['personal_urls']['logout']['text'],
'href' => $tpl->data['personal_urls']['logout']['href']
);
}
$data['more']['userpage'] = array(
'text' => wfMessage('mypage')->text(),
'href' => $tpl->data['personal_urls']['userpage']['href']
);
if(isset($tpl->data['personal_urls']['userprofile'])) {
$data['more']['userprofile'] = array(
'text' => $tpl->data['personal_urls']['userprofile']['text'],
'href' => $tpl->data['personal_urls']['userprofile']['href']
);
}
$data['more']['mycontris'] = array(
'text' => wfMessage('mycontris')->text(),
'href' => $tpl->data['personal_urls']['mycontris']['href']
);
$data['more']['preferences'] = array(
'text' => $tpl->data['personal_urls']['preferences']['text'],
'href' => $tpl->data['personal_urls']['preferences']['href']
);
}
// This function ignores anything from PersonalUrls hook which it doesn't expect. This
// loops lets it expect anything starting with "fb*" (because we need that for facebook connect).
// Perhaps we should have some system to let PersonalUrls hook work again on its own?
// - Sean Colombo
foreach($tpl->data['personal_urls'] as $urlName => $urlData){
if(strpos($urlName, "fb") === 0){
$data[$urlName] = $urlData;
}
}
wfProfileOut( __METHOD__ );
return $data;
}
} // end SkinMonaco
class MonacoTemplate extends QuickTemplate {
/*
* Build returnto parameter with new returntoquery from MW 1.16
*
* @author Marooned
* @return string
*/
static function getReturntoParam($customReturnto = null) {
global $wgTitle, $wgRequest;
if ($customReturnto) {
$returnto = "returnto=$customReturnto";
} else {
$thisurl = $wgTitle->getPrefixedURL();
$returnto = "returnto=$thisurl";
}
if (!$wgRequest->wasPosted()) {
$query = $wgRequest->getValues();
unset($query['title']);
unset($query['returnto']);
unset($query['returntoquery']);
$thisquery = wfUrlencode(wfArrayToCGI($query));
if($thisquery != '')
$returnto .= "&returntoquery=$thisquery";
}
return $returnto;
}
/**
* Shortcut for building these crappy blankimg based icons wikia probably could
* have implemented in a less ugly way.
* @author Daniel Friesen
*/
function blankimg( $attrs = array() ) {
return Html::element( 'img', array( "src" => $this->data['blankimg'] ) + $attrs );
}
/**
* Make this a method so that subskins can override this if they reorganize
* the user header and need the more button to function.
*
* @author Daniel Friesen
*/
function useUserMore() {
global $wgMonacoUseMoreButton;
return $wgMonacoUseMoreButton;
}
function execute() {
wfProfileIn( __METHOD__ );
global $wgContLang, $wgArticle, $wgUser, $wgLogo, $wgStyleVersion, $wgRequest, $wgTitle, $wgSitename;
global $wgMonacoUseSitenoticeIsland;
/*$skin = $wgUser->getSkin();
$namespace = $wgTitle->getNamespace();*/
$skin = $this->data['skin'];
$action = $wgRequest->getText('action');
$namespace = $wgTitle->getNamespace();
$this->set( 'blankimg', $this->data['stylepath'].'/monaco/style/images/blank.gif' );
// Suppress warnings to prevent notices about missing indexes in $this->data
wfSuppressWarnings();
$this->setupRightSidebar();
ob_start();
wfRunHooks('MonacoRightSidebar', array($this));
$this->addToRightSidebar( ob_get_contents() );
ob_end_clean();
$this->html( 'headelement' );
/*
$allinone = $wgRequest->getBool('allinone', $wgAllInOne);
echo WikiaAssets::GetCoreCSS($skin->themename, $wgContLang->isRTL(), $allinone); // StaticChute + browser specific
echo WikiaAssets::GetExtensionsCSS($this->data['csslinks-urls']);
echo WikiaAssets::GetThemeCSS($skin->themename, $skin->skinname);
echo WikiaAssets::GetSiteCSS($skin->themename, $wgContLang->isRTL(), $allinone); // Common.css, Monaco.css, -
echo WikiaAssets::GetUserCSS($this->data['csslinks-urls']);
*/
$this->printAdditionalHead(); // @fixme not valid
?>
<?php wfProfileOut( __METHOD__ . '-head'); ?>
<?php
wfProfileIn( __METHOD__ . '-body'); ?>
<?php
// this hook allows adding extra HTML just after <body> opening tag
// append your content to $html variable instead of echoing
$html = '';
wfRunHooks('GetHTMLAfterBody', array ($this, &$html));
echo $html;
?>
<div id="skiplinks">
<a class="skiplink" href="#article" tabIndex=1>Skip to Content</a>
<a class="skiplink wikinav" href="#widget_sidebar" tabIndex=1>Skip to Navigation</a>
</div>
<div id="background_accent1"></div>
<div id="background_accent2"></div>
<!-- HEADER -->
<?php
// curse like cobranding
$this->printCustomHeader();
wfProfileIn( __METHOD__ . '-header'); ?>
<div id="wikia_header" class="color2">
<div class="monaco_shrinkwrap">
<?php $this->printMonacoBranding(); ?>
<?php $this->printUserData(); ?>
</div>
</div>
<?php if (wfRunHooks('AlternateNavLinks')): ?>
<div id="background_strip" class="reset">
<div class="monaco_shrinkwrap">
<div id="accent_graphic1"></div>
<div id="accent_graphic2"></div>
</div>
</div>
<?php endif; ?>
<!-- /HEADER -->
<?php wfProfileOut( __METHOD__ . '-header'); ?>
<!-- PAGE -->
<?php wfProfileIn( __METHOD__ . '-page'); ?>
<div id="monaco_shrinkwrap_main" class="monaco_shrinkwrap with_left_sidebar<?php if ( $this->hasRightSidebar() ) { echo ' with_right_sidebar'; } ?>">
<div id="page_wrapper">
<?php wfRunHooks('MonacoBeforePage', array($this)); ?>
<?php $this->printBeforePage(); ?>
<?php if ( $wgMonacoUseSitenoticeIsland && $this->data['sitenotice'] ) { ?>
<div class="page">
<div id="siteNotice"><?php $this->html('sitenotice') ?></div>
</div>
<?php } ?>
<div id="wikia_page" class="page">
<?php
$this->printMasthead();
wfRunHooks('MonacoBeforePageBar', array($this));
$this->printPageBar(); ?>
<!-- ARTICLE -->
<?php wfProfileIn( __METHOD__ . '-article'); ?>
<article id="article" aria-role=main aria-labeledby="firstHeading">
<a name="top" id="top"></a>
<?php wfRunHooks('MonacoAfterArticle', array($this)); // recipes: not needed? ?>
<?php if ( !$wgMonacoUseSitenoticeIsland && $this->data['sitenotice'] ) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>
<?php $this->printFirstHeading(); ?>
<div id="bodyContent" class="body_content">
<h2 id="siteSub"><?php $this->msg('tagline') ?></h2>
<?php if($this->data['subtitle']) { ?><div id="contentSub"><?php $this->html('subtitle') ?></div><?php } ?>
<?php if($this->data['undelete']) { ?><div id="contentSub2"><?php $this->html('undelete') ?></div><?php } ?>
<?php if($this->data['newtalk'] ) { ?><div class="usermessage noprint"><?php $this->html('newtalk') ?></div><?php } ?>
<?php if(!empty($skin->newuemsg)) { echo $skin->newuemsg; } ?>