Jump to content


From mediawiki.org



The Article object encapsulates access to the "page" table of the database. The object represents an article, and maintains state such as text (in Wikitext format), flags, etc.

The CategoryPage and ImagePage objects are child objects of the Article object, and are used specifically for Category pages and Image pages.



Use the Context object to get what you need. Since 1.19, Context objects have a getWikiPage() to access the corresponding WikiPage object. Where you get this context object from depends on where your code is running. Many major classes extend ContextSource, which means you can just do $someObject->getContext() to get the context and $someObject->getWikiPage() for the WikiPage object. As of this writing that includes ApiBase, CategoryViewer, ChangesList, DerivativeContext, DifferenceEngine, HTMLForm, ImportReporter, IndexPager, OutputPage, RevisionListBase, Skin. Some other classes support getContext() which don't have ContextSource as a parent class, such as SpecialPage (So if you're writing a SpecialPage, you can often do $this->getContext() to get the context).

If you need to use a method which is in Article but not WikiPage and have a context object, say $context, you can use Article::newFromTitle( $context->getTitle(), $context );, please also note the following things:

  • The displayed revision's ID is accessible through OutputPage->getRevisionId() or Skin->getRevisionId() and the fact that this is the current revision of the page can be accessed through Skin->isRevisionCurrent() (instead of Article->isCurrent())
  • The text of the latest revision of the current page (not necessarily of the displayed revision) is accessible through WikiPage->getRawText(); depending on what you use Article->getContent() for, you may prefer this one.

Sample Code


Use $article->getPage()->getContent()->getNativeData() to replace this.