Page MenuHomePhabricator

Sidebar ignores templates
Closed, DeclinedPublic

Description

Author: pavelmalahov

Description:
The page MediaWiki:Sidebar includes a template and shows it as expected, but sidebar ignores what was included and shows everything else but a template part of menu.

This worked OK in v.1.16.5 (did not check in 1.17)


Version: 1.19.2
Severity: normal
URL: http://en.teopedia.org/lib/MediaWiki:Sidebar

Details

Reference
bz33766

Related Objects

StatusSubtypeAssignedTask
ResolvedJdlrobson
DeclinedNone

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 12:03 AM
bzimport set Reference to bz33766.
bzimport added a subscriber: Unknown Object (MLST).

Hrm... at first I thought this was Bug 33321. Could you try the laetest code from Subversion?

Just tested this. I got the template code "{{doc-important|test}}" as plain text in the sidebar for the first[1] entry, but not for the second.

[1] https://translatewiki.net/w/i.php?title=MediaWiki%3ASidebar&diff=3639689&oldid=3423597

Including of Templates workes in 1.17 (I tested) and no longer until 1.18.

It doesnot work in all skins, not only Vector.

someone, I dare not say who, hinted they would look for this regression.

/me hesitates to ask, but...

Is there a good use case for putting templates in the sidebar?

pavelmalahov wrote:

