Index: branches/on_wiki_configuration/includes/User.php |
— | — | @@ -168,6 +168,8 @@ |
169 | 169 | 'upload', |
170 | 170 | 'upload_by_url', |
171 | 171 | 'userrights', |
| 172 | + 'setlogo', |
| 173 | + 'grouprights' |
172 | 174 | ); |
173 | 175 | /** |
174 | 176 | * \string Cached results of getAllRights() |
Index: branches/on_wiki_configuration/includes/GlobalFunctions.php |
— | — | @@ -2969,3 +2969,27 @@ |
2970 | 2970 | $name = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $name ); |
2971 | 2971 | return $name; |
2972 | 2972 | } |
| 2973 | + |
| 2974 | +/** |
| 2975 | + * Gets the path to the site logo. |
| 2976 | + */ |
| 2977 | +function wfGetLogoPath( $checkDB = true ) { |
| 2978 | + ## In order of precedence: |
| 2979 | + ## Configuration cache, database, $wgLogo, default location. |
| 2980 | + |
| 2981 | + if ( $filename = ConfigurationCache::get( 'logo' ) ) { |
| 2982 | + ## They specified an image name. |
| 2983 | + $logo_file = wfFindFile( $filename ); |
| 2984 | + return $logo_file->getThumbnail(130, 130)->url; |
| 2985 | + } |
| 2986 | + |
| 2987 | + global $wgLogo; |
| 2988 | + |
| 2989 | + if ($wgLogo) { |
| 2990 | + return $wgLogo; |
| 2991 | + } |
| 2992 | + |
| 2993 | + global $wgStylePath; |
| 2994 | + |
| 2995 | + return "$wgStylePath/common/images/wiki.png"; |
| 2996 | +} |
\ No newline at end of file |
Index: branches/on_wiki_configuration/includes/ConfigurationCache.php |
— | — | @@ -0,0 +1,56 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +if (!defined('MEDIAWIKI')) |
| 5 | + die(); |
| 6 | + |
| 7 | +## Simple class for caching configuration data which needs to be retrieved per-pageview. |
| 8 | + |
| 9 | +class ConfigurationCache { |
| 10 | + static $data = false; |
| 11 | + static $dirty = false; |
| 12 | + |
| 13 | + static function load() { |
| 14 | + if (self::$data !== false) { |
| 15 | + return; |
| 16 | + } |
| 17 | + |
| 18 | + global $wgMemc; |
| 19 | + |
| 20 | + self::$data = $wgMemc->get( wfMemcKey( 'configuration-cache' ) ); |
| 21 | + self::$dirty = false; |
| 22 | + |
| 23 | + if ( !is_array( self::$data ) ) { |
| 24 | + self::$data = array(); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + static function get( $key ) { |
| 29 | + self::load(); |
| 30 | + |
| 31 | + return @self::$data[$key]; |
| 32 | + } |
| 33 | + |
| 34 | + static function set( $key, $value ) { |
| 35 | + self::load(); |
| 36 | + |
| 37 | + self::$data[$key] = $value; |
| 38 | + self::$dirty = true; |
| 39 | + } |
| 40 | + |
| 41 | + static function delete( $key ) { |
| 42 | + self::load(); |
| 43 | + |
| 44 | + unset( self::$data[$key] ); |
| 45 | + self::$dirty = true; |
| 46 | + } |
| 47 | + |
| 48 | + static function save( ) { |
| 49 | + if (!self::$dirty) { |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + global $wgMemc; |
| 54 | + |
| 55 | + $wgMemc->set( wfMemcKey( 'configuration-cache' ), self::$data, 86400 ); |
| 56 | + } |
| 57 | +} |
\ No newline at end of file |
Index: branches/on_wiki_configuration/includes/Setup.php |
— | — | @@ -42,8 +42,6 @@ |
43 | 43 | if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins"; |
44 | 44 | if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins"; |
45 | 45 | |
46 | | -if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png"; |
47 | | - |
48 | 46 | if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images"; |
49 | 47 | if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images"; |
50 | 48 | |
Index: branches/on_wiki_configuration/includes/AutoLoader.php |
— | — | @@ -30,6 +30,7 @@ |
31 | 31 | 'ChangesFeed' => 'includes/ChangesFeed.php', |
32 | 32 | 'ChannelFeed' => 'includes/Feed.php', |
33 | 33 | 'ConcatenatedGzipHistoryBlob' => 'includes/HistoryBlob.php', |
| 34 | + 'ConfigurationCache' => 'includes/ConfigurationCache.php', |
34 | 35 | 'ConstantDependency' => 'includes/CacheDependency.php', |
35 | 36 | 'CreativeCommonsRdf' => 'includes/Metadata.php', |
36 | 37 | 'Credits' => 'includes/Credits.php', |
— | — | @@ -485,6 +486,7 @@ |
486 | 487 | 'SpecialBookSources' => 'includes/specials/SpecialBooksources.php', |
487 | 488 | 'SpecialGroupRights' => 'includes/specials/SpecialGroupRights.php', |
488 | 489 | 'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php', |
| 490 | + 'SpecialSetLogo' => 'includes/specials/SpecialSetLogo.php', |
489 | 491 | 'SpecialMostlinkedtemplates' => 'includes/specials/SpecialMostlinkedtemplates.php', |
490 | 492 | 'SpecialPrefixindex' => 'includes/specials/SpecialPrefixindex.php', |
491 | 493 | 'SpecialRandomredirect' => 'includes/specials/SpecialRandomredirect.php', |
Index: branches/on_wiki_configuration/includes/SkinTemplate.php |
— | — | @@ -138,7 +138,7 @@ |
139 | 139 | global $wgScript, $wgStylePath, $wgContLanguageCode; |
140 | 140 | global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest; |
141 | 141 | global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces; |
142 | | - global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks; |
| 142 | + global $wgDisableCounters, $action, $wgFeedClasses, $wgHideInterlanguageLinks; |
143 | 143 | global $wgMaxCredits, $wgShowCreditsIfMax; |
144 | 144 | global $wgPageShowWatchingUsers; |
145 | 145 | global $wgUseTrackbacks, $wgUseSiteJs; |
— | — | @@ -263,7 +263,7 @@ |
264 | 264 | $tpl->setRef( 'articlepath', $wgArticlePath ); |
265 | 265 | $tpl->setRef( 'scriptpath', $wgScriptPath ); |
266 | 266 | $tpl->setRef( 'serverurl', $wgServer ); |
267 | | - $tpl->setRef( 'logopath', $wgLogo ); |
| 267 | + $tpl->setRef( 'logopath', wfGetLogoPath() ); |
268 | 268 | $tpl->setRef( "lang", $wgContLanguageCode ); |
269 | 269 | $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" ); |
270 | 270 | $tpl->set( 'rtl', $wgContLang->isRTL() ); |
Index: branches/on_wiki_configuration/includes/specials/SpecialSetLogo.php |
— | — | @@ -0,0 +1,104 @@ |
| 2 | +<?php |
| 3 | +if (!defined('MEDIAWIKI')) |
| 4 | + die(); |
| 5 | + |
| 6 | +class SpecialSetLogo extends SpecialPage { |
| 7 | + function __construct( ) { |
| 8 | + parent::__construct( 'SetLogo', 'setlogo' ); |
| 9 | + } |
| 10 | + |
| 11 | + function execute() { |
| 12 | + global $wgUser, $wgOut; |
| 13 | + |
| 14 | + $sk = $wgUser->getSkin(); |
| 15 | + |
| 16 | + if (!$this->userCanExecute($wgUser)) { |
| 17 | + $this->displayRestrictionError(); |
| 18 | + return; |
| 19 | + } |
| 20 | + |
| 21 | + $wgOut->setPageTitle( wfMsg( 'setlogo' ) ); |
| 22 | + |
| 23 | + if ( $this->trySubmit() ) { |
| 24 | + return; |
| 25 | + } |
| 26 | + |
| 27 | + if (!$this->mLogo) { |
| 28 | + $this->mLogo = ConfigurationCache::get( 'logo' ); |
| 29 | + } |
| 30 | + |
| 31 | + $wgOut->addWikiMsg( 'setlogo-intro' ); |
| 32 | + |
| 33 | + ## Build form |
| 34 | + $fields = array( 'setlogo-file' => wfInput( 'wpNewLogo', 45, $this->mLogo ) ); |
| 35 | + $form = Xml::buildForm( $fields, 'setlogo-preview-button' ); |
| 36 | + $form .= Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ); |
| 37 | + $form .= Xml::hidden( 'action', 'preview' ); |
| 38 | + $form = Xml::tags( 'form', array( 'action' => $this->getTitle()->getLocalURL(), 'method' => 'post' ), $form ); |
| 39 | + $form = Xml::fieldset( wfMsg( 'setlogo-fieldset' ), $form ); |
| 40 | + |
| 41 | + $wgOut->addHTML( $form ); |
| 42 | + } |
| 43 | + |
| 44 | + function trySubmit() { |
| 45 | + global $wgRequest, $wgUser, $wgOut; |
| 46 | + |
| 47 | + $sk = $wgUser->getSkin(); |
| 48 | + |
| 49 | + $action = $wgRequest->getVal( 'action' ); |
| 50 | + $this->mLogo = $selection = $wgRequest->getText( 'wpNewLogo' ); |
| 51 | + $tokenOK = $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), 'setlogo', $selection ); |
| 52 | + |
| 53 | + if ($action == 'success') { |
| 54 | + ## We've successfully set the logo |
| 55 | + $wgOut->addWikiMsg( 'setlogo-success' ); |
| 56 | + return true; |
| 57 | + } |
| 58 | + |
| 59 | + ## Sanity check on $selection |
| 60 | + if (!$selection) { |
| 61 | + return false; |
| 62 | + } |
| 63 | + |
| 64 | + $file = wfFindFile( $selection ); |
| 65 | + |
| 66 | + if ( !$file || !$file->exists() ) { |
| 67 | + $error = wfMsgExt( 'setlogo-notfound', array( 'parseinline' ) ); |
| 68 | + $error = Xml::tags( 'div', array( 'class' => 'error' ), $error ); |
| 69 | + |
| 70 | + $wgOut->addHTML( $error ); |
| 71 | + return false; |
| 72 | + } |
| 73 | + |
| 74 | + if ($action == 'set' && $tokenOK ) { |
| 75 | + ## The file exists, we've confirmed it properly (evidenced by the edit token), etc. Everything seems sweet. |
| 76 | + ConfigurationCache::set( 'logo', $selection ); |
| 77 | + ConfigurationCache::save(); |
| 78 | + |
| 79 | + ## Redirect them -- we don't want to repeatedly purge the cache. |
| 80 | + $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) ); |
| 81 | + return true; |
| 82 | + } elseif ( $action == 'preview' || $action == 'set' ) { |
| 83 | + $wgOut->addWikiMsg( 'setlogo-confirm' ); |
| 84 | + $title = Title::makeTitle( NS_IMAGE, $selection ); |
| 85 | + |
| 86 | + $display = $sk->makeImageLink2( $title, $file, |
| 87 | + array('thumbnail' => 1, 'caption' => wfMsg('setlogo-confirm-caption'), 'align' => 'center' ), |
| 88 | + array( 'width' => 130, 'height' => 130 ) |
| 89 | + ); |
| 90 | + |
| 91 | + $wgOut->addHTML( $display ); |
| 92 | + |
| 93 | + $form = Xml::hidden( 'wpNewLogo', $selection ); |
| 94 | + $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken( 'setlogo', $selection ) ); |
| 95 | + $form .= Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ); |
| 96 | + $form .= Xml::hidden( 'action', 'set' ); |
| 97 | + $form .= Xml::submitButton( wfMsg( 'setlogo-confirm-button' ) ); |
| 98 | + $form = Xml::tags( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getFullURL(), 'class' => 'mw-setlogo-confirm' ), $form ); |
| 99 | + |
| 100 | + $wgOut->addHTML( $form ); |
| 101 | + |
| 102 | + return true; |
| 103 | + } |
| 104 | + } |
| 105 | +} |
\ No newline at end of file |
Index: branches/on_wiki_configuration/includes/RightsManager.php |
— | — | @@ -541,14 +541,8 @@ |
542 | 542 | function loadGroupPermissions( ) { |
543 | 543 | static $groupPerms = null; |
544 | 544 | |
545 | | - // In-process caching... |
546 | | - if ( is_array($groupPerms) ) { |
547 | | - return $groupPerms; |
548 | | - } |
549 | | - |
550 | | - // Memcached caching |
551 | | - global $wgMemc; |
552 | | - $groupPerms = $wgMemc->get( wfMemcKey( 'grouprights' ) ); |
| 545 | + // Caching... |
| 546 | + $groupPerms = ConfigurationCache::get( 'grouprights' ); |
553 | 547 | if ( is_array( $groupPerms ) ) { |
554 | 548 | return $groupPerms; |
555 | 549 | } |
— | — | @@ -564,7 +558,8 @@ |
565 | 559 | $groupPerms[$row->gr_group][$row->gr_right] = (bool)$row->gr_enabled; |
566 | 560 | } |
567 | 561 | |
568 | | - $wgMemc->set( wfMemcKey( 'grouprights' ), $groupPerms ); |
| 562 | + ConfigurationCache::set( 'grouprights', $groupPerms ); |
| 563 | + ConfigurationCache::save(); |
569 | 564 | |
570 | 565 | return $groupPerms; |
571 | 566 | } |
— | — | @@ -595,8 +590,7 @@ |
596 | 591 | return $changeableGroups; |
597 | 592 | } |
598 | 593 | |
599 | | - global $wgMemc; |
600 | | - $changeableGroups = $wgMemc->get( wfMemcKey( 'changeablegroups' ) ); |
| 594 | + $changeableGroups = ConfigurationCache::get( 'changeablegroups' ); |
601 | 595 | if ( is_array( $changeableGroups ) ) { |
602 | 596 | return $changeableGroups; |
603 | 597 | } |
— | — | @@ -627,7 +621,8 @@ |
628 | 622 | $changeableGroups[$group] = array_merge_recursive( $groupTemplate, $changeableGroups[$group] ); |
629 | 623 | } |
630 | 624 | |
631 | | - $wgMemc->set( wfMemcKey('changeablegroups'), $changeableGroups ); |
| 625 | + ConfigurationCache::set( 'changeablegroups', $changeableGroups ); |
| 626 | + ConfigurationCache::save(); |
632 | 627 | |
633 | 628 | return $changeableGroups; |
634 | 629 | } |
— | — | @@ -754,11 +749,10 @@ |
755 | 750 | $user->invalidateCache(); |
756 | 751 | } |
757 | 752 | |
758 | | - function invalidateGroupCache( $group ) { |
759 | | - global $wgMemc; |
760 | | - |
761 | | - $wgMemc->delete( wfMemcKey( 'changeablegroups' ) ); |
762 | | - $wgMemc->delete( wfMemcKey( 'grouprights' ) ); |
| 753 | + function invalidateGroupCache( $group ) { |
| 754 | + ConfigurationCache::delete( 'changeablegroups' ); |
| 755 | + ConfigurationCache::delete( 'grouprights' ); |
| 756 | + ConfigurationCache::save(); |
763 | 757 | } |
764 | 758 | |
765 | 759 | function invalidateUserCache( $user ) { |
Index: branches/on_wiki_configuration/includes/Skin.php |
— | — | @@ -676,8 +676,7 @@ |
677 | 677 | * URL to the logo |
678 | 678 | */ |
679 | 679 | function getLogo() { |
680 | | - global $wgLogo; |
681 | | - return $wgLogo; |
| 680 | + return wfGetLogoPath(); |
682 | 681 | } |
683 | 682 | |
684 | 683 | /** |
Index: branches/on_wiki_configuration/includes/SpecialPage.php |
— | — | @@ -159,6 +159,7 @@ |
160 | 160 | 'Randomredirect' => 'SpecialRandomredirect', |
161 | 161 | 'Withoutinterwiki' => array( 'SpecialPage', 'Withoutinterwiki' ), |
162 | 162 | 'Filepath' => array( 'SpecialPage', 'Filepath' ), |
| 163 | + 'SetLogo' => 'SpecialSetLogo', |
163 | 164 | |
164 | 165 | 'Mypage' => array( 'SpecialMypage' ), |
165 | 166 | 'Mytalk' => array( 'SpecialMytalk' ), |
Index: branches/on_wiki_configuration/includes/Exception.php |
— | — | @@ -189,7 +189,9 @@ |
190 | 190 | * $wgOut to output the exception. |
191 | 191 | */ |
192 | 192 | function htmlHeader() { |
193 | | - global $wgLogo, $wgSitename, $wgOutputEncoding; |
| 193 | + global $wgSitename, $wgOutputEncoding; |
| 194 | + |
| 195 | + $logo = wfGetLogoPath( 'skipdb' ); |
194 | 196 | |
195 | 197 | if ( !headers_sent() ) { |
196 | 198 | header( 'HTTP/1.0 500 Internal Server Error' ); |
— | — | @@ -204,7 +206,7 @@ |
205 | 207 | <title>$title</title> |
206 | 208 | </head> |
207 | 209 | <body> |
208 | | - <h1><img src='$wgLogo' style='float:left;margin-right:1em' alt=''>$title</h1> |
| 210 | + <h1><img src='$logo' style='float:left;margin-right:1em' alt=''>$title</h1> |
209 | 211 | "; |
210 | 212 | } |
211 | 213 | |
Index: branches/on_wiki_configuration/languages/messages/MessagesEn.php |
— | — | @@ -1649,6 +1649,7 @@ |
1650 | 1650 | 'right-userrights-interwiki' => 'Edit user rights of users on other wikis', |
1651 | 1651 | 'right-siteadmin' => 'Lock and unlock the database', |
1652 | 1652 | 'right-grouprights' => 'Edit permissions assigned to local groups', |
| 1653 | +'right-setlogo' => 'Change the site logo', |
1653 | 1654 | |
1654 | 1655 | # User rights log |
1655 | 1656 | 'rightslog' => 'User rights log', |
— | — | @@ -3777,4 +3778,15 @@ |
3778 | 3779 | |
3779 | 3780 | #Put all regex fragments above this line. Leave this line exactly as it is</pre>', |
3780 | 3781 | |
| 3782 | +# Special:SetLogo |
| 3783 | +'setlogo' => 'Set the site logo', |
| 3784 | +'setlogo-intro' => 'You can use this form to set the site logo.', |
| 3785 | +'setlogo-confirm' => 'Please click <tt>confirm logo selection</tt> to confirm that you wish to set the site logo to the image shown below.', |
| 3786 | +'setlogo-confirm-caption' => 'The new site logo', |
| 3787 | +'setlogo-confirm-button' => 'Confirm logo selection', |
| 3788 | +'setlogo-notfound' => "The image you selected doesn't seem to exist.", |
| 3789 | +'setlogo-file' => "Image to use as logo:<br/>''(excluding namespace)''", |
| 3790 | +'setlogo-preview-button' => 'Preview change', |
| 3791 | +'setlogo-fieldset' => 'Set the site logo', |
| 3792 | +'setlogo-success' => 'You have successfully set the site logo', |
3781 | 3793 | ); |