From: Ryan Schmidt Date: Sun, 5 Oct 2008 21:28:11 +0000 (+0000) Subject: * fixing DismissSiteNotice so that it works properly with javascript-disabled browsers X-Git-Tag: 1.31.0-rc.0~44904 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=a235f130a66669d21982d9ed6563a933b9165788;p=lhc%2Fweb%2Fwiklou.git * fixing DismissSiteNotice so that it works properly with javascript-disabled browsers * make DismissSiteNotice honor cookie configuration variables * adding missing name to CREDITS --- diff --git a/CREDITS b/CREDITS index 2c418e1e9a..c91eb79a0d 100644 --- a/CREDITS +++ b/CREDITS @@ -18,6 +18,7 @@ following names for their contribution to the product. * Greg Sabino Mullane * Guy Van den Broeck * Hojjat +* Jack Phoenix * Jon Harald Søby * Leon Weber * Matt Johnston diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 2402204e04..6034237b57 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1864,11 +1864,14 @@ function wfGetNamespaceNotice() { * @return $siteNotice The site-wide notice as set by $wgSiteNotice or MediaWiki:Sitenotice interface message */ function wfGetSiteNotice() { - global $wgUser, $wgSiteNotice, $wgMajorSiteNoticeID; + global $wgUser, $wgMajorSiteNoticeID, $wgTitle; + global $wgCookiePrefix, $wgCookieExpiration, $wgCookiePath; $fname = 'wfGetSiteNotice'; wfProfileIn( $fname ); $siteNotice = ''; $loggedIn = false; + $spTitle = SpecialPage::getTitleFor('DismissNotice'); + $spUrl = $spTitle->getFullURL( array( 'returnto' => $wgTitle->getPrefixedURL() ) ); if( $wgUser instanceOf User && $wgUser->isLoggedIn() ) { $loggedIn = true; @@ -1884,53 +1887,35 @@ function wfGetSiteNotice() { } } - $encNotice = Xml::escapeJsString($siteNotice); - $encClose = Xml::escapeJsString( wfMsg( 'sitenotice_close' ) ); + $msgClose = wfMsg( 'sitenotice_close' ); $id = intval( $wgMajorSiteNoticeID ) . "." . intval( wfMsgForContent( 'sitenotice_id' ) ); if( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice ) ) ) { if( $loggedIn ) { + //it is hidden + if( isset($_COOKIE[$wgCookiePrefix . 'DismissSiteNotice']) && $_COOKIE[$wgCookiePrefix . 'DismissSiteNotice'] == $id ) + return ''; $siteNotice = <<$siteNotice +[$msgClose] -EOT; - } else { - // Don't allow anons to dismiss the site notice - $siteNotice = << - - EOT; } if( !$siteNotice ) { diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index cf16546570..37650bb18e 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -157,7 +157,8 @@ class SpecialPage 'Randomredirect' => 'SpecialRandomredirect', 'Withoutinterwiki' => array( 'SpecialPage', 'Withoutinterwiki' ), 'Filepath' => array( 'SpecialPage', 'Filepath' ), - + 'Dismissnotice' => array( 'UnlistedSpecialPage', 'Dismissnotice' ), + 'Mypage' => array( 'SpecialMypage' ), 'Mytalk' => array( 'SpecialMytalk' ), 'Mycontributions' => array( 'SpecialMycontributions' ), diff --git a/includes/specials/SpecialDismissnotice.php b/includes/specials/SpecialDismissnotice.php new file mode 100644 index 0000000000..6099a87a35 --- /dev/null +++ b/includes/specials/SpecialDismissnotice.php @@ -0,0 +1,31 @@ +isAnon()) { + $wgOut->addWikiText( wfMsg('dismissnotice-nologin') ); + return; + } + + # Set the cookie and redirect back to where they came from (or Main Page if they just typed it in the URL) + $id = intval( $wgMajorSiteNoticeID ) . "." . intval( wfMsgForContent( 'sitenotice_id' ) ); + #not using WebResponse's setcookie method because the cookie cannot be httpOnly + setcookie( $wgCookiePrefix . 'DismissSiteNotice', + $id, + time() + $wgCookieExpiration, + $wgCookiePath, + $wgCookieDomain, + false, + false + ); + + $titleObj = Title::newFromText( $wgRequest->getVal('returnto') ); + if ( !$titleObj instanceof Title ) { + $titleObj = Title::newMainPage(); + } + + $wgOut->redirect( $titleObj->getFullURL() ); +} \ No newline at end of file diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 24ee31b9d7..73293d9f98 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -441,6 +441,7 @@ $specialPageAliases = array( 'LinkSearch' => array( 'LinkSearch' ), 'DeletedContributions' => array( 'DeletedContributions' ), 'Nuke' => array( 'Nuke' ), + 'DismissNotice' => array( 'DismissNotice' ), ); /** @@ -3687,4 +3688,7 @@ Input the username or IP to get a list of pages to delete.', 'nuke-submit-delete' => 'Delete selected', 'right-nuke' => 'Mass delete pages', +# Special:DismissNotice +'dismissnotice' => 'Dismiss site notice', +'dismissnotice-nologin' => 'You must be [[Special:UserLogin|logged in]] to dismiss the site notice.', );