This lets us use the same parser cache for both settings of this option.
$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
. "<div class='visualClear'></div>\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 '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
- }
-
- /** @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 '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
- }
-
/** @todo document */
function editSectionLinkForOther( $title, $section ) {
global $wgRequest;
$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
$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 <h#> tag
@$head[$headlineCount] .= "<a name=\"$anchor\"></a><h".$level.$matches[2][$headlineCount] .$headline.'</h'.$level.'>';
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; }
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 ); }
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; }
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 );
}
}
$a['onload'] = $wgOut->getOnloadHandler();
+ if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
+ if( $a['onload'] != '' ) {
+ $a['onload'] .= ';';
+ }
+ $a['onload'] .= 'setupRightClickEdit()';
+ }
return $a;
}
global $wgOut, $wgTitle, $wgUser;
$s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
- if($wgUser->getOption( 'editsectiononrightclick' ) && $wgTitle->userCanEdit()) { $s=$this->editSectionScript($wgTitle, 0,$s);}
return $s;
}
} 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() );
$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' );
<?php if($this->data['userjsprev']) { ?><script type="text/javascript"><?php $this->html('userjsprev') ?></script><?php } ?>
</head>
<body <?php if($this->data['body_ondblclick']) { ?>ondblclick="<?php $this->text('body_ondblclick') ?>"<?php } ?>
+ <?php if($this->data['body_onload' ]) { ?>onload="<?php $this->text('body_onload') ?>"<?php } ?>
<?php if($this->data['nsclass' ]) { ?>class="<?php $this->text('nsclass') ?>"<?php } ?>>
<div id="globalWrapper">
<div id="column-content">
}
}
}
+
+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;
+ }
+ }
+ }
+ }
+}