[MediaWiki-commits] [Gerrit] mediawiki...VisualEditor[master]: Bypass warming red link cache for wikitext requests

2017-01-12 Thread Esanders (Code Review)
Esanders has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/331934 )

Change subject: Bypass warming red link cache for wikitext requests
..

Bypass warming red link cache for wikitext requests

Wikitext editor doesn't need to know about redlinks
on the page, so this is a waste of time. If the user
switches to VE, they will do a fresh metadata request
at that point.

Change-Id: I57f3fe3fca47dde03bba7905f763abc8a43d0653
---
M ApiVisualEditor.php
1 file changed, 27 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/34/331934/1

diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php
index d09ac29..8cf50e8 100644
--- a/ApiVisualEditor.php
+++ b/ApiVisualEditor.php
@@ -445,34 +445,36 @@
// We do the lookup for the current version. 
This might not be entirely complete
// if we're loading an oldid, but it'll 
probably be close enough, and LinkCache
// will automatically request any additional 
data it needs.
-   $links = [];
-   $wikipage = WikiPage::factory( $title );
-   $popts = $wikipage->makeParserOptions( 
'canonical' );
-   $cached = ParserCache::singleton()->get( 
$article, $popts, true );
-   $links = [
-   // Array of linked pages that are 
missing
-   'missing' => [],
-   // For current revisions: 1 (treat all 
non-missing pages as known)
-   // For old revisions: array of linked 
pages that are known
-   'known' => $restoring || !$cached ? [] 
: 1,
-   ];
-   if ( $cached ) {
-   foreach ( $cached->getLinks() as 
$namespace => $cachedTitles ) {
-   foreach ( $cachedTitles as 
$cachedTitleText => $exists ) {
-   $cachedTitle = 
Title::makeTitle( $namespace, $cachedTitleText );
-   if ( 
!$cachedTitle->isKnown() ) {
-   
$links['missing'][] = $cachedTitle->getPrefixedText();
-   } elseif ( 
$links['known'] !== 1 ) {
-   
$links['known'][] = $cachedTitle->getPrefixedText();
+   $links = null;
+   if ( $params['paction'] !== 'wikitext' ) {
+   $wikipage = WikiPage::factory( $title );
+   $popts = $wikipage->makeParserOptions( 
'canonical' );
+   $cached = 
ParserCache::singleton()->get( $article, $popts, true );
+   $links = [
+   // Array of linked pages that 
are missing
+   'missing' => [],
+   // For current revisions: 1 
(treat all non-missing pages as known)
+   // For old revisions: array of 
linked pages that are known
+   'known' => $restoring || 
!$cached ? [] : 1,
+   ];
+   if ( $cached ) {
+   foreach ( $cached->getLinks() 
as $namespace => $cachedTitles ) {
+   foreach ( $cachedTitles 
as $cachedTitleText => $exists ) {
+   $cachedTitle = 
Title::makeTitle( $namespace, $cachedTitleText );
+   if ( 
!$cachedTitle->isKnown() ) {
+   
$links['missing'][] = $cachedTitle->getPrefixedText();
+   } elseif ( 
$links['known'] !== 1 ) {
+   
$links['known'][] = $cachedTitle->getPrefixedText();
+   }
}
}
}
-   }
-   // Add information about current page
-   if (

[MediaWiki-commits] [Gerrit] mediawiki...VisualEditor[master]: Bypass warming red link cache for wikitext requests

2017-01-14 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/331934 )

Change subject: Bypass warming red link cache for wikitext requests
..


Bypass warming red link cache for wikitext requests

Wikitext editor doesn't need to know about redlinks
on the page, so this is a waste of time. If the user
switches to VE, they will do a fresh metadata request
at that point.

Change-Id: I57f3fe3fca47dde03bba7905f763abc8a43d0653
---
M ApiVisualEditor.php
1 file changed, 30 insertions(+), 25 deletions(-)

Approvals:
  jenkins-bot: Verified
  Jforrester: Looks good to me, approved



diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php
index d09ac29..e132470 100644
--- a/ApiVisualEditor.php
+++ b/ApiVisualEditor.php
@@ -445,34 +445,39 @@
// We do the lookup for the current version. 
This might not be entirely complete
// if we're loading an oldid, but it'll 
probably be close enough, and LinkCache
// will automatically request any additional 
data it needs.
-   $links = [];
-   $wikipage = WikiPage::factory( $title );
-   $popts = $wikipage->makeParserOptions( 
'canonical' );
-   $cached = ParserCache::singleton()->get( 
$article, $popts, true );
-   $links = [
-   // Array of linked pages that are 
missing
-   'missing' => [],
-   // For current revisions: 1 (treat all 
non-missing pages as known)
-   // For old revisions: array of linked 
pages that are known
-   'known' => $restoring || !$cached ? [] 
: 1,
-   ];
-   if ( $cached ) {
-   foreach ( $cached->getLinks() as 
$namespace => $cachedTitles ) {
-   foreach ( $cachedTitles as 
$cachedTitleText => $exists ) {
-   $cachedTitle = 
Title::makeTitle( $namespace, $cachedTitleText );
-   if ( 
!$cachedTitle->isKnown() ) {
-   
$links['missing'][] = $cachedTitle->getPrefixedText();
-   } elseif ( 
$links['known'] !== 1 ) {
-   
$links['known'][] = $cachedTitle->getPrefixedText();
+   // We only do this for visual edits, as the 
wikitext editor doesn't need to know
+   // about redlinks on the page. If the user 
switches to VE, they will do a fresh
+   // metadata request at that point.
+   $links = null;
+   if ( $params['paction'] !== 'wikitext' ) {
+   $wikipage = WikiPage::factory( $title );
+   $popts = $wikipage->makeParserOptions( 
'canonical' );
+   $cached = 
ParserCache::singleton()->get( $article, $popts, true );
+   $links = [
+   // Array of linked pages that 
are missing
+   'missing' => [],
+   // For current revisions: 1 
(treat all non-missing pages as known)
+   // For old revisions: array of 
linked pages that are known
+   'known' => $restoring || 
!$cached ? [] : 1,
+   ];
+   if ( $cached ) {
+   foreach ( $cached->getLinks() 
as $namespace => $cachedTitles ) {
+   foreach ( $cachedTitles 
as $cachedTitleText => $exists ) {
+   $cachedTitle = 
Title::makeTitle( $namespace, $cachedTitleText );
+   if ( 
!$cachedTitle->isKnown() ) {
+   
$links['missing'][] = $cachedTitle->getPrefixedText();
+   } elseif ( 
$links['known'] !== 1 ) {
+   
$links['known'][] = $cachedTitle->getPrefixedText();
+   }