User:SamanthaNguyen/Guides/Writing special pages
This page is under construction Please help review and edit this page. |
If you have read the guide on how to write an extension already, continue on! Otherwise, please go back to it as it is a prerequisite for this guide.
Special pages are unique pages in MediaWiki that allow performing a certain function, such as protecting a page so only users with certain permissions can edit it, changing the password to your account, viewing the contributions to the wiki by a specific user, and so on.
Difference between concrete classes and abstract classes
editThis guide makes references to concrete classes and abstract classes. The following bullet points aim to explain the difference to programmers who are writing their first extension in PHP, and don't understand the difference yet. If you already understand these concepts, feel free to skip ahead to the next section.
- A concrete class is considered "complete" as it has implementations for all of its methods, while an abstract does not have implementations for all of its methods.
- An abstract class is prefixed at its declaration with
abstract
, while a concrete class does not have this keyword prefixed. - A concrete class can be instantiated using the
new
keyword, while abstract classes cannot be instantiated. - A concrete class is not necessarily meant to always be extended. An abstract class is always meant to be extended, where the subclass must implement all methods marked as
abstract
.
In this special case, while SpecialPage is a concrete class, it is always meant to be extended.
PHP class hierarchy
edit- SpecialPage: A concrete class that all special pages inherit from. Special pages that need extra functionality can extend one of the listed subclasses that are marked as stable to extend.
- AuthManagerSpecialPage: An abstract class that special pages use for managing authentication requests and session requests.
- LoginSignupSpecialPage: An abstract class that shares the logic to use between Special:UserLogin and Special:CreateAccount.
- ChangesListSpecialPage: An abstract class that special pages use to show a list of changes based on certain conditions. This is used by Special:RecentChanges and Special:Watchlist.
- FormSpecialPage: An abstract class that is used to help create special pages with HTML forms, using the MediaWiki HTMLForm component. This includes by default, but is not limited to: Special:BotPasswords, Special:ChangeContentModel, and Special:ChangeEmail.
- IncludableSpecialPage: A concrete class that can be extended to easily mark a special page as includable. An includable special page means its content can be inserted into another page, by writing two curly brackets on the side of a special page, and the name of a special page. For example, Special:Contributions is includable, and could be written as
{{Special:Contributions/User123}}
(replaceUser123
with your own username in a sandbox page to test this out!) - QueryPage: An abstract class for special pages that query the database.
- ImageQueryPage: An abstract class that outputs a gallery for querying images. This by default includes Special:MostLinkedFiles, Special:UncategorizedFiles, and Special:UnusedFiles.
- PageQueryPage: An abstract class that renders an HTML link to each page in the queried list. This by default includes Special:DeadendPages, Special:LonelyPages, Special:UncategorizedPages (which Special:UncategorizedCategories and Special:UncategorizedTemplates both extend from), and Special:WithoutInterwiki.
- WantedQueryPage: An abstract class for defining wanted pages. This by default includes Special:WantedFiles, Special:WantedPages, Special:WantedTemplates, and Special:WantedCategories.
- UnlistedSpecialPage: An abstract class for making a special page that is unlisted from Special:SpecialPages by default.
- DisabledSpecialPage: A concrete class for marking a special page as disabled. (introduced in 1.33)
- RedirectPage: An abstract class for defining an alias to a special page.
- RedirectSpecialArticle: An abstract class for redirecting to an article on the wiki, versus a special page (e.g. Special:Contributions, Special:Log, etc)
- SpecialRedirectToSpecial: An abstract class for redirecting to a special page on the wiki
- SpecialRedirectWithAction: An abstract class for redirecting an action on the wiki.
- AuthManagerSpecialPage: An abstract class that special pages use for managing authentication requests and session requests.