* Move editsectiononrightclick setup to JavaScript (it requires JS anyway)
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 25 Mar 2005 12:37:19 +0000 (12:37 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 25 Mar 2005 12:37:19 +0000 (12:37 +0000)
This lets us use the same parser cache for both settings of this option.

includes/EditPage.php
includes/Linker.php
includes/Parser.php
includes/Skin.php
includes/SkinTemplate.php
includes/User.php
skins/MonoBook.php
skins/common/wikibits.js

index 0606e2d..b79cce8 100644 (file)
@@ -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
index 0c0f3d6..ce1bab5 100644 (file)
@@ -807,26 +807,6 @@ class Linker {
                                 . "<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&section='.$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&section='.$section );
-               return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
-       }
-
        /** @todo document */
        function editSectionLinkForOther( $title, $section ) {
                global $wgRequest;
index 060503c..bba5a91 100644 (file)
@@ -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 <h#> tag
                        @$head[$headlineCount] .= "<a name=\"$anchor\"></a><h".$level.$matches[2][$headlineCount] .$headline.'</h'.$level.'>';
 
@@ -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 );
        }
index 9d63c40..de7777d 100644 (file)
@@ -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 = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
-               if($wgUser->getOption( 'editsectiononrightclick' ) && $wgTitle->userCanEdit()) { $s=$this->editSectionScript($wgTitle, 0,$s);}
                return $s;
        }
 
index 12029c6..ede1ed8 100644 (file)
@@ -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() );
 
index 13621d4..8f51b13 100644 (file)
@@ -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' );
index 3371322..9b808ca 100644 (file)
@@ -67,6 +67,7 @@ class MonoBookTemplate extends QuickTemplate {
     <?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">
index 39ea802..6d2edc5 100644 (file)
@@ -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;
+                               }
+                       }
+               }
+       }
+}