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 subpage level of a given Page. * * @param Title $page Page to get the level from. * * @return Title Result The Level the given page has. Level 0 means the given page is no subpage at all. */ static function getSubpageLevel( Title $page ) { $ancestors = SubpageInfo::getAncestorPages( $page ); if( ! empty( $ancestors ) ) { return count ($ancestors ); } else //no parent! The page itself is the top level: return 0; }