(In reply to comment #6)

/me hesitates to ask, but...

Is there a good use case for putting templates in the sidebar?

I use it in wiki farm for common menu options

I combinate it with Extension "myvariables" http://www.mediawiki.org/wiki/Extension:MyVariables
User:USERNAME/Sidebar is the personal sidebar for USERNAME. In Mediawiki:Sidebar I include {{CURRENTUSER}}/Sidebar. Worked fine until 1.18.

pavelmalahov wrote:

I've tried it on 1.19.2 the bug is still alive.
It's getting annoying... :)

What are exact steps to reproduce the problem?

Since the work I'm currently doing makes extensive use of sidebar modifications, I definitely see a use for this. I'll look into the changes that were involved in 1.18 to cause this.

(In reply to comment #11)

Since the work I'm currently doing makes extensive use of sidebar
modifications, I definitely see a use for this. I'll look into the changes
that were involved in 1.18 to cause this.

If I recall, the change had to do with splitting the sidebar into multiple lines before expanding templates, instead of after.

pavelmalahov wrote:

(In reply to comment #10)

What are exact steps to reproduce the problem?

The steps are simple:

  1. Create a template, for example Template:Test
  2. Use it somewhere in Sidebar (page MediaWiki:Sidebar): {{Test}}
  3. Save the page

You will see the template in content area (just like it suppose to be), but not in the sidebar (like it used to be)

pavelmalahov wrote:

That's where you can see the bug in action:
http://en.teopedia.org/lib/MediaWiki:Sidebar

yvdbogert wrote:

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

yvdbogert wrote:

Detailed screenshot of the bug

We've got the same problem on 1.19.6. The bug was not in version 1.17.4!

Attached:

bug.png (608×1 px, 93 KB)

yvdbogert wrote:

In Includes/Skin.php search for function: addToSidebarPlain

If you have version 1.17* you'll probally see a elseif searching for '{{'. On the newer version, there is nothing thats searches for a '{{'

1.17.x function:
/**

  • Add content from plain text
  • @since 1.17
  • @param &$bar array
  • @param $text string
	 */

function addToSidebarPlain( &$bar, $text ) {

		$lines = explode( "\n", $text );
		$wikiBar = array(); # We need to handle the wikitext on a different variable, to avoid trying to do an array operation on text, which would be a fatal error.

		$heading = '';

		foreach ( $lines as $line ) {
			if ( strpos( $line, '*' ) !== 0 ) {
				continue;
			}

			if ( strpos( $line, '**' ) !== 0 ) {
				$heading = trim( $line, '* ' );
				if ( !array_key_exists( $heading, $bar ) ) {
					$bar[$heading] = array();
				}
			} else {
				$line = trim( $line, '* ' );

				if ( strpos( $line, '|' ) !== false ) { // sanity check
					$line = array_map( 'trim', explode( '|', $line, 2 ) );
					$link = wfMsgForContent( $line[0] );

					if ( $link == '-' ) {
						continue;
					}

					$text = wfMsgExt( $line[1], 'parsemag' );

					if ( wfEmptyMsg( $line[1], $text ) ) {
						$text = $line[1];
					}

					if ( wfEmptyMsg( $line[0], $link ) ) {
						$link = $line[0];
					}

					if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
						$href = $link;
					} else {
						$title = Title::newFromText( $link );

						if ( $title ) {
							$title = $title->fixSpecialName();
							$href = $title->getLocalURL();
						} else {
							$href = 'INVALID-TITLE';
						}
					}

					$bar[$heading][] = array(
						'text' => $text,
						'href' => $href,
						'id' => 'n-' . strtr( $line[1], ' ', '-' ),
						'active' => false
					);
				} else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
					global $wgParser, $wgTitle;

					$line = substr( $line, 2, strlen( $line ) - 4 );

					$options = new ParserOptions();
					$options->setEditSection( false );
					$options->setInterfaceMessage( true );
					$wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $options )->getText();
				} else {
					continue;
				}
			}
		}

		if ( count( $wikiBar ) > 0 ) {
			$bar = array_merge( $bar, $wikiBar );
		}

		return $bar;

}

1.19.x function:
/**

  • Add content from plain text
  • @since 1.17
  • @param $bar array
  • @param $text string
  • @return Array
	 */

function addToSidebarPlain( &$bar, $text ) {

		$lines = explode( "\n", $text );

		$heading = '';

		foreach ( $lines as $line ) {
			if ( strpos( $line, '*' ) !== 0 ) {
				continue;
			}
			$line = rtrim( $line, "\r" ); // for Windows compat

			if ( strpos( $line, '**' ) !== 0 ) {
				$heading = trim( $line, '* ' );
				if ( !array_key_exists( $heading, $bar ) ) {
					$bar[$heading] = array();
				}
			} else {
				$line = trim( $line, '* ' );

				if ( strpos( $line, '|' ) !== false ) { // sanity check
					$line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() );
					$line = array_map( 'trim', explode( '|', $line, 2 ) );
					if ( count( $line ) !== 2 ) {
						// Second sanity check, could be hit by people doing
						// funky stuff with parserfuncs... (bug 33321)
						continue;
					}

					$extraAttribs = array();

					$msgLink = $this->msg( $line[0] )->inContentLanguage();
					if ( $msgLink->exists() ) {
						$link = $msgLink->text();
						if ( $link == '-' ) {
							continue;
						}
					} else {
						$link = $line[0];
					}
					$msgText = $this->msg( $line[1] );
					if ( $msgText->exists() ) {
						$text = $msgText->text();
					} else {
						$text = $line[1];
					}

					if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
						$href = $link;

						// Parser::getExternalLinkAttribs won't work here because of the Namespace things
						global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
						if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
							$extraAttribs['rel'] = 'nofollow';
						}

						global $wgExternalLinkTarget;
						if ( $wgExternalLinkTarget) {
							$extraAttribs['target'] = $wgExternalLinkTarget;
						}
					} else {
						$title = Title::newFromText( $link );

						if ( $title ) {
							$title = $title->fixSpecialName();
							$href = $title->getLinkURL();
						} else {
							$href = 'INVALID-TITLE';
						}
					}

					$bar[$heading][] = array_merge( array(
						'text' => $text,
						'href' => $href,
						'id' => 'n-' . Sanitizer::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
						'active' => false
					), $extraAttribs );
				} else {
					continue;
				}
			}
		}

		return $bar;

}

Compare versions at diffnow.com and see the differences.

yvdbogert wrote:

Yesterday I've been working on a fix; and I fixed it by replacing a couple of functions. Note: I use MediaWiki 1.19.

All changes are done in the includes/Skin.php.

In function buildSidebar() we use the '$wgMemc' variable. This should be replaced to '$parserMemc'.

In function addToSidebar( &$bar, $message ) we use the function 'wfMsgForContentNoTrans($message)'. This should be replaced to 'wfMsgForContent($message)'.

I think the bug has something to do with it trying to translate things. Anyways; this fixed the problem for me.

Is this bug still a problem? I don't understand what it was about from reading the description and follow up conversation, but I don't think the Sidebar should be supporting templates... Such configuration should be as readable as possible.