Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F7567
Title.php.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
bzimport
Nov 21 2014, 11:28 PM
2014-11-21 23:28:24 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
Title.php.patch
View Options
Index: Title.php
===================================================================
--- Title.php (revisão 83693)
+++ Title.php (cópia de trabalho)
@@ -751,21 +751,50 @@
}
/**
- * Get the base name, i.e. the leftmost parts before the /
+ * Get the name of the lowest-level parent page which exists and returns
+ * the real subpage or basepage
*
- * @return String Base name
+ * @return String Base page name or Sub page name
*/
- public function getBaseText() {
+ 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 '';
+ }
- $parts = explode( '/', $this->getText() );
- # Don't discard the real title if there's no subpage involved
- if ( count( $parts ) > 1 ) {
- unset( $parts[count( $parts ) - 1] );
+ /**
+ * 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 implode( '/', $parts );
+ return substr( $page, 0, strrpos( $page, '/' ) );
}
/**
@@ -774,11 +803,11 @@
* @return String Subpage name
*/
public function getSubpageText() {
- if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
- return( $this->mTextform );
+ $page = $this->mTextform;
+ if ( $this->CheckExistence( 'subpage' ) ) {
+ return $this->CheckExistence( 'subpage' );
}
- $parts = explode( '/', $this->mTextform );
- return( $parts[count( $parts ) - 1] );
+ return substr( $page, strrpos( $page, '/' ) + 1 );
}
/**
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
7097
Default Alt Text
Title.php.patch (2 KB)
Attached To
Mode
T29976: please correct method "getBaseText()" and "getSubpageText()" to return the actual name of the pages
Attached
Detach File
Event Timeline
Log In to Comment