Add CSS hook for current WikiPage action
Closed, ResolvedPublic

Description

Author: colin.pitts

Description:
No CSS hook exists for distinguishing between content/history/etc actions for a
given page title. This obviously prevents CSS from changing the appearance based
on the action being performed.

This limitation appears to be inherent to all SkinTemplate.php derived skins, as
I can see nothing in that code that references the action.

Context:
I was implementing a link highlighting suggestion made by Timwi in this WikiEN-l
post: http://mail.wikimedia.org/pipermail/wikien-l/2005-October/031082.html

With the <body class="ns-0">, I was able to restrict the behavior to only the
article namespace. However, I found no way to prevent the behavior from
appearing on edit, history, protection, deletion, move, and watch/unwatch pages
for a given title.

A javascript workaround may exist.


Version: 1.6.x
Severity: enhancement

bzimport set Reference to bz4438.
bzimport created this task.Via LegacyJan 1 2006, 12:28 AM
bzimport added a comment.Via ConduitApr 27 2007, 12:51 AM

herd wrote:

An existing problem this could fix:
http://en.wikipedia.org/wiki/Main_Page?action=history The "View logs for this
page" link is in #contentSub which is hidden on the [[Main Page]] in css. It
would be nice to restore it.

Here is an experimental js for per-action CSS (should not be used except for
demonstration):
http://test.wikipedia.org/w/index.php?title=User:Splarka/monobook.js&oldid=21972

It first appends a class "action-actionname" to the body according to the
&action parameter value, such as: 'watch unwatch delete revert rollback protect
unprotect info markpatrolled purge credits submit edit history'. Note that 'raw'
and 'render' do not have a <body> tag.

It then overwrites this with "action-diff" if a 'diff' parameter is used
(because the actions above have almost no effect on diffs).

It then appends "action-oldid" if 'oldid' is defined (as oldid does affect diffs).

So for example:

Main_Page == class="mediawiki ns-0 ltr page-Main_Page action-view"

Main_Page?action=unwatch == class="mediawiki ns-0 ltr page-Main_Page action-unwatch"

Main_Page?action=edit&oldid=11112 == class="mediawiki ns-0 ltr page-Main_Page
action-edit action-oldid"

Main_Page?diff=14912&oldid=11112 == class="mediawiki ns-0 ltr page-Main_Page
action-diff action-oldid"

Possibly also useful would be classes for 'direction', 'curid', 'redirect',
'diffonly', 'rdfrom', 'from', 'until' (the pecking order would have to be worked
out).

bzimport added a comment.Via ConduitMay 2 2007, 12:04 AM

ayg wrote:

*** Bug 9758 has been marked as a duplicate of this bug. ***

bzimport added a comment.Via ConduitMay 2 2007, 12:38 AM

md5 wrote:

I created a patch that is attached to #9758, but it simply takes the value of
the "action" parameter and creates a class with "action-" prepended (defaulting
to "action-view"). If I can get some guidance as to whether that simple behavior
or the more complex behavior outlined by Sparkla is desired, I can adjust the
patch and attach it here. Since a release candidate of 1.10 has already been
cut, I guess this will have to target 1.11-svn, not 1.10-svn as I put in #9758.

brion added a comment.Via ConduitMay 2 2007, 3:02 PM

That sounds a bit fragile to me. I don't like relying on pulling a literal GET
param there either, we want to be more general in handling the action parameters
and in validating. Might work ok though, as long as there's not a problem with
whitespace/invalid chars/etc.

bzimport added a comment.Via ConduitMay 2 2007, 5:37 PM

md5 wrote:

My patch was using Sanitizer::escapeClass to avoid potential problems with bad
characters. I agree that it is slightly fragile if people are hacking URLs, but
it will work all normal use cases (there is a fallback to "view" when "action"
is not provided). People who put in an action that isn't recognized get an error
page anyways.

I was hoping that there would be a $wgAction global that contained the validated
action name to avoid having to default to "view" in multiple places in the code,
but I couldn't find it. I ended up using the same code that populated the
"wgAction" JavaScript variable.

