Manual:Article.php
| MediaWiki File: Article.php | |
|---|---|
| Location: | /includes/ |
| Source code: | |
| Classes: | Article |
The Article class represents a MediaWiki article and its history. It encapsulates access to the way articles are stored in the database, and allows access to properties such as article text (in Wikitext format), flags, etc.
This file contains e.g. one version of function view() for viewing a page, called from ViewAction.php (another version is in RawAction.php). This function fetches the wikitext $mContent of the page from the database using functions getContent, loadContent and fetchContent, and assigns this to $text. After that it calls function outputWikiText to process $text.
Contents |
[edit] Creating a new Article object
To instantiate Article, call one of the static factory methods:
Article::newFromId($id), where $id is an article id.Article::newFromTitle(Title $title, IContextSource $context): creates an Article object of the appropriate class for the given title.Article::newFromWikiPage(WikiPage $page, IContextSource $context): creates an Article object of the appropriate class for the given page.
[edit] Methods
getContent(): get the text of this revision. This function has side effects. Do not use this function if you only want the real revision text if any.getContext()(since 1.18): gets the context this Article is executed in.getOldID(): gets the oldid of the article that is to be shown, or 0 for the current revision.getPage()(since 1.19): gets the WikiPage object of this instance.getParserOptions(): gets the parser options suitable for rendering the primary article wikitext.getParserOutput([$oldid, User $user]): a lightweight method to get the parser output for a page, checking the parser cache and so on. It doesn't consider most of the stuff thatWikiPage::view()is forced to consider.getRevIdFetched(): gets the rev ID used on page views.getRevisionFetched()(since 1.19): get the fetched Revision object depending on request parameters or null on failure.getRobotPolicy(string $action, ParserOutput $pOutput): gets the robot policy to be used for the current view. $action is a string containing the action= GET parameter and $pOutput.getTitle(): gets the Title associated with this page.isCurrent(): returns true if the currently-referenced revision is the current edit to this page (and it exists).isFileCacheable(): returns true if the page can be cached.view(): this method handles the (default) action of viewing a page. Actions (like 'view', 'revert', 'delete', etc) are handled by Action subclasses. Theshow()method of the ViewAction calls Article::view() to do the actual work.
See http://svn.wikimedia.org/doc/classArticle.html for a complete lists of methods.
[edit] Hooks
Hooks called from this file are listed in the Category:MediaWiki hooks included in Article.php category.
[edit] Example
To create an Article object and print the raw wiki text from that article, for example from within an extension, you could do something like this:
$id = Title::newFromText("Test_page")->getArticleId(); //Get the id for the article called Test_page $myArticle = Article::newFromId($id); //Make an article object from that id echo $myArticle->getRawText(); //Print the raw wiki text of the article
[edit] See also
| Language: | English • Français • 日本語 • Polski |
|---|