[MediaWiki-commits] [Gerrit] mediawiki/core[master]: refreshLinks.php: allow refreshing by categories, tracking o...

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

Change subject: refreshLinks.php: allow refreshing by categories, tracking or 
not
..


refreshLinks.php: allow refreshing by categories, tracking or not

Needed for selective updates of pages using a particular feature.
Intended to be run in production, so needs to scale.

Bug: T149723
Change-Id: If20fb1f91de8d4227def5b07d6d52b91161ed3fd
---
M RELEASE-NOTES-1.29
M autoload.php
A includes/TrackingCategories.php
M includes/parser/ParserOutput.php
M includes/specials/SpecialTrackingCategories.php
M maintenance/refreshLinks.php
6 files changed, 239 insertions(+), 104 deletions(-)

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



diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29
index d0738e2..3bf50ac 100644
--- a/RELEASE-NOTES-1.29
+++ b/RELEASE-NOTES-1.29
@@ -206,6 +206,8 @@
 * Article::doEditContent() was marked as deprecated, to be removed in 1.30
   or later.
 * ContentHandler::runLegacyHooks() was removed.
+* refreshLinks.php now can be limited to a particular category with 
--category=...
+  or a tracking category with --tracking-category=...
 
 == Compatibility ==
 
diff --git a/autoload.php b/autoload.php
index 7ed08df..e7c97ad 100644
--- a/autoload.php
+++ b/autoload.php
@@ -1459,6 +1459,7 @@
'TitlePrefixSearch' => __DIR__ . '/includes/PrefixSearch.php',
'TitleValue' => __DIR__ . '/includes/title/TitleValue.php',
'TrackBlobs' => __DIR__ . '/maintenance/storage/trackBlobs.php',
+   'TrackingCategories' => __DIR__ . '/includes/TrackingCategories.php',
'TraditionalImageGallery' => __DIR__ . 
'/includes/gallery/TraditionalImageGallery.php',
'TransactionProfiler' => __DIR__ . 
'/includes/libs/rdbms/TransactionProfiler.php',
'TransformParameterError' => __DIR__ . 
'/includes/media/MediaTransformOutput.php',
diff --git a/includes/TrackingCategories.php b/includes/TrackingCategories.php
new file mode 100644
index 000..825860a
--- /dev/null
+++ b/includes/TrackingCategories.php
@@ -0,0 +1,130 @@
+http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Categories
+ */
+
+/**
+ * This class performs some operations related to tracking categories, such as 
creating
+ * a list of all such categories.
+ */
+class TrackingCategories {
+   /** @var Config */
+   private $config;
+
+   /**
+* Tracking categories that exist in core
+*
+* @var array
+*/
+   private static $coreTrackingCategories = [
+   'index-category',
+   'noindex-category',
+   'duplicate-args-category',
+   'expensive-parserfunction-category',
+   'post-expand-template-argument-category',
+   'post-expand-template-inclusion-category',
+   'hidden-category-category',
+   'broken-file-category',
+   'node-count-exceeded-category',
+   'expansion-depth-exceeded-category',
+   'restricted-displaytitle-ignored',
+   'deprecated-self-close-category',
+   ];
+
+   /**
+* @param Config $config
+*/
+   public function __construct( Config $config ) {
+   $this->config = $config;
+   }
+
+   /**
+* Read the global and extract title objects from the corresponding 
messages
+* @return array Array( 'msg' => Title, 'cats' => Title[] )
+*/
+   public function getTrackingCategories() {
+   $categories = array_merge(
+   self::$coreTrackingCategories,
+   ExtensionRegistry::getInstance()->getAttribute( 
'TrackingCategories' ),
+   $this->config->get( 'TrackingCategories' ) // deprecated
+   );
+
+   // Only show magic link tracking categories if they are enabled
+   $enableMagicLinks = $this->config->get( 'EnableMagicLinks' );
+   if ( $enableMagicLinks['ISBN'] ) {
+   $categories[] = 'magiclink-tracking-isbn';
+   }
+   if ( $enableMagicLinks['RFC'] ) {
+   $categories[] = 'magiclink-tracking-rfc';
+   }
+   if ( $enableMagicLinks['PMID'] ) {
+   $categories[] = 'magiclink-tracking-pmid';
+   }
+
+   $trackingCategories = [];
+   foreach ( $categories as $catMsg ) {
+   /*
+* Check if the tracking category varies by namespace
+* Otherwise only pages in the current namespace will 
be displayed
+* If it does vary, show pages considering all 
namespaces
+*/
+   $msgObj = wfMessage( $catMsg )->inContentLanguage();
+   $allCats = 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: refreshLinks.php: allow refreshing by categories, tracking o...

2016-11-29 Thread MaxSem (Code Review)
MaxSem has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/324347

Change subject: refreshLinks.php: allow refreshing by categories, tracking or 
not
..

refreshLinks.php: allow refreshing by categories, tracking or not

Needed for selective updates of pages using a particular feature.
Intended to be run in production, so needs to scale.

Bug: T149723
Change-Id: If20fb1f91de8d4227def5b07d6d52b91161ed3fd
---
M RELEASE-NOTES-1.29
M includes/specials/SpecialTrackingCategories.php
M maintenance/refreshLinks.php
3 files changed, 98 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/47/324347/1

diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29
index 5b5640f..c85e6b8 100644
--- a/RELEASE-NOTES-1.29
+++ b/RELEASE-NOTES-1.29
@@ -54,6 +54,8 @@
 === Other changes in 1.29 ===
 * Database::getSearchEngine() (deprecated in 1.28) was removed. Use
   SearchEngineFactory::getSearchEngineClass() instead.
+* refreshLinks.php now can be limited to a particular category with 
--category=...
+  or a tracking category with --tracking-category=
 
 == Compatibility ==
 
diff --git a/includes/specials/SpecialTrackingCategories.php 
b/includes/specials/SpecialTrackingCategories.php
index 4c6a345..787db03 100644
--- a/includes/specials/SpecialTrackingCategories.php
+++ b/includes/specials/SpecialTrackingCategories.php
@@ -76,7 +76,7 @@
"
);
 
-   $trackingCategories = $this->prepareTrackingCategoriesData();
+   $trackingCategories = $this->getTrackingCategories();
 
$batch = new LinkBatch();
foreach ( $trackingCategories as $catMsg => $data ) {
@@ -145,7 +145,7 @@
 * Read the global and extract title objects from the corresponding 
messages
 * @return array Array( 'msg' => Title, 'cats' => Title[] )
 */
-   private function prepareTrackingCategoriesData() {
+   public function getTrackingCategories() {
$categories = array_merge(
self::$coreTrackingCategories,
ExtensionRegistry::getInstance()->getAttribute( 
'TrackingCategories' ),
diff --git a/maintenance/refreshLinks.php b/maintenance/refreshLinks.php
index e7a4d06..9d54901 100644
--- a/maintenance/refreshLinks.php
+++ b/maintenance/refreshLinks.php
@@ -29,6 +29,8 @@
  * @ingroup Maintenance
  */
 class RefreshLinks extends Maintenance {
+   const REPORTING_INTERVAL = 100;
+
/** @var int|bool */
protected $namespace = false;
 
@@ -43,6 +45,8 @@
$this->addOption( 'dfn-chunk-size', 'Maximum number of existent 
IDs to check per ' .
'query, default 10', false, true );
$this->addOption( 'namespace', 'Only fix pages in this 
namespace', false, true );
+   $this->addOption( 'category', 'Only fix pages in this 
category', false, true );
+   $this->addOption( 'tracking-category', 'Only fix pages in this 
tracking category', false, true );
$this->addArg( 'start', 'Page_id to start from, default 1', 
false );
$this->setBatchSize( 100 );
}
@@ -61,7 +65,15 @@
} else {
$this->namespace = (int)$ns;
}
-   if ( !$this->hasOption( 'dfn-only' ) ) {
+   if ( ( $category = $this->getOption( 'category', false ) ) !== 
false ) {
+   $title = Title::makeTitle( NS_CATEGORY, $category );
+   if ( !$title ) {
+   $this->error( "'$category' is an invalid 
category name!\n", true );
+   }
+   $this->refreshCategory( $category );
+   } elseif ( ( $category = $this->getOption( 'tracking-category', 
false ) ) !== false ) {
+   $this->refreshTrackingCategory( $category );
+   } elseif ( !$this->hasOption( 'dfn-only' ) ) {
$new = $this->getOption( 'new-only', false );
$redir = $this->getOption( 'redirects-only', false );
$oldRedir = $this->getOption( 'old-redirects-only', 
false );
@@ -89,7 +101,6 @@
private function doRefreshLinks( $start, $newOnly = false,
$end = null, $redirectsOnly = false, $oldRedirectsOnly = false
) {
-   $reportingInterval = 100;
$dbr = $this->getDB( DB_REPLICA, [ 'vslow' ] );
 
if ( $start === null ) {
@@ -124,7 +135,7 @@
$i = 0;
 
foreach ( $res as $row ) {
-   if ( !( ++$i % $reportingInterval ) ) {
+   if ( !( ++$i % self::REPORTING_INTERVAL ) ) {
$this->output( "$i\n" );