Entlinkt added a comment.Via ConduitAug 23 2010, 8:43 PM
  • Bug 24895 has been marked as a duplicate of this bug. ***
duplicatebug added a comment.Via ConduitOct 27 2010, 2:09 PM
  • Bug 25657 has been marked as a duplicate of this bug. ***
demon added a comment.Via ConduitFeb 12 2011, 9:31 PM
  • Bug 27370 has been marked as a duplicate of this bug. ***
Subfader added a comment.Via ConduitFeb 12 2011, 9:42 PM

What's so complicated about adding these useful classes? :(

Subfader added a comment.Via ConduitFeb 13 2011, 12:51 PM

Can't get Sparkla's JS solution working http://test.wikipedia.org/w/index.php?title=User:Splarka/monobook.js&oldid=21972

For those who want to hardcode a solution: includes/Skin.php:

function getPageClasses( $title ) {

		global $wgRequest;
		$numeric = 'ns-'.$title->getNamespace();
		if( $title->getNamespace() == NS_SPECIAL ) {
			$type = 'ns-special';
		} elseif( $title->isTalkPage() ) {
			$type = 'ns-talk';
		} else {
			$type = 'ns-subject';
		}
		$name = Sanitizer::escapeClass( 'page-'.$title->getPrefixedText() );
	  if (!$wgRequest->getVal('action')) {
	  	  $actionValue='view';
	  	  } else {
	  	  $actionValue = $wgRequest->getVal('action');
	  	  }
		$action = 'action-'. $actionValue;
		return "$numeric $type $name $action";

}

This will add " action-edit" to the body class when you edit a page etc. and action-view when there is no action.

Subfader added a comment.Via ConduitFeb 13 2011, 12:57 PM

A slightly improved version will also add action-yes to catch all pages that have an action.

	  if (!$wgRequest->getVal('action')) {
	  	  $actionValue = 'action-no action-view';
	  	  } else {
	  	  $actionValue = 'action-yes action-'.$wgRequest->getVal('action');
	  	  }
		$action = $actionValue;
Subfader added a comment.Via ConduitFeb 13 2011, 5:30 PM

Now also considering diffs which don't use the action parameter.

	  if (!$wgRequest->getVal('action')) {
	  	  $actionValue = 'action-no action-view';
	  	  } else {
	  	  $actionValue = 'action-yes action-'.$wgRequest->getVal('action');
	  	  }
	  if ($wgRequest->getVal('diff')) {
	  	  $actionValue = 'action-yes action-diff';
	  	  }
		$action = $actionValue;
Krinkle added a comment.Via ConduitMar 8 2011, 9:41 AM

See also bug 25800

DieBuche added a comment.Via ConduitJul 11 2011, 10:57 AM

Fixed in r91871 (w/o action-no, just use body:not(.action-view) )

Krinkle added a comment.Via ConduitJul 12 2011, 11:04 AM

Please don't fix this locally, there is enough ad-hoc "what action" implementations already. Instead focus on bug 27930. Once that is fixed we can insert it into various places (mw.config wgAction and body-class "action-$1").

That way action=yes%20I%know will not end up with wgAction="yes i know" or <body class="action-yes I know" (3 classes).

Just escaping it to action-yes_i_know isn't acceptable either imho, bug 27930 :-)

DieBuche added a comment.Via ConduitJul 12 2011, 11:08 AM

action=yes%20I%know returns wgAction="nosuchaction" since r91870 . That rev needs some polish per CR, though

DieBuche added a comment.Via ConduitJul 12 2011, 12:32 PM

Edit: I meant r91949

Subfader added a comment.Via ConduitJul 12 2011, 5:30 PM

The fixes don't consider diffs.

if ($wgRequest->getVal('diff')) {

       $actionValue = 'action-yes action-diff';
}
Krinkle added a comment.Via ConduitJan 8 2012, 1:37 AM

Reopening as r94131 reverted this, didn't anyone notice ?

Krinkle added a comment.Via ConduitJan 8 2012, 1:49 AM

Fixed in r108345.

Add Comment