From: Brion Vibber Date: Fri, 25 Mar 2005 12:37:19 +0000 (+0000) Subject: * Move editsectiononrightclick setup to JavaScript (it requires JS anyway) X-Git-Tag: 1.5.0alpha1~528 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=fad4b5928dbf107585e7fbac561640252db87b9c;p=lhc%2Fweb%2Fwiklou.git * Move editsectiononrightclick setup to JavaScript (it requires JS anyway) This lets us use the same parser cache for both settings of this option. --- diff --git a/includes/EditPage.php b/includes/EditPage.php index 0606e2dbb8..b79cce8149 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -746,7 +746,6 @@ END $parserOptions = ParserOptions::newFromUser( $wgUser ); $parserOptions->setEditSection( false ); - $parserOptions->setEditSectionOnRightClick( false ); # don't parse user css/js, show message about preview # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here diff --git a/includes/Linker.php b/includes/Linker.php index 0c0f3d6b69..ce1bab5ef6 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -807,26 +807,6 @@ class Linker { . "
\n"; } - /** - * These two do not check for permissions: check $wgTitle->userCanEdit - * before calling them - */ - function editSectionScriptForOther( $title, $section, $head ) { - $ttl = Title::newFromText( $title ); - $url = $ttl->escapeLocalURL( 'action=edit§ion='.$section ); - return ''.$head.''; - } - - /** @todo document */ - function editSectionScript( $nt, $section, $head ) { - global $wgRequest; - if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) { - return $head; - } - $url = $nt->escapeLocalURL( 'action=edit§ion='.$section ); - return ''.$head.''; - } - /** @todo document */ function editSectionLinkForOther( $title, $section ) { global $wgRequest; diff --git a/includes/Parser.php b/includes/Parser.php index 060503cfcf..bba5a9169b 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -2195,10 +2195,8 @@ class Parser $forceTocHere = false; if( !$this->mTitle->userCanEdit() ) { $showEditLink = 0; - $rightClickHack = 0; } else { $showEditLink = $this->mOptions->getEditSection(); - $rightClickHack = $this->mOptions->getEditSectionOnRightClick(); } # Inhibit editsection links if requested in the page @@ -2389,14 +2387,6 @@ class Parser $head[$headlineCount] .= $sk->editSectionLink($this->mTitle, $sectionCount+1); } - # Add the edit section span - if( $rightClickHack ) { - if( $istemplate ) - $headline = $sk->editSectionScriptForOther($templatetitle, $templatesection, $headline); - else - $headline = $sk->editSectionScript($this->mTitle, $sectionCount+1,$headline); - } - # give headline the correct tag @$head[$headlineCount] .= "'; @@ -2988,7 +2978,6 @@ class ParserOptions var $mSkin; # Reference to the preferred skin var $mDateFormat; # Date format index var $mEditSection; # Create "edit section" links - var $mEditSectionOnRightClick; # Generate JavaScript to edit section on right click var $mNumberHeadings; # Automatically number headings function getUseTeX() { return $this->mUseTeX; } @@ -2998,7 +2987,6 @@ class ParserOptions function getSkin() { return $this->mSkin; } function getDateFormat() { return $this->mDateFormat; } function getEditSection() { return $this->mEditSection; } - function getEditSectionOnRightClick() { return $this->mEditSectionOnRightClick; } function getNumberHeadings() { return $this->mNumberHeadings; } function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); } @@ -3007,7 +2995,6 @@ class ParserOptions function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages, $x ); } function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); } function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); } - function setEditSectionOnRightClick( $x ) { return wfSetVar( $this->mEditSectionOnRightClick, $x ); } function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); } function setSkin( &$x ) { $this->mSkin =& $x; } @@ -3043,7 +3030,6 @@ class ParserOptions wfProfileOut( $fname.'-skin' ); $this->mDateFormat = $user->getOption( 'date' ); $this->mEditSection = $user->getOption( 'editsection' ); - $this->mEditSectionOnRightClick = $user->getOption( 'editsectiononrightclick' ); $this->mNumberHeadings = $user->getOption( 'numberheadings' ); wfProfileOut( $fname ); } diff --git a/includes/Skin.php b/includes/Skin.php index 9d63c40d02..de7777d919 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -330,6 +330,12 @@ END; } $a['onload'] = $wgOut->getOnloadHandler(); + if( $wgUser->getOption( 'editsectiononrightclick' ) ) { + if( $a['onload'] != '' ) { + $a['onload'] .= ';'; + } + $a['onload'] .= 'setupRightClickEdit()'; + } return $a; } @@ -595,7 +601,6 @@ END; global $wgOut, $wgTitle, $wgUser; $s = '

' . htmlspecialchars( $wgOut->getPageTitle() ) . '

'; - if($wgUser->getOption( 'editsectiononrightclick' ) && $wgTitle->userCanEdit()) { $s=$this->editSectionScript($wgTitle, 0,$s);} return $s; } diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 12029c6f6d..ede1ed8f9b 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -378,6 +378,11 @@ class SkinTemplate extends Skin { } else { $tpl->set('body_ondblclick', false); } + if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) { + $tpl->set( 'body_onload', 'setupRightClickEdit()' ); + } else { + $tpl->set( 'body_onload', false ); + } $tpl->set( 'navigation_urls', $this->buildNavigationUrls() ); $tpl->set( 'nav_urls', $this->buildNavUrls() ); diff --git a/includes/User.php b/includes/User.php index 13621d48b9..8f51b13ecd 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1119,7 +1119,6 @@ class User { $confstr = $this->getOption( 'math' ); $confstr .= '!' . $this->getOption( 'stubthreshold' ); $confstr .= '!' . $this->getOption( 'editsection' ); - $confstr .= '!' . $this->getOption( 'editsectiononrightclick' ); $confstr .= '!' . $this->getOption( 'date' ); $confstr .= '!' . $this->getOption( 'numberheadings' ); $confstr .= '!' . $this->getOption( 'language' ); diff --git a/skins/MonoBook.php b/skins/MonoBook.php index 3371322853..9b808ca351 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -67,6 +67,7 @@ class MonoBookTemplate extends QuickTemplate { data['userjsprev']) { ?> data['body_ondblclick']) { ?>ondblclick="text('body_ondblclick') ?>" + data['body_onload' ]) { ?>onload="text('body_onload') ?>" data['nsclass' ]) { ?>class="text('nsclass') ?>">
diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index 39ea802df4..6d2edc549f 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -414,3 +414,42 @@ function akeytt() { } } } + +function setupRightClickEdit() { + if( document.getElementsByTagName ) { + var divs = document.getElementsByTagName( 'div' ); + for( var i = 0; i < divs.length; i++ ) { + var el = divs[i]; + if( el.className == 'editsection' ) { + addRightClickEditHandler( el ); + } + } + } +} + +function addRightClickEditHandler( el ) { + for( var i = 0; i < el.childNodes.length; i++ ) { + var link = el.childNodes[i]; + if( link.nodeType == 1 && link.nodeName.toLowerCase() == 'a' ) { + var editHref = link.getAttribute( 'href' ); + + // find the following a + var next = el.nextSibling; + while( next.nodeType != 1 ) + next = next.nextSibling; + + // find the following header + next = next.nextSibling; + while( next.nodeType != 1 ) + next = next.nextSibling; + + if( next && next.nodeType == 1 && + next.nodeName.match( /^[Hh][1-6]$/ ) ) { + next.oncontextmenu = function() { + document.location = editHref; + return false; + } + } + } + } +}