class MySpecialPage extends SpecialPage { public function __construct() { parent::__construct('MySpecialPage'); } public function execute($par) { $this->setHeaders(); $output = $this->getOutput(); $output->addWikiText("Hello, world!"); } } // Get the title of the custom special page $title = SpecialPage::getTitleFor('MySpecialPage'); // Output the title echo $title->getText();
// Get the title of the special page $title = SpecialPage::getTitleFor('MySpecialPage'); // Create a link to the special page $link = Html::element('a', ['href' => $title->getLocalURL()], 'Click here to visit My Special Page!'); // Output the link echo $link;
class MyExtensionHooks { public static function onBeforePageDisplay(OutputPage &$out, Skin &$skin) { // Check if the user is logged in if (! $out->getUser()->isLoggedIn()) { // Get the title of the login page $loginTitle = SpecialPage::getTitleFor('Userlogin'); // Redirect to the login page $out->redirect($loginTitle->getLocalURL()); } } } // Register the hook $wgHooks['BeforePageDisplay'][] = 'MyExtensionHooks::onBeforePageDisplay';This example uses a hook to check if the user is logged in, and if not, redirects them to the login page. The `getTitleFor()` method is used to get the title of the login page, and the `redirect()` method is used to redirect the user to that page. Package/library: MediaWiki core.