'user' or 'bot'. The API will throw an error if the user is not logged
in (user) or does not have the 'bot' userright (bot). Based off of the
AssertEdit extension by Steve Sanbeg.
+* WikitextContent will now render redirects with the expected "redirect"
+ header, rather than as an ordered list. Code calling Article::viewRedirect
+ can probably be changed to no longer special-case redirects.
=== Bug fixes in 1.23 ===
* (bug 41759) The "updated since last visit" markers (on history pages, recent
the JavaScript evaluator were updated to support the new format. Plural rules
for some languages have changed, most notably Russian. Affected software
messages have been updated and marked for review at translatewiki.net.
+* (bug 14323) Redirect pages, when viewed with redirect=no, no longer hide the
+ remaining page content.
=== Web API changes in 1.23 ===
* (bug 54884) action=parse&prop=categories now indicates hidden and missing
# Allow extensions do their own custom view for certain pages
$outputDone = true;
- } else {
- $content = $this->getContentObject();
- $rt = $content ? $content->getRedirectChain() : null;
- if ( $rt ) {
- wfDebug( __METHOD__ . ": showing redirect=no page\n" );
- # Viewing a redirect page (e.g. with parameter redirect=no)
- $outputPage->addHTML( $this->viewRedirect( $rt ) );
- # Parse just to get categories, displaytitle, etc.
- $this->mParserOutput = $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions, false );
- $outputPage->addParserOutputNoText( $this->mParserOutput );
- $outputDone = true;
- }
}
break;
case 4:
# Run the parse, protected by a pool counter
wfDebug( __METHOD__ . ": doing uncached parse\n" );
+ $content = $this->getContentObject();
$poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
- $this->getRevIdFetched(), $useParserCache, $this->getContentObject() );
+ $this->getRevIdFetched(), $useParserCache, $content );
if ( !$poolArticleView->execute() ) {
$error = $poolArticleView->getError();
$this->mParserOutput = $poolArticleView->getParserOutput();
$outputPage->addParserOutput( $this->mParserOutput );
+ if ( $content->getRedirectTarget() ) {
+ $outputPage->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
+ }
# Don't cache a dirty ParserOutput object
if ( $poolArticleView->getIsDirty() ) {
}
/**
- * View redirect
+ * Return the HTML for the top of a redirect page
+ *
+ * Chances are you should just be using the ParserOutput from
+ * WikitextContent::getParserOutput instead of calling this for redirects.
*
* @param $target Title|Array of destination(s) to redirect
* @param $appendSubtitle Boolean [optional]
* @return string containing HMTL with redirect link
*/
public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
+ $lang = $this->getTitle()->getPageLanguage();
+ if ( $appendSubtitle ) {
+ $out = $this->getContext()->getOutput();
+ $out->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
+ }
+ return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
+ }
+
+ /**
+ * Return the HTML for the top of a redirect page
+ *
+ * Chances are you should just be using the ParserOutput from
+ * WikitextContent::getParserOutput instead of calling this for redirects.
+ *
+ * @since 1.23
+ * @param Language $lang
+ * @param Title|array $target destination(s) to redirect
+ * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
+ * @return string containing HMTL with redirect link
+ */
+ public static function getRedirectHeaderHtml( Language $lang, $target, $forceKnown = false ) {
global $wgStylePath;
if ( !is_array( $target ) ) {
$target = array( $target );
}
- $lang = $this->getTitle()->getPageLanguage();
$imageDir = $lang->getDir();
- if ( $appendSubtitle ) {
- $out = $this->getContext()->getOutput();
- $out->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
- }
-
// the loop prepends the arrow image before the link, so the first case needs to be outside
/**
}
}
- $rt = $content->getRedirectChain();
- if ( $rt ) {
- $previewHTML = $this->mArticle->viewRedirect( $rt, false );
- } else {
-
- # If we're adding a comment, we need to show the
- # summary as the headline
- if ( $this->section === "new" && $this->summary !== "" ) {
- $content = $content->addSectionHeader( $this->summary );
- }
+ # If we're adding a comment, we need to show the
+ # summary as the headline
+ if ( $this->section === "new" && $this->summary !== "" ) {
+ $content = $content->addSectionHeader( $this->summary );
+ }
- $hook_args = array( $this, &$content );
- ContentHandler::runLegacyHooks( 'EditPageGetPreviewText', $hook_args );
- wfRunHooks( 'EditPageGetPreviewContent', $hook_args );
+ $hook_args = array( $this, &$content );
+ ContentHandler::runLegacyHooks( 'EditPageGetPreviewText', $hook_args );
+ wfRunHooks( 'EditPageGetPreviewContent', $hook_args );
- $parserOptions->enableLimitReport();
+ $parserOptions->enableLimitReport();
- # For CSS/JS pages, we should have called the ShowRawCssJs hook here.
- # But it's now deprecated, so never mind
+ # For CSS/JS pages, we should have called the ShowRawCssJs hook here.
+ # But it's now deprecated, so never mind
- $content = $content->preSaveTransform( $this->mTitle, $wgUser, $parserOptions );
- $parserOutput = $content->getParserOutput( $this->getArticle()->getTitle(), null, $parserOptions );
+ $content = $content->preSaveTransform( $this->mTitle, $wgUser, $parserOptions );
+ $parserOutput = $content->getParserOutput( $this->getArticle()->getTitle(), null, $parserOptions );
- $previewHTML = $parserOutput->getText();
- $this->mParserOutput = $parserOutput;
- $wgOut->addParserOutputNoText( $parserOutput );
+ $previewHTML = $parserOutput->getText();
+ $this->mParserOutput = $parserOutput;
+ $wgOut->addParserOutputNoText( $parserOutput );
- if ( count( $parserOutput->getWarnings() ) ) {
- $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
- }
+ if ( count( $parserOutput->getWarnings() ) ) {
+ $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
}
} catch ( MWContentSerializationException $ex ) {
$m = wfMessage( 'content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage() );
return $dbr->select(
array( 'imagelinks', 'page' ),
- array( 'page_namespace', 'page_title', 'page_is_redirect', 'il_to' ),
+ array( 'page_namespace', 'page_title', 'il_to' ),
array( 'il_to' => $target, 'il_from = page_id' ),
__METHOD__,
array( 'LIMIT' => $limit + 1, 'ORDER BY' => 'il_from', )
$limit = 100;
$out = $this->getContext()->getOutput();
- $res = $this->queryImageLinks( $this->getTitle()->getDBkey(), $limit + 1 );
+
$rows = array();
$redirects = array();
+ foreach ( $this->getTitle()->getRedirectsHere( NS_FILE ) as $redir ) {
+ $redirects[$redir->getDBkey()] = array();
+ $rows[] = (object)array(
+ 'page_namespace' => NS_FILE,
+ 'page_title' => $redir->getDBkey(),
+ );
+ }
+
+ $res = $this->queryImageLinks( $this->getTitle()->getDBkey(), $limit + 1 );
foreach ( $res as $row ) {
- if ( $row->page_is_redirect ) {
- $redirects[$row->page_title] = array();
- }
$rows[] = $row;
}
$count = count( $rows );
}
/**
- * Implement redirect extraction for wikitext.
- *
- * @return null|Title
+ * Extract the redirect target and the remaining text on the page.
*
* @note: migrated here from Title::newFromRedirectInternal()
*
- * @see Content::getRedirectTarget
- * @see AbstractContent::getRedirectTarget
+ * @since 1.23
+ * @return array 2 elements: Title|null and string
*/
- public function getRedirectTarget() {
+ protected function getRedirectTargetAndText() {
global $wgMaxRedirects;
if ( $wgMaxRedirects < 1 ) {
// redirects are disabled, so quit early
- return null;
+ return array( null, $this->getNativeData() );
}
$redir = MagicWord::get( 'redirect' );
- $text = trim( $this->getNativeData() );
+ $text = ltrim( $this->getNativeData() );
if ( $redir->matchStartAndRemove( $text ) ) {
// Extract the first link and see if it's usable
// Ensure that it really does come directly after #REDIRECT
// Some older redirects included a colon, so don't freak about that!
$m = array();
- if ( preg_match( '!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}!', $text, $m ) ) {
+ if ( preg_match( '!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}\s*!', $text, $m ) ) {
// Strip preceding colon used to "escape" categories, etc.
// and URL-decode links
if ( strpos( $m[1], '%' ) !== false ) {
$title = Title::newFromText( $m[1] );
// If the title is a redirect to bad special pages or is invalid, return null
if ( !$title instanceof Title || !$title->isValidRedirectTarget() ) {
- return null;
+ return array( null, $this->getNativeData() );
}
- return $title;
+ return array( $title, substr( $text, strlen( $m[0] ) ) );
}
}
- return null;
+ return array( null, $this->getNativeData() );
+ }
+
+ /**
+ * Implement redirect extraction for wikitext.
+ *
+ * @return null|Title
+ *
+ * @see Content::getRedirectTarget
+ * @see AbstractContent::getRedirectTarget
+ */
+ public function getRedirectTarget() {
+ list( $title, ) = $this->getRedirectTargetAndText();
+ return $title;
}
/**
$options = $this->getContentHandler()->makeParserOptions( 'canonical' );
}
- $po = $wgParser->parse( $this->getNativeData(), $title, $options, true, true, $revId );
+ list( $redir, $text ) = $this->getRedirectTargetAndText();
+ $po = $wgParser->parse( $text, $title, $options, true, true, $revId );
+
+ // Add redirect indicator at the top
+ if ( $redir ) {
+ // Make sure to include the redirect link in pagelinks
+ $po->addLink( $redir );
+ if ( $generateHtml ) {
+ $chain = $this->getRedirectChain();
+ $po->setText(
+ Article::getRedirectHeaderHtml( $title->getPageLanguage(), $chain, false ) .
+ $po->getText()
+ );
+ }
+ }
return $po;
}
$parserOutput = $this->getParserOutput( $wikiPage, $this->mNewRev );
- # Also try to load it as a redirect
- $rt = $this->mNewContent ? $this->mNewContent->getRedirectTarget() : null;
-
- if ( $rt ) {
- $article = Article::newFromTitle( $this->mNewPage, $this->getContext() );
- $out->addHTML( $article->viewRedirect( $rt ) );
-
- # WikiPage::getParserOutput() should not return false, but just in case
- if ( $parserOutput ) {
- # Show categories etc.
- $out->addParserOutputNoText( $parserOutput );
- }
- } elseif ( $parserOutput ) {
+ # WikiPage::getParserOutput() should not return false, but just in case
+ if ( $parserOutput ) {
$out->addParserOutput( $parserOutput );
}
}