* @return ParserOutput or false if the given revsion ID is not found
*/
public function getParserOutput( $oldid = null, User $user = null ) {
- $user = is_null( $user ) ? $this->getContext()->getUser() : $user;
- $parserOptions = $this->mPage->makeParserOptions( $user );
+ if ( $user === null ) {
+ $parserOptions = $this->getParserOptions();
+ } else {
+ $parserOptions = $this->mPage->makeParserOptions( $user );
+ }
return $this->mPage->getParserOutput( $parserOptions, $oldid );
}
*/
public function getParserOptions() {
if ( !$this->mParserOptions ) {
- $this->mParserOptions = $this->mPage->makeParserOptions( $this->getContext()->getUser() );
+ $this->mParserOptions = $this->mPage->makeParserOptions( $this->getContext() );
}
// Clone to allow modifications of the return value without affecting cache
return clone $this->mParserOptions;
/**
* Get parser options suitable for rendering the primary article wikitext
- * @param User|string $user User object or 'canonical'
+ *
+ * @param IContextSource|User|string $context One of the following:
+ * - IContextSource: Use the User and the Language of the provided
+ * context
+ * - User: Use the provided User object and $wgLang for the language,
+ * so use an IContextSource object if possible.
+ * - 'canonical': Canonical options (anonymous user with default
+ * preferences and content language).
* @return ParserOptions
*/
- public function makeParserOptions( $user ) {
+ public function makeParserOptions( $context ) {
global $wgContLang;
- if ( $user instanceof User ) { // settings per user (even anons)
- $options = ParserOptions::newFromUser( $user );
+
+ if ( $context instanceof IContextSource ) {
+ $options = ParserOptions::newFromContext( $context );
+ } elseif ( $context instanceof User ) { // settings per user (even anons)
+ $options = ParserOptions::newFromUser( $context );
} else { // canonical settings
$options = ParserOptions::newFromUserAndLang( new User, $wgContLang );
}
+
$options->enableLimitReport(); // show inclusion/loop reports
$options->setTidy( true ); // fix bad HTML
+
return $options;
}
$this->getContext()->setLanguage( Language::factory( $params['uselang'] ) );
}
- $popts = ParserOptions::newFromContext( $this->getContext() );
- $popts->setTidy( true );
- $popts->enableLimitReport( !$params['disablepp'] );
-
$redirValues = null;
// Return result
}
$titleObj = $rev->getTitle();
-
$wgTitle = $titleObj;
+ $pageObj = WikiPage::factory( $titleObj );
+ $popts = $pageObj->makeParserOptions( $this->getContext() );
+ $popts->enableLimitReport( !$params['disablepp'] );
// If for some reason the "oldid" is actually the current revision, it may be cached
if ( $titleObj->getLatestRevID() === intval( $oldid ) ) {
// May get from/save to parser cache
- $p_result = $this->getParsedSectionOrText( $titleObj, $popts, $pageid,
+ $p_result = $this->getParsedSectionOrText( $pageObj, $popts, $pageid,
isset( $prop['wikitext'] ) ) ;
} else { // This is an old revision, so get the text differently
$this->text = $rev->getText( Revision::FOR_THIS_USER, $this->getUser() );
foreach ( (array)$redirValues as $r ) {
$to = $r['to'];
}
- $titleObj = Title::newFromText( $to );
- } else {
- if ( !is_null ( $pageid ) ) {
- $reqParams['pageids'] = $pageid;
- $titleObj = Title::newFromID( $pageid );
- } else { // $page
- $to = $page;
- $titleObj = Title::newFromText( $to );
- }
- }
- if ( !is_null ( $pageid ) ) {
- if ( !$titleObj ) {
- // Still throw nosuchpageid error if pageid was provided
- $this->dieUsageMsg( array( 'nosuchpageid', $pageid ) );
- }
- } elseif ( !$titleObj || !$titleObj->exists() ) {
- $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );
+ $pageParams = array( 'title' => $to );
+ } elseif ( !is_null( $pageid ) ) {
+ $pageParams = array( 'pageid' => $pageid );
+ } else { // $page
+ $pageParams = array( 'title' => $page );
}
+
+ $pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' );
+ $titleObj = $pageObj->getTitle();
$wgTitle = $titleObj;
if ( isset( $prop['revid'] ) ) {
- $oldid = $titleObj->getLatestRevID();
+ $oldid = $pageObj->getLatest();
}
+ $popts = $pageObj->makeParserOptions( $this->getContext() );
+ $popts->enableLimitReport( !$params['disablepp'] );
+
// Potentially cached
- $p_result = $this->getParsedSectionOrText( $titleObj, $popts, $pageid,
+ $p_result = $this->getParsedSectionOrText( $pageObj, $popts, $pageid,
isset( $prop['wikitext'] ) ) ;
}
} else { // Not $oldid, $pageid, $page. Hence based on $text
$this->dieUsageMsg( array( 'invalidtitle', $title ) );
}
$wgTitle = $titleObj;
+ $pageObj = WikiPage::factory( $titleObj );
+
+ $popts = $pageObj->makeParserOptions( $this->getContext() );
+ $popts->enableLimitReport( !$params['disablepp'] );
if ( $this->section !== false ) {
$this->text = $this->getSectionText( $this->text, $titleObj->getText() );
}
/**
- * @param $titleObj Title
+ * @param $page WikiPage
* @param $popts ParserOptions
* @param $pageId Int
* @param $getWikitext Bool
* @return ParserOutput
*/
- private function getParsedSectionOrText( $titleObj, $popts, $pageId = null, $getWikitext = false ) {
+ private function getParsedSectionOrText( $page, $popts, $pageId = null, $getWikitext = false ) {
global $wgParser;
- $page = WikiPage::factory( $titleObj );
-
if ( $this->section !== false ) {
$this->text = $this->getSectionText( $page->getRawText(), !is_null( $pageId )
- ? 'page id ' . $pageId : $titleObj->getText() );
+ ? 'page id ' . $pageId : $page->getTitle()->getPrefixedText() );
// Not cached (save or load)
- return $wgParser->parse( $this->text, $titleObj, $popts );
+ return $wgParser->parse( $this->text, $page->getTitle(), $popts );
} else {
// Try the parser cache first
// getParserOutput will save to Parser cache if able