Last modified: 2014-01-31 07:11:40 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T35766, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 33766 - Sidebar ignores templates
Sidebar ignores templates
Status: NEW
Product: MediaWiki
Classification: Unclassified
Interface (Other open bugs)
1.19.2
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
http://en.teopedia.org/lib/MediaWiki:...
: need-integration-test
: 48738 (view as bug list)
Depends on:
Blocks: 27292
  Show dependency treegraph
 
Reported: 2012-01-17 06:37 UTC by Pavel Malakhov
Modified: 2014-01-31 07:11 UTC (History)
10 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Detailed screenshot of the bug (93.50 KB, image/png)
2013-05-23 08:21 UTC, Youri van den Bogert
Details

Description Pavel Malakhov 2012-01-17 06:37:03 UTC
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)
Comment 1 Mark A. Hershberger 2012-01-19 18:24:43 UTC
Hrm... at first I thought this was Bug 33321.  Could you try the laetest code from Subversion?
Comment 2 Siebrand Mazeland 2012-01-23 13:57:11 UTC
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
Comment 3 carchaias 2012-02-08 16:19:21 UTC
Including of Templates workes in 1.17 (I tested) and no longer until 1.18.
Comment 4 carchaias 2012-02-08 16:36:08 UTC
It doesnot work in all skins, not only Vector.
Comment 5 Mark A. Hershberger 2012-03-02 21:48:07 UTC
someone, I dare not say who, hinted they would look for this regression.
Comment 6 Bawolff (Brian Wolff) 2012-03-02 21:59:09 UTC
/me hesitates to ask, but...

Is there a good use case for putting templates in the sidebar?
Comment 7 Pavel Malakhov 2012-03-03 02:02:01 UTC
(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
Comment 8 carchaias 2012-04-22 09:46:05 UTC
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.
Comment 9 Pavel Malakhov 2013-01-07 13:31:18 UTC
I've tried it on 1.19.2 the bug is still alive.
It's getting annoying... :)
Comment 10 Andre Klapper 2013-01-07 13:34:53 UTC
What are exact steps to reproduce the problem?
Comment 11 Mark A. Hershberger 2013-01-07 14:42:51 UTC
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.
Comment 12 Bawolff (Brian Wolff) 2013-01-07 15:46:02 UTC
(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.
Comment 13 Pavel Malakhov 2013-01-07 16:56:05 UTC
(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)
Comment 14 Pavel Malakhov 2013-01-07 17:02:27 UTC
That's where you can see the bug in action:
http://en.teopedia.org/lib/MediaWiki:Sidebar
Comment 15 Youri van den Bogert 2013-05-23 08:20:54 UTC
*** Bug 48738 has been marked as a duplicate of this bug. ***
Comment 16 Youri van den Bogert 2013-05-23 08:21:49 UTC
Created attachment 12377 [details]
Detailed screenshot of the bug

We've got the same problem on 1.19.6. The bug was not in version 1.17.4!
Comment 17 Youri van den Bogert 2013-05-23 08:59:42 UTC
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.
Comment 18 Youri van den Bogert 2013-08-09 06:58:14 UTC
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.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links