static function pf_toplevelpage( &$parser /* , $title = null */ ) { $t = self::newTitleObject( $parser, func_get_args() ); if( $t === null ) { return ''; // invalid title given } //get all parents because the toplevel is the highest existing parent: $parentpages = SubpageInfo::getAncestorPages( $t ); if( ! empty( $parentpages ) ) { return wfEscapeWikiText( $parentpages[0]->getPrefixedText() ); } else { ////no parent! The page itself is the top level: return wfEscapeWikiText( $t->getPrefixedText() ); } }
/** * Delivers the real subpage title, not only the part behind the last "/" like PAGENAME does. * * @param Title $page The page to get the title from. * * @return string Result The subpage title of the given page. If page isn't a subpage, the Pages * name (without prefix) will be returned. */ static function getSubpageTitle( Title $page ) { $parent = SubpageInfo::getParentPage( $page ); //return the whole subpage name not like SUBPAGENAME only the last part after the last "/": if( ! empty( $parent ) ) { return substr( $page->getText(), strlen( $parent->getText() . '/' ) ); } return $page->getText(); //return PAGENAME }