Last modified: 2014-09-24 00:52:17 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 T29976, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 27976 - please correct method "getBaseText()" and "getSubpageText()" to return the actual name of the pages
please correct method "getBaseText()" and "getSubpageText()" to return the ac...
Status: PATCH_TO_REVIEW
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
unspecified
All All
: Normal enhancement with 1 vote (vote)
: ---
Assigned To: Nobody - You can work on this!
: patch, patch-reviewed
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-03-10 17:27 UTC by Raylton P. Sousa
Modified: 2014-09-24 00:52 UTC (History)
4 users (show)

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


Attachments
New code (2.13 KB, patch)
2011-03-11 13:00 UTC, Helder
Details
Parser test with many possibilities (18.87 KB, text/plain)
2011-05-19 20:01 UTC, Raylton P. Sousa
Details

Description Raylton P. Sousa 2011-03-10 17:27:11 UTC
these two methods has serious problems, because it returns the correct name of the sub pages and base pages, for exemple

 Guia do Linux/Avançado/Personalização do Sistema/Arquivo /etc/profile 

the subpage would be correctly defined to "Arquivo /etc/profile" instead of "profile". In this example, the last "/" is part of the chapter name, which is "Arquivo /etc/profile", and not a separator. the same goes for base pages.
Note that by default, MediaWiki shows below the title of a page (in a span inside of the element with id="contentSub") the names of "existing pages above" each page in a namespace with subpages enabled.

for this reason (with the help of my friend Helder.wiki) made ​​a code that corrects this failure and expect that we deserve some attention. 
here is the code : 
	/**
	 * Get the name of the lowest-level parent page which exists and returns the real subpage or basepage
	 *
	 * @return String Base page name or Sub page name
	 */

	 private function CheckExistence($type = null){
		if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
			return $this->getText();
		}
		$defaultpage = $this->mTextform;
		$page = $this->mTextform;
		for( $i = 1; $i <= 25; $i++ ){
			$pos = strrpos( $page, '/' );
			if ( $pos ) {
				$page = substr( $page, 0, $pos );
				if( Title::newFromText( $page )->exists()  ){
					switch( $type ){
					case 'subpage' :				
						return (substr( $defaultpage, $pos+1 ));
					case 'basepage': 
						return ($page);
					default:
						return( $defaultpage); 
					}
				}
			}
			else{
				return( $defaultpage );
			}
		}
		return '';
	}

	/**
	 * Get the base name, i.e. the leftmost parts before the /
	 *
	 * @return String Base name
	 */
	public function getBaseText() {
		$page = $this->mTextform;
		if($this->CheckExistence('basepage')){
			return $this->CheckExistence('basepage');
		}
		return substr( $page, 0, strrpos( $page, '/' ) );
	}
	
	/**
	 * Get the lowest-level subpage name, i.e. the rightmost part after /
	 *
	 * @return String Subpage name
	 */
	public function getSubpageText() {
		$page = $this->mTextform;
		if($this->CheckExistence('subpage')){
			return $this->CheckExistence('subpage');
		}
		return substr( $page, strrpos( $page, '/' )+1 );
	}
	
	
This code needs to be added "Title.php" for  replace the "getSubpageText()" getBaseText() "and added the private method "CheckExistence() "
Comment 1 Raylton P. Sousa 2011-03-10 17:29:33 UTC
* in the first line I meant "no returns"
Comment 2 Mark A. Hershberger 2011-03-10 18:14:34 UTC
What do you propose to happen in the following cases:

   "Foo" does not exist
   "Foo/bar" exists ... what is its title?

   "Foo" exists
   "Foo/bar " exists
   "Foo/bar /bash/" does not exist
   "Foo/bar /bash/blah" exists. ... what is its title?

   "Foo" does not exist
   "Foo/bar " does not exist
   "Foo/bar /bash/" exists ... what is its title?
   "Foo/bar /bash/blah" exists. ... what is its title?

I thank you for your code contribution, but I would think some parser tests here would help, too.
Comment 3 Raylton P. Sousa 2011-03-10 18:43:34 UTC
In the first case 
  If the page is parsed "Foo" the result to be basepage "Foo"  and subpage too
  If the page is parsed "Foo/bar" the result to be basepage "Foo/bar" and subpage too(if there is no father then the page means that the "/" part of the name of the page) 

In the second case 
  If the page is parsed "Foo" the result to be basepage "Foo" and subpage too
  If the page is parsed "Foo/bar" the result to be basepage "Foo" and subpage "bar"
  If the page is parsed "Foo/bar/bash" the result to be basepagee "Foo/bar"  and subpage "bash"
  If the page is parsed "Foo/bar/bash/blah" the result to be basepage "Foo/bar" and subpage "bash/blah"

In the third case 
  If the page is parsed "Foo" the result to be basepage "Foo" and subpage too
  If the page is parsed "Foo/bar" the result to be basepage "Foo/bar" and subpage too(if there is no father then the page means that the "/" part of the name of the page) 
  If the page is parsed "Foo/bar/bash" the result to be basepage "Foo/bar"  and subpage "Foo/bar/bash"(if there is no father then the page means that the "/" part of the name of the page) 
  If the page is parsed "Foo/bar/bash/blah" the result to be basepage "Foo/bar/bash" and subpage "blah"
Comment 4 Helder 2011-03-11 13:00:14 UTC
Created attachment 8280 [details]
New code

