Last modified: 2014-11-17 10:35:51 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 T3605, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 1605 - [[Section::...]] variables
[[Section::...]] variables
Status: NEW
Product: MediaWiki extensions
Classification: Unclassified
Extensions requests (Other open bugs)
unspecified
All All
: Low enhancement with 10 votes (vote)
: ---
Assigned To: Nobody - You can work on this!
: patch, patch-reviewed
: 6591 9240 12434 18398 30296 33477 (view as bug list)
Depends on: 17131
Blocks:
  Show dependency treegraph
 
Reported: 2005-02-28 12:38 UTC by Jason Lee, AllyUnion
Modified: 2014-11-17 10:35 UTC (History)
15 users (show)

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


Attachments
Additions to MagicWord.php to support the new variables (238 bytes, patch)
2009-01-16 15:05 UTC, Kinsey Moore
Details
Additions to Parser.php to support the new variables (against 1.13.3) (2.46 KB, patch)
2009-01-16 15:05 UTC, Kinsey Moore
Details
Additions to MessagesEn.php to support the new variables (against 1.13.3) (473 bytes, patch)
2009-01-16 15:06 UTC, Kinsey Moore
Details
This is a VERY cleaned up patch against current trunk (3.30 KB, patch)
2009-01-16 16:22 UTC, Kinsey Moore
Details
Move closer to preserving existing numbering behavior (3.32 KB, patch)
2009-01-16 16:59 UTC, Kinsey Moore
Details
Existing behavior duplicated, numbering still needs work (3.26 KB, patch)
2009-01-16 20:39 UTC, Kinsey Moore
Details
Fixed existing behavior (3.38 KB, patch)
2009-01-17 18:06 UTC, Kinsey Moore
Details
Numbering now works properly (doesn't take into account template sections) (4.20 KB, patch)
2009-01-17 23:17 UTC, Kinsey Moore
Details
Hooks into template inclusion, processed before transcluding occurs (506 bytes, patch)
2009-01-21 19:39 UTC, Kinsey Moore
Details
Effectively an extension at this point. It still needs polishing. Does not currently attach the T- to template header numbers. (3.32 KB, application/x-httpd-php)
2009-01-21 19:41 UTC, Kinsey Moore
Details
Extension-like, bug fixed, still no source or template support (3.62 KB, patch)
2010-04-29 15:30 UTC, Kinsey Moore
Details
fix a bug, correct opening and closing syntax (3.58 KB, patch)
2010-05-04 15:35 UTC, Kinsey Moore
Details

Description Jason Lee, AllyUnion 2005-02-28 12:38:50 UTC
I would like to request a special variable {{SECTION}} where it would
automatically include the section number of where the variable was put. This
allows linking of editing sections directly.
Comment 1 Antoine "hashar" Musso (WMF) 2005-03-27 20:16:29 UTC
There is already a link to directly modify a section next
to the section header. Seems to fullfill the requirement.
Comment 2 Jason Lee, AllyUnion 2005-03-27 22:26:28 UTC
The purpose is to allow the variable in the inclusion of templates.

I think you miss the point here.  Yes, the edit link at the section is there,
but what if you wanted to create your own section edit link?  The numbering
would not be automatic, it would be manual.

The way everything works now, there is a way to tack on to the end of the page,
but there is no way to create a template or a link to insert somewhere inbetween.
Comment 3 Jason Lee, AllyUnion 2005-04-05 04:13:39 UTC
(In reply to comment #1)
> There is already a link to directly modify a section next
> to the section header. Seems to fullfill the requirement.

The reason for this is if you were to put the {{SECTION}} variable on a
transinclude page or template, you can create an edit link.  For example:

This section is considered as a stub.  You can help Wikipedia by expanding this
section (link to the edit button)
Comment 4 Rob Church 2006-07-08 14:52:22 UTC
*** Bug 6591 has been marked as a duplicate of this bug. ***
Comment 5 Marco 2006-07-08 16:05:24 UTC
I would use this variable for a link in Sysop votes on dewiki...every sysop vote
is a == == section...it would be nice to fetch this ID. Marco
Comment 6 lordtbt 2007-03-19 18:19:40 UTC
This would be a great variable. Please implement it!
Comment 7 Daniel Folsom 2008-09-01 20:52:14 UTC
This would be awesome - it would be so useful for templates!
Comment 8 Kinsey Moore 2009-01-15 17:57:57 UTC
It seems that no one has implemented this yet.  I'm going to poke around and see if I can generate a relatively clean patch to provide this functionality, since I need this feature for what I'm working on.
Comment 9 Kinsey Moore 2009-01-15 21:15:32 UTC
Looking at the code in Parser.php, it is not possible to add this the way normal variables are parsed, since they seem to be completely context insensitive.  However, I think I can add it to the formatHeadings function.  It might be more prudent to put it in doHeadings, but that would require a complete rewrite of the function to parse the document line by line instead of doing its preg_replace calls on the document as a whole.  I'll get back after some experimentation.
Comment 10 Kinsey Moore 2009-01-15 21:23:58 UTC
It appears, upon further consideration, that formatHeadings would also have to be rewritten.  It is possible that the two functions can be combined in the future, but for the moment, I will be focusing my efforts on doHeadings.
Comment 11 Kinsey Moore 2009-01-16 00:28:38 UTC
I have successfully completed the patch.  Tomorrow, I will work on cleanup.  I have defined two new variables: SECTNAME and SECTNUM.  This took more effort than I would have liked, but at least it's functional. :D
Comment 12 Alex Z. 2009-01-16 00:32:06 UTC
Just a note, magic word names are generally not abbreviated even if they are a bit long, though you can add abbreviated aliases in the messages file.
Comment 13 Kinsey Moore 2009-01-16 00:48:05 UTC
Thanks for the information, Z-man.  I'll change things accordingly.  What is generally done about translations?  Unfortunately, I only know english.
Comment 14 Kinsey Moore 2009-01-16 15:05:07 UTC
Created attachment 5681 [details]
Additions to MagicWord.php to support the new variables
Comment 15 Kinsey Moore 2009-01-16 15:05:53 UTC
Created attachment 5682 [details]
Additions to Parser.php to support the new variables (against 1.13.3)
Comment 16 Kinsey Moore 2009-01-16 15:06:33 UTC
Created attachment 5683 [details]
Additions to MessagesEn.php to support the new variables (against 1.13.3)
Comment 17 Kinsey Moore 2009-01-16 15:08:20 UTC
I have attached the three required patches to enable this new feature.  The diff is against release 1.13.3.  If the diff needs to be against a different version, please let me know and I will update them accordingly.
Comment 18 Roan Kattouw 2009-01-16 15:54:43 UTC
(In reply to comment #17)
> I have attached the three required patches to enable this new feature.  The
> diff is against release 1.13.3.  If the diff needs to be against a different
> version, please let me know and I will update them accordingly.
> 

Preferably, diff against the latest SVN version, and use the "svn diff" command to generate the diff (or the Create patch option in TortoiseSVN). This also puts the whole thing in one file and makes the patch easier to apply (because right now, the filenames don't match: Parser.orig.php vs. Parser.php).

For a guide on how to check out MediaWiki using SVN, see http://www.mediawiki.org/wiki/SVN
Comment 19 Roan Kattouw 2009-01-16 15:56:14 UTC
Whoops, accidentally changed this bug from ASSIGNED to NEW; changing back.
Comment 20 Kinsey Moore 2009-01-16 15:56:44 UTC
Thanks for the input, Roan.  I'm already in the process of revising the patch for trunk, and making things a lot cleaner (removing for loops, converting join to implode, etc).
Comment 21 Kinsey Moore 2009-01-16 16:22:16 UTC
Created attachment 5684 [details]
This is a VERY cleaned up patch against current trunk
Comment 22 Kinsey Moore 2009-01-16 16:23:43 UTC
The current patch adds {{SECTIONNAME}} and {{SECTIONNUMBER}} variables to trunk.  They should be pretty self-explanatory.
Comment 23 Kinsey Moore 2009-01-16 16:28:40 UTC
Changing the summary to something slightly more accurate.
Comment 24 Roan Kattouw 2009-01-16 16:33:47 UTC
(In reply to comment #21)
> Created an attachment (id=5684) [details]
> This is a VERY cleaned up patch against current trunk
> 

Tim, can you review that?
Comment 25 Kinsey Moore 2009-01-16 16:59:49 UTC
Created attachment 5685 [details]
Move closer to preserving existing numbering behavior
Comment 26 Alex Z. 2009-01-16 19:09:19 UTC
Some comments from testing, haven't really looked at the code in detail:

*{{SECTIONNUMBER}} should probably return 0 rather than nothing when used before the first section header
*The number returned by {{SECTIONNUMBER}} is not the number used for section editing, but the number used by the TOC. For section editing, the sections are just numbered sequentially, regardless of what heading level it is, except for sections from templates, which are prefixed with "T-" and are numbered sequentially based on other sections from that template (so its possible to have multiple sections with the same "T-" number if they're from different templates, or the same template transcluded multiple times.) This is annoying in other areas as well, bug 16276. In any case, the numbers outputted won't work for section editing unless all sections are the same level and none are from templates.
*SECTIONNAME doesn't trim whitespace from the start/end of the section name
*SECTIONNAME doesn't take into consideration sections created using <h2> and the like in the wikitext, while not the normal way to create section headings, its not prohibited and does work.

When making changes to the parser, you should run the parserTests.php in the /maintenance directory. Its normal for some to fail, so you'll want to run it before and after your changes to determine if any of the failures are caused by your changes. When running it after applying the patch, I get an E_NOTICE (twice), 
PHP Notice:  Undefined offset:  12 in C:\xampp\htdocs\w\includes\parser\Parser.php on line 1169

This also causes some new test failures:
Running test Handling of sections up to level 6 and beyond... FAILED! - http://pastebin.com/f23f8d867
Running test Fuzz testing: Parser14... FAILED! - http://pastebin.com/f6cb2b8ed

The above 2 seem to be the same problem, the regex used assumes sections won't have more than 6 "=", but MediaWiki allows just ignores them and adds them to the section name. This also seems to check only 1 side of the section header, so ===Section name== will be treated as <h3>Section name</h3>, rather than <h2>=Section name</h2> as it currently does. It also seems to treat "=" in the middle of the section name very oddly, "=Test=n===" and "=Test=n==" both produce an <h3>, when neither of them should (they should both produce an <h1>). This seems to be related with the other test failure:

Running test Invalid header with following text... FAILED! - http://pastebin.com/f3d044be6

The text that's parsed in each test can be found in maintenance/parserTests.txt
Comment 27 Kinsey Moore 2009-01-16 19:22:10 UTC
Thanks for the quick update!  I'll work on these issues over the weekend.
Comment 28 Kinsey Moore 2009-01-16 20:39:14 UTC
Created attachment 5686 [details]
Existing behavior duplicated, numbering still needs work
Comment 29 Kinsey Moore 2009-01-16 21:27:28 UTC
I retract that statement, 2 failures remaining to address.
Comment 30 Jason Lee, AllyUnion 2009-01-17 06:50:20 UTC
Wow... 4 years ago... has it been that long?  Thanks Kinsey!
Comment 31 Kinsey Moore 2009-01-17 18:06:12 UTC
Created attachment 5694 [details]
Fixed existing behavior
Comment 32 Kinsey Moore 2009-01-17 23:17:43 UTC
Created attachment 5695 [details]
Numbering now works properly (doesn't take into account template sections)
Comment 33 Kinsey Moore 2009-01-17 23:24:16 UTC
I just did a quick test, and it seems like my code has no issue dealing with template sections.  I'd say this is ready for a review.
Comment 34 Kinsey Moore 2009-01-17 23:35:36 UTC
Reading through Mr.Z-man's comments, there are two section numbers for each section.  The one generated by the TOC, and the one in the source document.  Right now, {{SECTIONNUMBER}} generates the numbers as seen in the TOC.  To generate numbers as they would appear in the source document, I would have to rework quite a bit and change the location of the call.
Comment 35 Kinsey Moore 2009-01-19 15:09:32 UTC
As per my conversation with TimStarling on IRC, I am reworking this as an extension, since it's better not to hack the parser into tiny little pieces, Office Space style.  I have current functionality reimplemented, and I am working on source header number for edit link functionality.  The new format for this is going to be [[Section::*]] where * can be one of: Name, Number, SourceNumber.
Comment 36 Kinsey Moore 2009-01-21 19:37:27 UTC
What I'm about to attach is just about all I can manage at the moment.  To have template section numbers work properly for edit links, one of two things needs to happen: either include the patch I'm attaching to add the hooks to template inclusion (or some cleaned up variant thereof), or to expose mHeadings to the outside world somehow.  As it is, mHeadings contains the information I want, but having the prefix "m", it is technically an internal/private member with no outside accessor.  The hooks in the patch are more than likely not in the right place, but work for the moment.
Comment 37 Kinsey Moore 2009-01-21 19:39:45 UTC
Created attachment 5717 [details]
Hooks into template inclusion, processed before transcluding occurs
Comment 38 Kinsey Moore 2009-01-21 19:41:04 UTC
Created attachment 5718 [details]
Effectively an extension at this point.  It still needs polishing.  Does not currently attach  the T- to template header numbers.
Comment 39 Kinsey Moore 2009-01-21 19:46:25 UTC
Just to explain a little more thoroughly, all the section number replacement works without the template hook patch except for the template numbers.  [[Section::SourceNumber]] will remain untouched if the patch is not applied and it is in a template.  [[Section::SourceNumber]] DOES work for non-included pages, so user-generated edit links will work for the local page.
Comment 40 Kinsey Moore 2009-01-23 19:08:12 UTC
The scope of this bug has changed, somewhat.  It is best implemented as an extension once bug 17131 gets implemented.
Comment 41 Kinsey Moore 2009-01-27 04:32:41 UTC
adding bug dependency on a different one
Comment 42 Dan Jacobson 2009-04-08 06:15:19 UTC
*** Bug 18398 has been marked as a duplicate of this bug. ***
Comment 43 Ryan Schmidt 2009-04-08 20:26:06 UTC
*** Bug 18398 has been marked as a duplicate of this bug. ***
Comment 44 IRP 2009-04-08 20:58:25 UTC
It doesn't appear that anything has been done yet. When I try to use it on http://en.wikipedia.org/wiki/Template:Emptysection, nothing happens. What text am I supposed to add?
Comment 45 Kinsey Moore 2009-04-08 23:02:23 UTC
This has not been merged in.  There is still work to be done to enable full support for source numbers, though work for TOC numbers is pretty much complete.  It is unlikely you will be able to use this on wikipedia for a good while, still.  I hope to find time to complete the rest of the necessary work this summer when I have more time.  If you want to finish the work, please do so :).  The related bug to get a hook into template inclusion is what is required.  Once that is done, I need to make sure everything still works as expected and put everything into a proper extension.
Comment 46 Dan Jacobson 2009-04-30 01:47:08 UTC
*** Bug 12434 has been marked as a duplicate of this bug. ***
Comment 47 Dan Jacobson 2009-04-30 01:48:57 UTC
*** Bug 9240 has been marked as a duplicate of this bug. ***
Comment 48 IRP 2009-05-08 20:31:45 UTC
Will this get done in a relatively short amount of time if I hire a developer to do this? Who is willing to do this and how much will you charge?
Comment 49 Happy-melon 2009-05-09 18:23:46 UTC
In the spirit of free software development, Kinsey has already committed a huge amount of (her? 50/50 chance, sorry if I guessed wrong) time for free.  While I'm sure she'd be delighted if you offered a financial incentive, it probably wouldn't get this functionality deployed on WMF significantly faster.  The feature requires at least one hook to be added into the core software, then the feature itself needs to be compiled into a complete extension.  Then it needs to be reviewed by a senior developer for code integrity and performance: deploying extensions on the larger WMF wikis, particularly enwiki, usually requires extensive optimisation.  Ultimately the decision to install the extension is made by Brion.  The WMF end of the chain is where the bottleneck lies; if you want to buy quick action, offer to donate to the Foundation if those stages are expedited.
Comment 50 IRP 2009-05-09 19:08:27 UTC
How much should I donate?
Comment 51 Kinsey Moore 2010-04-29 15:30:53 UTC
Created attachment 7339 [details]
Extension-like, bug fixed, still no source or template support

Uploaded a new patch with a little extension polish (now shows up in Special:Version) and a bug fix involving the Section::Name variable.  Name was being evaluated too early and it was possible to replace it with source data instead of rendered data.  Just as a refresher, source numbering doesn't currently work properly because I don't have a hook to the right point in the parser.  There may be new hooks available since I haven't touched this in a year, so I'll look into that.
Comment 52 Kinsey Moore 2010-04-29 15:32:54 UTC
Oh, and just a FYI, you need the following line at the bottom of LocalSettings.php to make this extension work:
require_once( "$IP/extensions/sectionvars.php" );
Comment 53 Kinsey Moore 2010-05-04 15:35:14 UTC
Created attachment 7348 [details]
fix a bug, correct opening and closing syntax

Fixed a bug caused by debugging I had in the code.
Comment 54 p858snake 2011-04-30 00:08:56 UTC
*Bulk BZ Change: +Patch to open bugs with patches attached that are missing the keyword*
Comment 55 Sumana Harihareswara 2011-12-23 18:27:15 UTC
Kinsey, thanks for writing this. I added the "need-review" keyword to indicate that your code awaits review.  You might just want to apply for commit access and commit your extension to Subversion to get review faster, per https://www.mediawiki.org/wiki/Writing_an_extension_for_deployment .  Sorry for the wait!
Comment 56 Kinsey Moore 2011-12-23 18:36:31 UTC
Thanks for the update after all this time.  My need for this extension is waning, but it seems to be a useful feature so I'll jump back in and see if I can get everything working the way it needs to be.  I have all next week off and ever so much to get done, but I'm sure I can find time for this as well.
Comment 57 Kinsey Moore 2011-12-25 04:31:45 UTC
This extension seems to still work as expected on current trunk as of rev 105797.  I'm now looking at the work that needs to be done to get this in SVN and ready for deployment.
Comment 58 Sumana Harihareswara 2012-01-11 22:04:33 UTC
Kinsey, I appreciate your time working on this.  If you want to chat with other developers about what it takes to get your extension in Subversion and ready for deployment, our IRC channel is usually populated https://www.mediawiki.org/wiki/MediaWiki_on_IRC .  If you're actively working on an extension, it's pretty easy to get commit access: https://www.mediawiki.org/wiki/Commit_access_requests#Requesting_commit_access

Thanks.
Comment 59 Gustronico 2012-01-14 22:01:08 UTC
*** Bug 30296 has been marked as a duplicate of this bug. ***
Comment 60 Gustronico 2012-01-14 22:02:28 UTC
*** Bug 33477 has been marked as a duplicate of this bug. ***
Comment 61 Gustronico 2012-01-14 22:17:16 UTC
Please, consider the implementation of {{SECTIONLEVEL}} too.
It should return the number of equal signs in the section title.
Comment 62 Gustronico 2012-01-14 22:40:01 UTC
In addition, if also {{PARENTSECTIONNUMBER}} could be developed, it will serve as an elegant solution to bug 11415, which appears to have got a growing number of votes.

Note that parent section number may not be {{SECTIONNUMBER}} - 1
Comment 63 Sumana Harihareswara 2012-02-23 02:23:47 UTC
Kinsey, thanks for your work on this.  If you need help or guidance, please feel free to let us know on IRC or on the mailing list: https://www.mediawiki.org/wiki/Communication
Comment 64 Max Semenik 2012-04-20 20:50:46 UTC
My review:

* First of all, all PHP development should happen with error_reporting set to E_ALL | E_STRICT, otherwise you may miss problems like "Undefined variable: updatestatus in D:\Projects\MediaWiki\extensions\SectionNumber.php on line 82". Or "Notice: Undefined variable: hdepth in D:\Projects\MediaWiki\extensions\SectionNumber.php on line 87"
* This extension works correctly only when page contains no transcluded sections, otherwise the numbers go out of sync with those in section edit links.
* strpos( $parser->mTitle->mPrefixedText, 'Special:' ) === false works only on English-language wikis, use Title's functions that work with namespaces.
* Overall, the system that relies heavily on action (and retrieves it using an undocumented variable!) is extremely fragile.
* This extension's syntax ([[section::name]] and [[section::number]]) is non-standard and should be replaced with magic words.

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


Navigation
Links