From 7833589c5d576648b4db78bc69963bf8d516242d Mon Sep 17 00:00:00 2001 From: MatmaRex Date: Wed, 6 Mar 2013 21:10:15 +0100 Subject: [PATCH] (bug 41729) Move section edit links to after the headings This requires minor changes in various parts of MediaWiki, and being extra careful about cached rendered pages' HTML. Fun fact: editsection links are not made in Parser. They're made in Linker, in Skin *and* in ParserOutput. Client-side code and screen-scrapers will have to be adjusted to handle both cases (old HTML will still be visible on cached page renders until they are purged); extensions using the DoEditSectionLink or EditSectionLink hooks might need adjustments as well. * Linker: Change the HTML of pages to move the link itself from the beginning of the heading (before ) to the end of the heading (after the span). * Skin: Change the class from .editsection to .mw-editsection; we use this opportunity to clean up old cruft, and this makes it much easier to handle cached renders (by just detecting the old class). * ParserOutput: Implement a horrible hack to support cached parser outputs with the old order of items. * Ensure everything that should support both classes supports both classes (this includes print stylesheets and some scripts). * Implement styles for the new look for all the skins (did this in shared.css; the styles are non-intrusive and can be overridden easily, and all of the skins were using the same look before). Change-Id: I6a6c12a90de3604012420b20c1f520e0ece170ab --- RELEASE-NOTES-1.22 | 7 + includes/Linker.php | 2 +- includes/Skin.php | 4 +- includes/parser/ParserOutput.php | 16 +- .../ResourceLoaderUserCSSPrefsModule.php | 2 +- .../mediawiki.action.view.rightClickEdit.js | 2 +- skins/common/commonPrint.css | 1 + skins/common/shared.css | 29 ++- skins/common/wikiprintable.css | 1 + skins/modern/print.css | 1 + tests/parser/parserTests.txt | 202 +++++++++--------- 11 files changed, 159 insertions(+), 108 deletions(-) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index ec424d31ac..159a2164e7 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -45,6 +45,13 @@ production. another portlet will work as expected. * (bug 6747) {{ROOTPAGENAME}} introduced, contains the name of the topmost page without namespace. +* BREAKING CHANGE: (bug 41729) Display editsection links next to headings. Also + change their class name from .editsection to .mw-editsection and place them at + the end of the heading element instead of the beginning. Client-side code and + screen-scrapers will have to be adjusted to handle both cases (old HTML will + still be visible on cached page renders until they are purged); extensions + using the DoEditSectionLink or EditSectionLink hooks might need adjustments as + well. === Bug fixes in 1.22 === * Disable Special:PasswordReset when $wgEnableEmail. Previously one could still diff --git a/includes/Linker.php b/includes/Linker.php index 5e4675abbd..4003efb30b 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1740,8 +1740,8 @@ class Linker { */ public static function makeHeadline( $level, $attribs, $anchor, $html, $link, $legacyAnchor = false ) { $ret = "$html " . $link - . " $html" . ""; if ( $legacyAnchor !== false ) { $ret = "
$ret"; diff --git a/includes/Skin.php b/includes/Skin.php index 24561d81df..cc957c47d4 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1533,14 +1533,14 @@ abstract class Skin extends ContextSource { # DoEditSectionLink: it can't change the brackets or the span.) $result = wfMessage( 'editsection-brackets' )->rawParams( $result ) ->inLanguage( $lang )->escaped(); - return "$result"; + return "$result"; } # Add the brackets and the span, and *then* run the nice new hook, with # clean and non-redundant arguments. $result = wfMessage( 'editsection-brackets' )->rawParams( $link ) ->inLanguage( $lang )->escaped(); - $result = "$result"; + $result = "$result"; wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) ); return $result; diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index c5e42a4d2d..29b3500967 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -67,8 +67,22 @@ class ParserOutput extends CacheTime { function getText() { if ( $this->mEditSectionTokens ) { + $text = $this->mText; + + // If there's old output with misplaced editsections links cached, mangle it to put them in + // the right position. We can assume that there is no '' inside header tags, making this + // possible to do with a regex. + $text = preg_replace( + // [ this part is like EDITSECTION_REGEX, but with non-capturing groups ] + // note the space here ------v + '#(<[hH](\d)>)(<(?:mw:)?editsection page="(?:.*?)" section="(?:.*?)"(?:/>|>(?:.*?)(?:))) ([\s\S]*?)()#', + // swap the order of content and editsection link - $2 is ignored since it's the number in hN's tag name + '$1$4 $3$5', + $text + ); + return preg_replace_callback( ParserOutput::EDITSECTION_REGEX, - array( &$this, 'replaceEditSectionLinksCallback' ), $this->mText ); + array( &$this, 'replaceEditSectionLinksCallback' ), $text ); } return preg_replace( ParserOutput::EDITSECTION_REGEX, '', $this->mText ); } diff --git a/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php b/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php index 9795cd05f0..61e6e15023 100644 --- a/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php +++ b/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php @@ -81,7 +81,7 @@ class ResourceLoaderUserCSSPrefsModule extends ResourceLoaderModule { $rules[] = "#toc { display: none; }\n"; } if ( !$options['editsection'] ) { - $rules[] = ".editsection { display: none; }\n"; + $rules[] = ".mw-editsection, .editsection { display: none; }\n"; } if ( $options['editfont'] !== 'default' ) { // Double-check that $options['editfont'] consists of safe characters only diff --git a/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js b/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js index 61d9d15031..0e85fd9696 100644 --- a/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js +++ b/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js @@ -8,7 +8,7 @@ jQuery( function ( $ ) { // Don't use the ":has:(.editsection a)" selector because it performs very bad. // http://jsperf.com/jq-1-7-2-vs-jq-1-8-1-performance-of-mw-has/2 $( document ).on( 'contextmenu', 'h1, h2, h3, h4, h5, h6', function ( e ) { - var $edit = $( this ).find( '.editsection a' ); + var $edit = $( this ).find( '.mw-editsection a, .editsection a' ); if ( !$edit.length ) { return; } diff --git a/skins/common/commonPrint.css b/skins/common/commonPrint.css index 02297448a9..9b6d6ef8cf 100644 --- a/skins/common/commonPrint.css +++ b/skins/common/commonPrint.css @@ -111,6 +111,7 @@ div#jump-to-nav, div.top, div#column-one, #colophon, +.mw-editsection, .editsection, .toctoggle, .tochidden, diff --git a/skins/common/shared.css b/skins/common/shared.css index 6e1c94fd36..99e7d6d769 100644 --- a/skins/common/shared.css +++ b/skins/common/shared.css @@ -1092,9 +1092,36 @@ table.floatleft { z-index: 99; } -.editsection, .toctoggle { +.mw-editsection, .editsection, .toctoggle { -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; user-select: none; } + +/* Display editsection links smaller and next to headings */ +.mw-editsection { + font-size: x-small; + font-weight: normal; + margin-left: 1em; + vertical-align: baseline; + /* Reset line-height; headings tend to have it set to larger values */ + line-height: 1em; + /* As .mw-editsection is a (inline element), it is treated as part */ + /* of the heading content when selecting text by multiple clicks and thus */ + /* selected together with heading content, despite the user-select: none; */ + /* rule set above. This enforces non-selection without changing the look. */ + display: inline-block; +} + +/* Correct directionality when page dir is different from site/user dir */ +/* @noflip */ +.mw-content-ltr .mw-editsection, +.mw-content-rtl .mw-content-ltr .mw-editsection { + margin-left: 1em; +} +/* @noflip */ +.mw-content-rtl .mw-editsection, +.mw-content-ltr .mw-content-rtl .mw-editsection { + margin-right: 1em; +} diff --git a/skins/common/wikiprintable.css b/skins/common/wikiprintable.css index 95fcfef3cf..f5650b5105 100644 --- a/skins/common/wikiprintable.css +++ b/skins/common/wikiprintable.css @@ -32,6 +32,7 @@ a.stub { #logo, #footer, #siteNotice, +.mw-editsection, .editsection, .toctoggle { display: none; diff --git a/skins/modern/print.css b/skins/modern/print.css index 827841008b..6e0f8b3fef 100644 --- a/skins/modern/print.css +++ b/skins/modern/print.css @@ -3,6 +3,7 @@ #p-personal, #jump-to-nav, #footer, +.mw-editsection, span.editsection, .noprint { display: none; diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index a587a76a9e..68e68a11f0 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -4879,7 +4879,7 @@ List interrupted by empty line or heading -

[edit] A heading

+

A heading [edit]

@@ -5959,8 +5959,8 @@ Bug 6563: Edit link generation for section shown by !! input {{includeonly section}} !! result -

[edit] Includeonly section

-

[edit] Section T-1

+

Includeonly section [edit]

+

Section T-1 [edit]

!! end @@ -5986,7 +5986,7 @@ Bug 6563: Edit link generation for section suppressed by ==Section 1== !! result -

[edit] Section 1

+

Section 1 [edit]

!! end @@ -8060,13 +8060,13 @@ More ===Smaller headline=== Blah blah !! result -

[edit] Headline 1

+

Headline 1 [edit]

Some text

-

[edit] Headline 2

+

Headline 2 [edit]

More

-

[edit] Smaller headline

+

Smaller headline [edit]

Blah blah

!! end @@ -8105,14 +8105,14 @@ Some text -

[edit] Headline 1

-

[edit] Subheadline 1

-
[edit] Skipping a level
-
[edit] Skipping a level
-

[edit] Headline 2

+

Headline 1 [edit]

+

Subheadline 1 [edit]

+
Skipping a level [edit]
+
Skipping a level [edit]
+

Headline 2 [edit]

Some text

-

[edit] Another headline

+

Another headline [edit]

!! end @@ -8160,16 +8160,16 @@ Handling of sections up to level 6 and beyond -

[edit] Level 1 Heading

-

[edit] Level 2 Heading

-

[edit] Level 3 Heading

-

[edit] Level 4 Heading

-
[edit] Level 5 Heading
-
[edit] Level 6 Heading
-
[edit] = Level 7 Heading=
-
[edit] == Level 8 Heading==
-
[edit] === Level 9 Heading===
-
[edit] ==== Level 10 Heading====
+

Level 1 Heading [edit]

+

Level 2 Heading [edit]

+

Level 3 Heading [edit]

+

Level 4 Heading [edit]

+
Level 5 Heading [edit]
+
Level 6 Heading [edit]
+
= Level 7 Heading= [edit]
+
== Level 8 Heading== [edit]
+
=== Level 9 Heading=== [edit]
+
==== Level 10 Heading==== [edit]
!! end @@ -8202,12 +8202,12 @@ TOC regression (bug 9764) -

[edit] title 1

-

[edit] title 1.1

-

[edit] title 1.1.1

-

[edit] title 1.2

-

[edit] title 2

-

[edit] title 2.1

+

title 1 [edit]

+

title 1.1 [edit]

+

title 1.1.1 [edit]

+

title 1.2 [edit]

+

title 2 [edit]

+

title 2.1 [edit]

!! end @@ -8238,12 +8238,12 @@ wgMaxTocLevel=3 -

[edit] title 1

-

[edit] title 1.1

-

[edit] title 1.1.1

-

[edit] title 1.2

-

[edit] title 2

-

[edit] title 2.1

+

title 1 [edit]

+

title 1.1 [edit]

+

title 1.1.1 [edit]

+

title 1.2 [edit]

+

title 2 [edit]

+

title 2.1 [edit]

!! end @@ -8268,11 +8268,11 @@ wgMaxTocLevel=3
  • 2 Section 2
  • -

    [edit] Section 1

    -

    [edit] Section 1.1

    -

    [edit] Section 1.1.1

    -

    [edit] Section 1.1.1.1

    -

    [edit] Section 2

    +

    Section 1 [edit]

    +

    Section 1.1 [edit]

    +

    Section 1.1.1 [edit]

    +

    Section 1.1.1.1 [edit]

    +

    Section 2 [edit]

    !! end @@ -8283,8 +8283,8 @@ Resolving duplicate section names == Foo bar == == Foo bar == !! result -

    [edit] Foo bar

    -

    [edit] Foo bar

    +

    Foo bar [edit]

    +

    Foo bar [edit]

    !! end @@ -8294,8 +8294,8 @@ Resolving duplicate section names with differing case (bug 10721) == Foo bar == == Foo Bar == !! result -

    [edit] Foo bar

    -

    [edit] Foo Bar

    +

    Foo bar [edit]

    +

    Foo Bar [edit]

    !! end @@ -8314,10 +8314,10 @@ __NOTOC__ {{sections}} ==Section 4== !! result -

    [edit] Section 0

    -

    [edit] Section 1

    -

    [edit] Section 2

    -

    [edit] Section 4

    +

    Section 0 [edit]

    +

    Section 1 [edit]

    +

    Section 2 [edit]

    +

    Section 4 [edit]

    !! end @@ -8328,8 +8328,8 @@ __NOEDITSECTION__ ==Section 1== ==Section 2== !! result -

    Section 1

    -

    Section 2

    +

    Section 1

    +

    Section 2

    !! end @@ -8338,7 +8338,7 @@ Link inside a section heading !! input ==Section with a [[Main Page|link]] in it== !! result -

    [edit] Section with a link in it

    +

    Section with a link in it [edit]

    !! end @@ -8360,9 +8360,9 @@ __TOC__
  • 2 title 2
  • -

    [edit] title 1

    -

    [edit] title 1.1

    -

    [edit] title 2

    +

    title 1 [edit]

    +

    title 1.1 [edit]

    +

    title 2 [edit]

    !! end @@ -8384,10 +8384,10 @@ The line above must have a trailing space! --> But just in case it doesn't... !! result -

    [edit] =

    +

    = [edit]

    The line above must have a trailing space!

    -

    [edit] =

    +

    = [edit]

    But just in case it doesn't...

    !! end @@ -8423,19 +8423,19 @@ section 5
  • 5 text " text
  • -

    [edit] text > text

    +

    text > text [edit]

    section 1

    -

    [edit] text < text

    +

    text < text [edit]

    section 2

    -

    [edit] text & text

    +

    text & text [edit]

    section 3

    -

    [edit] text ' text

    +

    text ' text [edit]

    section 4

    -

    [edit] text " text

    +

    text " text [edit]

    section 5

    !! end @@ -8457,10 +8457,10 @@ Headers with excess '=' characters
  • 4 =italic heading
  • -

    [edit] foo=

    -

    [edit] =foo

    -

    [edit] italic heading=

    -

    [edit] =italic heading

    +

    foo= [edit]

    +

    =foo [edit]

    +

    italic heading= [edit]

    +

    =italic heading [edit]

    !! end @@ -8494,12 +8494,12 @@ __NOEDITSECTION__ -

    Header 1

    -

    Header 1.1

    -

    Header 1.2

    -

    Header 2

    -

    Header 2.1

    -

    Header 2.2

    +

    Header 1

    +

    Header 1.1

    +

    Header 1.2

    +

    Header 2

    +

    Header 2.1

    +

    Header 2.2

    !! end @@ -9786,7 +9786,7 @@ Fuzz testing: Parser14 == onmouseover= == http://__TOC__ !! result -

    [edit] onmouseover=

    +

    onmouseover= [edit]

    http://

    Contents

    • 1 onmouseover=
    • @@ -9801,7 +9801,7 @@ Fuzz testing: Parser14-table ==a== {| STYLE=__TOC__ !! result -

      [edit] a

      +

      a [edit]

      @@ -11598,7 +11598,7 @@ Inclusion of !userCanEdit() content !! input {{MediaWiki:Fake}} !! result -

      [edit] header

      +

      header [edit]

      !! end @@ -11629,12 +11629,12 @@ Out-of-order TOC heading levels
    -

    [edit] 2

    -
    [edit] 6
    -

    [edit] 3

    -

    [edit] 1

    -
    [edit] 5
    -

    [edit] 2

    +

    2 [edit]

    +
    6 [edit]
    +

    3 [edit]

    +

    1 [edit]

    +
    5 [edit]
    +

    2 [edit]

    !! end @@ -11741,7 +11741,7 @@ anchorencode encodes like the TOC generator: (bug 18431) {{anchorencode: _ +:.3A%3A&&]] }} __NOEDITSECTION__ !! result -

    _ +:.3A%3A&&]]

    +

    _ +:.3A%3A&&]]

    .2B:.3A.253A.26.26.5D.5D

    !! end @@ -11992,7 +11992,7 @@ language=sr variant=sr-ec !! input == -{Naslov}- == !! result -

    [уреди] Naslov

    +

    Naslov [уреди]

    !! end @@ -12309,7 +12309,7 @@ Morwen/13: Unclosed link followed by heading !! result

    [[link

    -

    [edit] heading

    +

    heading [edit]

    !! end @@ -12321,7 +12321,7 @@ HHP2.1: Heuristics for headings in preprocessor parenthetical structures !! result

    {{foo|

    -

    heading

    +

    heading

    !! end @@ -12333,7 +12333,7 @@ HHP2.2: Heuristics for headings in preprocessor parenthetical structures !! result

    {{foo|

    -

    [edit] heading

    +

    heading [edit]

    !! end @@ -13153,7 +13153,7 @@ __TOC__
  • 1 Lost episodes
  • -

    [edit] Lost episodes

    +

    Lost episodes [edit]

    !! end @@ -13170,7 +13170,7 @@ __TOC__
  • 1 should be bold then normal text
  • -

    [edit] should be bold then normal text

    +

    should be bold then normal text [edit]

    !! end @@ -13187,7 +13187,7 @@ __TOC__
  • 1 Image
  • -

    [edit] Image Foobar.jpg

    +

    Image Foobar.jpg [edit]

    !! end @@ -13204,7 +13204,7 @@ __TOC__
  • 1 Quote
  • -

    [edit]
    Quote

    +

    Quote
    [edit]

    !! end @@ -13223,7 +13223,7 @@ QED
  • 1 Proof: 2 < 3
  • -

    [edit] Proof: 2 < 3

    +

    Proof: 2 < 3 [edit]

    Hanc marginis exiguitas non caperet. QED

    @@ -13243,8 +13243,8 @@ __TOC__
  • 2 Foo Bar
  • -

    [edit] Foo Bar

    -

    [edit] Foo
    Bar

    +

    Foo Bar [edit]

    +

    Foo
    Bar
    [edit]

    !! end @@ -13262,8 +13262,8 @@ __TOC__
  • 2 b">Evilbye
  • -

    [edit] Hello

    -

    [edit] b">Evilbye

    +

    Hello [edit]

    +

    b">Evilbye [edit]

    !! end @@ -13290,11 +13290,11 @@ __TOC__
  • 5 Attributes after dir on these span tags must be deleted from the TOC
  • -

    [edit] C++

    -

    [edit] זבנג!

    -

    [edit] The attributes on these span tags must be deleted from the TOC

    -

    [edit] All attributes on these span tags must be deleted from the TOC

    -

    [edit] Attributes after dir on these span tags must be deleted from the TOC

    +

    C++ [edit]

    +

    זבנג! [edit]

    +

    The attributes on these span tags must be deleted from the TOC [edit]

    +

    All attributes on these span tags must be deleted from the TOC [edit]

    +

    Attributes after dir on these span tags must be deleted from the TOC [edit]

    !! end @@ -13311,7 +13311,7 @@ title=[[Main Page]] !! input {{int:Bug32057}} !! result -

    [edit] Headline text

    +

    Headline text [edit]

    !! end @@ -13413,7 +13413,7 @@ nowiki inside link inside heading (bug 18295) !! input ==[[foo|xyz]]== !! result -

    [edit] xyz

    +

    xyz [edit]

    !! end -- 2.20.1