(In reply to comment #0)
Here is the patch with the code above
Comment 5 Niklas Laxström 2011-03-11 13:21:59 UTC
At least fiwp has pages like Talk:M/S_Jamaa_II where M is not supposed to be the basepagename.
Comment 6 Helder 2011-03-11 13:30:52 UTC
[Mid-air collision detected!]

(In reply to comment #2)
For the sake of comparison, with the old version, if we add the wikicode
 *base = "{{BASEPAGENAME}}"
 *sub = "{{SUBPAGENAME}}"
to the following pages in the described situations, we have:
(1)
>    "Foo" does not exist
>    "Foo/bar" exists ... what is its title?
 On "Foo":
  *contentSub is empty (since there is no bar, we are not in a subpage)
  *base = "Foo"
  *sub = "Foo"
 On "Foo/bar":
  *contentSub is empty (since the existence of a bar doesn't means we are in a
subpage)
  *base = "Foo" (wrong)
  *sub = "bar" (wrong)

(2)
>    "Foo" exists
>    "Foo/bar " exists
>    "Foo/bar /bash/" does not exist
>    "Foo/bar /bash/blah" exists. ... what is its title?
 On "Foo":
  *contentSub is empty (since there is no bar, we are not in a subpage)
  *base = "Foo"
  *sub = "Foo"
 On "Foo/bar": (note that "Foo/bar " can't exist with a space in the end of
title)
  *contentSub has "< Foo" (here the bar is a separator, so we are in a subpage)
  *base = "Foo"
  *sub = "bar"
 On "Foo/bar /bash/":
  *contentSub has "< Foo | bar" (we are in a subpage of "Foo/bar" whose name is
"bash/")
  *base = "Foo/bar /bash" (wrong)
  *sub = "" (wrong)
 On "Foo/bar /bash/blah":
  *contentSub has "< Foo | bar" (we are in another subpage of "Foo/bar" whose
name is "bash/blah")
  *base = "Foo/bar /bash" (wrong)
  *sub = "blah" (wrong)

(3)
>    "Foo" does not exist
>    "Foo/bar " does not exist
>    "Foo/bar /bash/" exists ... what is its title?
>    "Foo/bar /bash/blah" exists. ... what is its title?
 On "Foo":
  *contentSub is empty (since there is no bar, we are not in a subpage)
  *base = "Foo"
  *sub = "Foo"
 On "Foo/bar":(note that "Foo/bar " can't exist with a space in the end of
title)
  *contentSub is empty (since the existence of a bar doesn't means we are in a
subpage)
  *base = "Foo" (wrong)
  *sub = "bar" (wrong)
 On "Foo/bar /bash/":
  *contentSub is empty (none of the bars is used to separate "the title of an
existing page" of the rest of the title, so we are not in a subpage)
  *base = "Foo/bar /bash" (wrong)
  *sub = "" (wrong)
 On "Foo/bar /bash/blah":
  *contentSub is empty (same as before)
  *base = "Foo/bar /bash" (wrong)
  *sub = "blah" (wrong)
 On "Foo/bar /bash//blah"
  *contentSub is "< Foo/bar /bash/"
  *base = "Foo/bar /bash/"
  *sub = "blah"
Comment 7 Raylton P. Sousa 2011-03-11 18:50:03 UTC
Niklas Laxström, Really... but that's the thing that happens in both the
{{BASEPAGENAME}} today, as our new code, our intention with this new code is to
solve a different type of inconsistency that has no direct relationship with
it.
Comment 8 Raylton P. Sousa 2011-05-19 20:01:15 UTC
Created attachment 8558 [details]
Parser test with many possibilities
Comment 9 Raylton P. Sousa 2011-05-19 20:05:36 UTC
Comment on attachment 8280 [details]
New code

(In reply to comment #2)
Here is the parserTests above
Comment 10 Raylton P. Sousa 2011-05-19 20:07:30 UTC
Comment on attachment 8558 [details]
Parser test with many possibilities

(In reply to comment #2)
Here is the parserTests above(please ignore my last comment)
Comment 11 Bawolff (Brian Wolff) 2011-09-28 01:51:31 UTC
My main concerns with this code are as follows:

*This does existence checks (and possibly quite a few [like ~127] for weird inputs) whenever getSubpage is called. I don't know for sure, but that sounds expensive when (an abusive) user could add thousands of such things to a page (I suppose if we really wanted this we could make it an expensive parser function)
*People may be (ab)using the {{SUPAGENAME}} stuff for other uses that this would break (admittedly I don't know off hand if anyone does, but we should be careful when changing these types of thing). For example {{BASEPAGE:foo/bar}} can be used to strip off everything after the / without any concern for if its a real title. (Perhaps if we really wanted it, make a new magic parser func thing for this behaviour)

Minor issue: (This is just at looking at code, I haven't tested so i could of missed something). It appears this doesn't check existence in the right namespace.
Comment 12 Sumana Harihareswara 2011-11-07 03:30:49 UTC
Adding the "reviewed" keyword since Bawolff has reviewed it in comment # 11.  Raylton, have you had a chance to consider those comments?  Thanks for the patch and the parser test!
Comment 13 Gerrit Notification Bot 2014-08-16 02:42:08 UTC
Change 154377 had a related patch set uploaded by Helder.wiki:
Allow subpagename to contain bars

https://gerrit.wikimedia.org/r/154377

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


Navigation
Links