// Create a new Title object from a redirect $currentTitle = Title::newFromText('Main_Page'); $redirectTitle = $currentTitle->getRedirectTarget(); $newTitle = Title::newFromRedirect($redirectTitle); // Compare the original and redirected titles if ($currentTitle->equals($newTitle)) { echo "The titles are equal"; } else { echo "The titles are not equal"; }
// Get a list of all pages that redirect to a certain page $targetTitle = Title::newFromText('MyPage'); $redirects = $targetTitle->getRedirectedFrom(); foreach ($redirects as $redirect) { echo $redirect->getPrefixedText() . "\n"; }In this example, we start with a Title object for a page called MyPage. We use the getRedirectedFrom method to get a list of all Title objects that redirect to MyPage. Then we loop through the list of redirects and print out their page titles.