Kipcool has submitted this change and it was merged.

Change subject: SpecialPage:OWDownloads
......................................................................


SpecialPage:OWDownloads

* issue: the updated date might be a little off by the nature of the job queue.

* patch 2 trailing corrections.

* patch 3 abandon

* patch 4 corrections to patch 3

* patch 5 adjustments and corrections

* patch 6 $wgScript usage change on SpecialOWDownloads.php

* patch 7 deleted unused functions and moved csv function to its own
          script

* patch 8 added definition csv job generator. Using a job that creates
          other jobs until the whole file is generated. A way to escape
          the randomness of job execution. Drawback is that it takes a
          lot of page activity to finish... unless used with runJobs.php

* patch 9 (Kip) still learning some php... apparently we don't need to
define "global" if not inside a function (amended WikiDataGlobals.php).

Change-Id: If21ee9db67d025891ee851e68a96646124dbe14a
---
M App.php
M OmegaWiki/WikiDataGlobals.php
A includes/formatCSV.php
A includes/jobs/OWDefinedExpressionListJob.php
A includes/jobs/OWExpressionListJob.php
A includes/jobs/WldJobs.php
A includes/setup/OWSpecials.php
R includes/specials/SpecialDatasearch.php
A includes/specials/SpecialOWDownloads.php
R includes/specials/SpecialOWStatistics.php
10 files changed, 634 insertions(+), 61 deletions(-)

Approvals:
  Kipcool: Verified; Looks good to me, approved



diff --git a/App.php b/App.php
index 018b151..3708fe4 100644
--- a/App.php
+++ b/App.php
@@ -4,9 +4,15 @@
 
 $dir = dirname( __FILE__ ) . '/';
 
+$dir = str_replace( '\\', '/', $dir );
+
+require_once( $dir . 'OmegaWiki/WikiDataGlobals.php' );
 require_once( $dir . 'OmegaWiki/Wikidata.php' );
-require_once( $dir . 'SpecialLanguages.php' );
-require_once( $dir . 'includes/api/OmegaWikiExt.php');
+
+require_once( $wgWldScriptPath . 'SpecialLanguages.php' );
+
+// API
+require_once( $wgWldAPIScriptPath . 'OmegaWikiExt.php');
 
 $wgExtensionCredits['other'][] = array(
        'path'            => __FILE__,
@@ -23,24 +29,7 @@
        'descriptionmsg'  => 'wikidata-desc',
 );
 
-$wgExtensionCredits['specialpage'][] = array(
-       'name' => 'SpecialConceptMapping',
-       'author' => 'Kim Bruning',
-);
-
-$wgExtensionCredits['specialpage'][] = array(
-       'name' => 'SpecialCopy',
-       'author' => 'Alan Smithee',
-);
-
-/* the API "wikidata" does not work.
- * Should be repaired, if someone has the courage to go through
- * the undocumented code...
- */
-// $wgAPIModules['wikidata'] = 'ApiWikiData';
-
 $wgExtensionMessagesFiles['Wikidata'] = $dir . 'Wikidata.i18n.php';
-
 
 // Resource modules
 
@@ -74,11 +63,6 @@
 $wgAutoloadClasses['WikidataArticle'      ] = $dir . 
'includes/WikidataArticle.php';
 $wgAutoloadClasses['WikidataEditPage'     ] = $dir . 
'includes/WikidataEditPage.php';
 $wgAutoloadClasses['WikidataPageHistory'  ] = $dir . 
'includes/WikidataPageHistory.php';
-// api wikidata is disabled since it does not work
-// $wgAutoloadClasses['ApiWikiData'          ] = $dir . 
'includes/api/ApiWikiData.php';
-// $wgAutoloadClasses['ApiWikiDataFormatBase'] = $dir . 
'includes/api/ApiWikiDataFormatBase.php';
-// $wgAutoloadClasses['ApiWikiDataFormatXml' ] = $dir . 
'includes/api/ApiWikiDataFormatXml.php';
-
 
 # FIXME: Rename this to reduce chance of collision.
 $wgAutoloadClasses['OmegaWiki'] = $dir . 'OmegaWiki/OmegaWiki.php';
@@ -91,15 +75,14 @@
 
 $wgAutoloadClasses['SpecialSuggest'] = $dir . 'OmegaWiki/SpecialSuggest.php';
 $wgAutoloadClasses['SpecialSelect'] = $dir . 'OmegaWiki/SpecialSelect.php';
-$wgAutoloadClasses['SpecialDatasearch'] = $dir . 
'OmegaWiki/SpecialDatasearch.php';
 // $wgAutoloadClasses['SpecialTransaction'] = $dir . 
'OmegaWiki/SpecialTransaction.php';
 $wgAutoloadClasses['SpecialNeedsTranslation'] = $dir . 
'OmegaWiki/SpecialNeedsTranslation.php';
 $wgAutoloadClasses['SpecialImportLangNames'] = $dir . 
'OmegaWiki/SpecialImportLangNames.php';
 $wgAutoloadClasses['SpecialAddCollection'] = $dir . 
'OmegaWiki/SpecialAddCollection.php';
 $wgAutoloadClasses['SpecialConceptMapping'] = $dir . 
'OmegaWiki/SpecialConceptMapping.php';
 $wgAutoloadClasses['SpecialCopy'] = $dir . 'OmegaWiki/SpecialCopy.php';
-$wgAutoloadClasses['SpecialOWStatistics'] = $dir . 
'OmegaWiki/SpecialOWStatistics.php';
 
+require_once( $wgWldSetupScriptPath . "OWSpecials.php" );
 
 # FIXME: These should be modified to make Wikidata more reusable.
 $wgAvailableRights[] = 'editwikidata-uw';
@@ -109,7 +92,7 @@
 $wgAvailableRights[] = 'addcollection';
 $wgAvailableRights[] = 'editClassAttributes';
 
-$wgGroupPermissions['*']['editClassAttributes'] = false;  
+$wgGroupPermissions['*']['editClassAttributes'] = false;
 
 $wgGroupPermissions['wikidata-omega']['editwikidata-uw'] = true;
 $wgGroupPermissions['wikidata-omega']['deletewikidata-uw'] = true;
@@ -136,7 +119,7 @@
 $wdTermDBDataSet = 'uw';
 
 # This is the dataset that should be shown to all users by default.
-# It _must_ exist for the Wikidata application to be executed 
+# It _must_ exist for the Wikidata application to be executed
 # successfully.
 $wdDefaultViewDataSet = 'uw';
 
@@ -164,17 +147,14 @@
 # in a single database.
 if ( !isset( $wdSiteContext ) ) $wdSiteContext = "uw";
 
-
 $wgSpecialPages['Suggest'] = 'SpecialSuggest';
 $wgSpecialPages['Select'] = 'SpecialSelect';
-$wgSpecialPages['Datasearch'] = 'SpecialDatasearch';
 // $wgSpecialPages['Transaction'] = 'SpecialTransaction';
 $wgSpecialPages['NeedsTranslation'] = 'SpecialNeedsTranslation';
 $wgSpecialPages['ImportLangNames'] = 'SpecialImportLangNames';
 $wgSpecialPages['AddCollection'] = 'SpecialAddCollection';
 $wgSpecialPages['ConceptMapping'] = 'SpecialConceptMapping';
 $wgSpecialPages['Copy'] = 'SpecialCopy';
-$wgSpecialPages['ow_statistics'] = 'SpecialOWStatistics';
 
 #
 ## Hooks
@@ -191,6 +171,12 @@
 $wgHooks['PageContentLanguage'][] = 
'WikiLexicalDataHooks::onPageContentLanguage';
 $wgHooks['SkinTemplateNavigation'][] = 
'WikiLexicalDataHooks::onSkinTemplateNavigation';
 
+// Job Classes
+$wgAutoloadClasses['CreateExpressionListJob'] = $wgWldJobsScriptPath . 
'OWExpressionListJob.php';
+$wgJobClasses['CreateExpressionList'] = 'CreateExpressionListJob';
+$wgAutoloadClasses['CreateDefinedExpressionListJob'] = $wgWldJobsScriptPath . 
'OWDefinedExpressionListJob.php';
+$wgJobClasses['CreateDefinedExpressionList'] = 
'CreateDefinedExpressionListJob';
+
 // LocalApp.php is optional. Its function is like LocalSettings.php,
 // if you want to separate the MediaWiki configuration from the Wikidata 
configuration
 if ( file_exists ( dirname(__FILE__) . "LocalApp.php" )) {
diff --git a/OmegaWiki/WikiDataGlobals.php b/OmegaWiki/WikiDataGlobals.php
index 5f4fde4..6eb1f10 100644
--- a/OmegaWiki/WikiDataGlobals.php
+++ b/OmegaWiki/WikiDataGlobals.php
@@ -40,22 +40,30 @@
 define ( 'WLD_TRANSLATED_TEXT', "transl" );
 
 # Global context override. This is an evil hack to allow saving, basically.
-global $wdCurrentContext;
 $wdCurrentContext = null;
 
-global $wgIso639_3CollectionId;
 $wgIso639_3CollectionId = null;
+
+// paths
+$wgWldScriptPath       = __DIR__ . '/';
+$wgWldScriptPath = str_replace( '\\', '/', $wgWldScriptPath );
+$wgWldScriptPath = str_replace( 'OmegaWiki/', '', $wgWldScriptPath );
+
+$wgWldOwScriptPath     = $wgWldScriptPath . "OmegaWiki/";
+$wgWldDownloadScriptPath = $IP . "/downloads/";
+$wgWldIncludesScriptPath = $wgWldScriptPath . "includes/";
+$wgWldSpecialsScriptPath = $wgWldIncludesScriptPath . "specials/";
+$wgWldAPIScriptPath      = $wgWldIncludesScriptPath . "api/";
+$wgWldSetupScriptPath    = $wgWldIncludesScriptPath . "setup/";
+$wgWldJobsScriptPath     = $wgWldIncludesScriptPath . "jobs/";
 
 /**
  * the DM of an annotation to use for sorting expression
  * such as the DM representing the concept "part of speech"
  */
-global $wgWldSortingAnnotationDM;
 $wgWldSortingAnnotationDM = null;
 
 // Defined meaning editor
-global $wdDefinedMeaningAttributesOrder;
-
 $wdDefinedMeaningAttributesOrder = array(
        WLD_SYNT_ATTRIBUTES,
        WLD_DEFINITION,
@@ -70,19 +78,9 @@
 );
 
 // Page titles
-
-global $wgUseExpressionPageTitlePrefix;
-
 $wgUseExpressionPageTitlePrefix = true;        # malafaya: Use the expression 
prefix "Multiple meanings:" from message ow_Multiple_meanings
 
 // Search page
-
-global
-       $wgWldSearchExternalIDDefault,
-       $wgWldSearchWordsDefault,
-       $wgWldSearchExternalIDOption,
-       $wgWldSearchWordsOption;
-
 $wgWldSearchExternalIDDefault = false;
 $wgWldSearchWordsDefault = true;
 
@@ -91,9 +89,6 @@
 $wgWldSearchExternalIDOption = false;
 $wgWldSearchWordsOption = false;
 
-
-global
-       $wgPropertyToColumnFilters;
 
 /**
  * $wgPropertyToColumnFilters is an array of property to column filters
diff --git a/includes/formatCSV.php b/includes/formatCSV.php
new file mode 100644
index 0000000..f6e2771
--- /dev/null
+++ b/includes/formatCSV.php
@@ -0,0 +1,21 @@
+<?php
+/**
+ * Some CSV functions for WLD
+ */
+
+/**
+ * Simple formatting
+ */
+
+class WldFormatCSV {
+       function formatCSVcolumn( $column ) {
+
+               if( is_numeric( $column ) ) {
+                       return $column;
+               }
+               if( preg_match( '/\"/', $column ) ) {
+                       $column = str_replace( '"', '""', $column );
+               }
+               return '"' . $column . '"';
+       }
+}
diff --git a/includes/jobs/OWDefinedExpressionListJob.php 
b/includes/jobs/OWDefinedExpressionListJob.php
new file mode 100644
index 0000000..dd1fbb9
--- /dev/null
+++ b/includes/jobs/OWDefinedExpressionListJob.php
@@ -0,0 +1,191 @@
+<?php
+/**
+ * Create a list of Expressions with Definitions
+ *
+ */
+global $wgWldOwScriptPath, $wgWldIncludesScriptPath;
+require_once( $wgWldOwScriptPath . 'languages.php' );
+require_once( $wgWldIncludesScriptPath . 'formatCSV.php' );
+
+Class CreateDefinedExpressionListJob extends Job {
+
+       public function __construct( $title, $params ) {
+               parent::__construct( 'CreateDefinedExpressionList', $title, 
$params );
+       }
+
+       /**
+        * Execute the job
+        *
+        * @return bool
+        */
+       public function run() {
+               // Load data from $this->params and $this->title
+               if ( isset( $this->params['langcode'] ) ) {
+                       $languageId = $this->params['langcode'];
+               }
+
+               if ( isset( $this->params['type'] ) ) {
+                       $type = $this->params['type'];
+               }
+
+               if ( isset( $this->params['format'] ) ) {
+                       $format = $this->params['format'];
+               }
+
+               if ( isset( $this->params['start'] ) ) {
+                       $start = $this->params['start'];
+               }
+
+               if ( $type && $languageId && $format && $start ) {
+                       $this->createDefinedList( $type, $languageId, $format, 
$start );
+                       return true;
+               }
+
+               // Perform your updates
+
+               return false;
+       }
+
+       protected function createDefinedList( $type, $code, $format, $start ) {
+               global $wgWldDownloadScriptPath;
+               $csv = new WldFormatCSV();
+
+               // the greater the value of $sqlLimit the faster the download 
file is
+               // finished but the slower each web page loads while the job is 
being
+               // processed.
+               $sqlLimit = 100;
+               $ctrOver = $sqlLimit + 1;
+
+               $options['OFFSET'] = $start;
+
+               // we need an extra line to determine if a new job is needed.
+               $options['LIMIT'] = $sqlLimit + 1;
+
+               // Why order by expression_id? To avoid duplication of words
+               // and skipping of some. When a language is constantly edited,
+               // order by spelling would not accurately get all unique 
expressions
+               // when job queued.
+               $options['ORDER BY'] = 'expression_id';
+
+               // language specifics
+               $languageId = getLanguageIdForIso639_3( $code );
+               $languageExpressions = $this->getLanguageIdExpressions( 
$languageId, $options );
+
+               // create File name
+               $fileName = $wgWldDownloadScriptPath;
+               $fileName .= $type . '_' . $code . '.' . $format;
+
+               // When someone updates the file while someone is
+               // downloading the file, the file may ( in my mind ),
+               // be corrupted. So process it first as a temporary file,
+               // delete the original file, and rename the temporary file ~he
+               $tempFileName = $wgWldDownloadScriptPath;
+               $tempFileName .= "tmp_$type" . "_$code.tmp";
+
+               if ( $start == 1 ) {
+                       $fh = fopen( $tempFileName, 'w' );
+                       fwrite( $fh, '"Expression","Definition"' . "\n" );
+               } else {
+                       $fh = fopen( $tempFileName, 'a' );
+               }
+               $ctr = 0;
+               if ( $start != 0 ) {
+                       foreach( $languageExpressions as $row ) {
+                               $spelling = $csv->formatCSVcolumn( 
$row->spelling );
+                               // create a function to check if the expression 
has
+                               // a dm translated, if so write it to the file
+                               if ( $ctr != $ctrOver ) {
+                                       $defineList = $this->getDefineList( 
$row->spelling, $languageId );
+                                       foreach ( $defineList as $text ) {
+                                               fwrite( $fh, $spelling . ',' . 
$csv->formatCSVcolumn( $text ) . "\n" );
+                                       }
+                                       $defineList = array();
+                               }
+                               $ctr ++;
+                       }
+               }
+               fclose( $fh );
+
+               // If the number of lines processed is $sqlLimit . we can't be 
sure
+               // if it has a complete job or not. It's safer to assume that
+               // it is not. ~he
+
+               // incomplete job
+               if( $ctr >= $sqlLimit ) {
+                       $jobParams = array( 'type' => $type, 'langcode' => 
$code, 'format' => $format );
+                       $jobParams['start'] = $start + $sqlLimit;
+                       $jobName = 'User:JobQuery/' . $type . '_' . $code . '.' 
. $format;
+                       $title = Title::newFromText( $jobName );
+                       $job = new CreateDefinedExpressionListJob( $title, 
$jobParams );
+                       JobQueueGroup::singleton()->push( $job ); // mediawiki 
>= 1.21
+               } else { // complete job
+                       if ( file_exists( $fileName ) ) {
+                               unlink( $fileName );
+                       }
+                       rename( $tempFileName, $fileName );
+               }
+
+       }
+
+       function getDefineList( $spelling, $languageId ) {
+               $dmlist = getExpressionMeaningIds( $spelling );
+               // There are duplicates using getExpressionMeaningIds !!!
+               $dmlist = array_unique ( $dmlist );
+               $express = array();
+               foreach ( $dmlist as $definedMeaningId ) {
+                       $text = getDefinedMeaningDefinitionForLanguage( 
$definedMeaningId, $languageId );
+                       if ( $text ) {
+                               $express[] = $text;
+                       }
+               }
+               $dmlist = array();
+               return $express;
+       }
+
+       /**
+        * returns an array of "Expression" objects
+        * for a language
+        *
+        * else returns null
+        */
+       function getLanguageIdExpressions( $languageId, $options = array(), $dc 
= null ) {
+               if ( is_null( $dc ) ) {
+                       $dc = wdGetDataSetContext();
+               }
+               $dbr = wfGetDB( DB_SLAVE );
+
+               if ( isset( $options['ORDER BY'] ) ) {
+                       $cond['ORDER BY']= $options['ORDER BY'];
+               } else {
+                       $cond['ORDER BY']= 'spelling';
+               }
+
+               if ( isset( $options['LIMIT'] ) ) {
+                       $cond['LIMIT']= $options['LIMIT'];
+               }
+               if ( isset( $options['OFFSET'] ) ) {
+                       $cond['OFFSET']= $options['OFFSET'];
+               }
+
+               $queryResult = $dbr->select(
+                       "{$dc}_expression",
+                       'spelling',
+                       array(
+                               'language_id' => $languageId,
+                               'remove_transaction_id' => null
+                       ),
+                       __METHOD__,
+                       $cond
+               );
+
+               $expression = array();
+               foreach ( $queryResult as $exp ) {
+                       $expression[] = $exp;
+               }
+
+               if ( $expression ) {
+                       return $expression;
+               }
+               return null;
+       }
+}
diff --git a/includes/jobs/OWExpressionListJob.php 
b/includes/jobs/OWExpressionListJob.php
new file mode 100644
index 0000000..75f4874
--- /dev/null
+++ b/includes/jobs/OWExpressionListJob.php
@@ -0,0 +1,124 @@
+<?php
+/**
+ * Create a list of Expressions
+ *
+ */
+global $wgWldOwScriptPath, $wgWldIncludesScriptPath;
+require_once( $wgWldOwScriptPath . 'languages.php' );
+require_once( $wgWldIncludesScriptPath . 'formatCSV.php' );
+
+Class CreateExpressionListJob extends Job {
+
+       public function __construct( $title, $params ) {
+               parent::__construct( 'CreateExpressionList', $title, $params );
+       }
+
+       /**
+        * Execute the job
+        *
+        * @return bool
+        */
+       public function run() {
+               // Load data from $this->params and $this->title
+               if ( isset( $this->params['langcode'] ) ) {
+                       $languageId = $this->params['langcode'];
+               }
+
+               if ( isset( $this->params['type'] ) ) {
+                       $type = $this->params['type'];
+               }
+
+               if ( isset( $this->params['format'] ) ) {
+                       $format = $this->params['format'];
+               }
+
+               if ( $type && $languageId && $format ) {
+                       $this->createList( $type, $languageId, $format );
+                       return true;
+               }
+
+               // Perform your updates
+
+               return false;
+       }
+
+       protected function createList( $type, $code, $format ) {
+               global $wgWldDownloadScriptPath;
+               $csv = new WldFormatCSV();
+
+               // language specifics
+               $languageId = getLanguageIdForIso639_3( $code );
+               $languageExpressions = $this->getLanguageIdExpressions( 
$languageId );
+
+               // create File name
+               $fileName = $wgWldDownloadScriptPath;
+               $fileName .= $type . '_' . $code . ".$format";
+
+               // When someone updates the file while someone is
+               // downloading the file, the file may ( in my mind ),
+               // be corrupted. So process it first as a temporary file,
+               // delete the original file, and rename the temporary file ~he
+               $tempFileName = $wgWldDownloadScriptPath;
+               $tempFileName .= "tmp_$type" . "_$code.tmp";
+
+               $fh = fopen( $tempFileName, 'w' );
+               fwrite( $fh, '"Expression"' . "\n" );
+               foreach( $languageExpressions as $row ) {
+                       $spelling = $csv->formatCSVcolumn( $row->spelling );
+                       fwrite( $fh, $spelling . "\n" );
+               }
+               fclose( $fh );
+
+               if ( file_exists( $fileName ) ) {
+                       unlink( $fileName );
+               }
+               rename( $tempFileName, $fileName );
+       }
+
+       /**
+        * returns an array of "Expression" objects
+        * for a language
+        *
+        * else returns null
+        */
+       function getLanguageIdExpressions( $languageId, $options = array(), $dc 
= null ) {
+               if ( is_null( $dc ) ) {
+                       $dc = wdGetDataSetContext();
+               }
+               $dbr = wfGetDB( DB_SLAVE );
+
+               if ( isset( $options['ORDER BY'] ) ) {
+                       $cond['ORDER BY']= $options['ORDER BY'];
+               } else {
+                       $cond['ORDER BY']= 'spelling';
+               }
+
+               if ( isset( $options['LIMIT'] ) ) {
+                       $cond['LIMIT']= $options['LIMIT'];
+               }
+               if ( isset( $options['OFFSET'] ) ) {
+                       $cond['OFFSET']= $options['OFFSET'];
+               }
+
+               $queryResult = $dbr->select(
+                       "{$dc}_expression",
+                       'spelling',
+                       array(
+                               'language_id' => $languageId,
+                               'remove_transaction_id' => null
+                       ),
+                       __METHOD__,
+                       $cond
+               );
+
+               $expression = array();
+               foreach ( $queryResult as $exp ) {
+                       $expression[] = $exp;
+               }
+
+               if ( $expression ) {
+                       return $expression;
+               }
+               return null;
+       }
+}
diff --git a/includes/jobs/WldJobs.php b/includes/jobs/WldJobs.php
new file mode 100644
index 0000000..01bc729
--- /dev/null
+++ b/includes/jobs/WldJobs.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * WikiLexicalData Job Class
+ *
+ */
+
+class WldJobs {
+
+       public function __construct() {
+       }
+
+       /**
+        * Check if Download Job Exists
+        * Scans job.job_title like 'JobQuery/nameOfDownloadFileWithExtension'
+        *
+        * @return bool
+        */
+       public function downloadJobExist( $jobTitle ) {
+               $dc = wdGetDataSetContext();
+               $dbr = wfGetDB( DB_SLAVE );
+
+               $title = $dbr->selectField(
+                       'job',
+                       'job_title',
+                       array(
+                               'job_title' => $jobTitle
+                       ), __METHOD__
+               );
+
+               if ( $title ) {
+                       return true;
+               }
+               return false;
+       }
+
+}
+
diff --git a/includes/setup/OWSpecials.php b/includes/setup/OWSpecials.php
new file mode 100644
index 0000000..aaa33a9
--- /dev/null
+++ b/includes/setup/OWSpecials.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * A Special Page Setup
+ *
+ * TODO: transfer all special page configuration to this script
+ */
+global $wgWldScriptPath, $wgWldSpecialsScriptPath;
+
+ # Alert the user that this is not a valid access point to MediaWiki if they 
try to access the special pages file directly.
+if ( !defined( 'MEDIAWIKI' ) ) {
+       echo
+       'To install my extension, put the following line in LocalSettings.php:' 
.
+       "\n" .
+       'require_once( "' . $wgWldScriptPath . 'OWSpecials.php" );
+       ';
+       exit( 1 );
+}
+
+$wgExtensionCredits['specialpage'][] = array(
+       'name' => 'SpecialConceptMapping',
+       'author' => 'Kim Bruning',
+);
+
+$wgExtensionCredits['specialpage'][] = array(
+       'name' => 'SpecialCopy',
+       'author' => 'Alan Smithee',
+);
+
+$wgExtensionCredits['specialpage'][] = array(
+       'name' => 'SpecialDatasearch',
+       'author' => 'Kipcool',
+);
+
+$wgExtensionCredits['specialpage'][] = array(
+       'name' => 'SpecialOWStatistics',
+       'author' => 'Kipcool',
+);
+
+$wgExtensionCredits['specialpage'][] = array(
+       'name' => 'SpecialOWDownloads',
+       'author' => 'Hiong3-eng5',
+);
+
+# Location of the SpecialMyExtension class (Tell MediaWiki to load this file)
+$wgAutoloadClasses['SpecialDatasearch'] = $wgWldSpecialsScriptPath . 
'SpecialDatasearch.php';
+$wgAutoloadClasses['SpecialOWStatistics'] = $wgWldSpecialsScriptPath . 
'SpecialOWStatistics.php';
+$wgAutoloadClasses[ 'SpecialOWDownloads' ] = $wgWldSpecialsScriptPath . 
'SpecialOWDownloads.php';
+
+# Tell MediaWiki about the new special page and its class name
+$wgSpecialPages['ow_data_search'] = 'SpecialDatasearch';
+$wgSpecialPages['ow_statistics'] = 'SpecialOWStatistics';
+$wgSpecialPages['ow_downloads'] = 'SpecialOWDownloads';
+
+# Tell MediaWiki about which group the new special page belongs to
+$wgSpecialPageGroups[ 'ow_data_search' ] = 'wiki';
+$wgSpecialPageGroups[ 'ow_statistics' ] = 'wiki';
+$wgSpecialPageGroups[ 'ow_downloads' ] = 'wiki';
+
+# Location of an aliases file (Tell MediaWiki to load this file)
+//$wgExtensionMessagesFiles[ 'OWSpecialsAlias' ] = #dir . 
'../i18n/OWSpecials.alias.php';
diff --git a/OmegaWiki/SpecialDatasearch.php 
b/includes/specials/SpecialDatasearch.php
similarity index 96%
rename from OmegaWiki/SpecialDatasearch.php
rename to includes/specials/SpecialDatasearch.php
index f07385e..0a23714 100644
--- a/OmegaWiki/SpecialDatasearch.php
+++ b/includes/specials/SpecialDatasearch.php
@@ -2,15 +2,16 @@
 
 if ( !defined( 'MEDIAWIKI' ) ) die();
 
-require_once( "Wikidata.php" );
-require_once( "WikiDataGlobals.php" );
-require_once( "WikiDataAPI.php" );
-require_once( "forms.php" );
-require_once( "type.php" );
-require_once( "ViewInformation.php" );
-require_once( "OmegaWikiAttributes.php" );
-require_once( "OmegaWikiRecordSets.php" );
-require_once( "OmegaWikiEditors.php" );
+global $wgWldOwScriptPath;
+require_once( $wgWldOwScriptPath . "Wikidata.php" );
+require_once( $wgWldOwScriptPath . "WikiDataGlobals.php" );
+require_once( $wgWldOwScriptPath . "WikiDataAPI.php" );
+require_once( $wgWldOwScriptPath . "forms.php" );
+require_once( $wgWldOwScriptPath . "type.php" );
+require_once( $wgWldOwScriptPath . "ViewInformation.php" );
+require_once( $wgWldOwScriptPath . "OmegaWikiAttributes.php" );
+require_once( $wgWldOwScriptPath . "OmegaWikiRecordSets.php" );
+require_once( $wgWldOwScriptPath . "OmegaWikiEditors.php" );
 
 class SpecialDatasearch extends SpecialPage {
        protected $externalIdentifierAttribute;
@@ -42,7 +43,7 @@
        private $offset = 0;
 
        function SpecialDatasearch() {
-               parent::__construct( 'DataSearch' );
+               parent::__construct( 'ow_data_search' );
 
                $request = $this->getRequest();
                $this->collectionId = $request->getInt( "collection" ); // 
default is 0
diff --git a/includes/specials/SpecialOWDownloads.php 
b/includes/specials/SpecialOWDownloads.php
new file mode 100644
index 0000000..709cd33
--- /dev/null
+++ b/includes/specials/SpecialOWDownloads.php
@@ -0,0 +1,157 @@
+<?php
+/**
+ * Special download page. Currently regenerated files are formatted
+ * using standard csv with headers and commas as separator and quotation
+ * marks, when appropriate as text delimiter (but actually, I guess the
+ * all non numeric fields are text delimited, to be remedied in future
+ * revisions).
+ *
+ * QUESTION: Is there a way for the job to know that it is processing a
+ * job while in the Special Dowload Page?
+ * If so, is there a way to refresh the page to show the updated file with date
+ * and at the same time not run another job? ~he
+ */
+global $wgWldJobsScriptPath;
+require_once( $wgWldJobsScriptPath . 'OWExpressionListJob.php');
+require_once( $wgWldJobsScriptPath . 'WldJobs.php');
+
+class SpecialOWDownloads extends SpecialPage {
+
+       function __construct() {
+               parent::__construct( 'ow_downloads' );
+       }
+
+       function execute( $par ) {
+               global $wgWldDownloadScriptPath;
+               $request = $this->getRequest();
+               $output = $this->getOutput();
+               $this->setHeaders();
+
+               # Get requests
+               $fileName = $request->getText( 'update' );
+
+               $wikitext = array();
+               $definitions = array();
+               $expressions = array();
+               $translations = array();
+
+               $downloadDir = scandir( $wgWldDownloadScriptPath ) ;
+
+               if ( $fileName ) {
+                       $wldJobs = new WldJobs();
+                       // update Expression
+                       if ( preg_match( '/^exp_/', $fileName ) ) {
+                               preg_match( '/_(.+)\.(.+)/', $fileName, $match 
);
+                               $jobParams = array( 'type' => 'exp', 'langcode' 
=> $match[1], 'format' => $match[2] );
+                               $title = 
Title::newFromText('User:JobQuery/exp_' . $match[1] . '.' . $match[2] );
+                               $job = new CreateExpressionListJob( $title, 
$jobParams );
+                               JobQueueGroup::singleton()->push( $job ); // 
mediawiki >= 1.21
+                       }
+                       // update Definition
+                       if ( preg_match( '/^def_/', $fileName ) ) {
+                               preg_match( '/_(.+)\.(.+)/', $fileName, $match 
);
+                               $jobName = 'JobQuery/' . $fileName;
+                               $jobParams = array( 'type' => 'def', 'langcode' 
=> $match[1], 'format' => $match[2], 'start' => '1' );
+                               $jobExist = $wldJobs->downloadJobExist( 
$jobName );
+                               if ( $jobExist == false ) {
+                                       $title = Title::newFromText( 'User:' . 
$jobName );
+                                       $job = new 
CreateDefinedExpressionListJob( $title, $jobParams );
+                                       JobQueueGroup::singleton()->push( $job 
); // mediawiki >= 1.21
+                               }
+                       }
+               }
+
+               // Segregate by groups
+               foreach( $downloadDir as $files ) {
+                       // definitions
+                       if ( preg_match( '/^def_/', $files ) ) {
+                               $definitions[] = "$files";
+                       }
+                       // definitions
+                       if ( preg_match( '/^exp_/', $files ) ) {
+                               $expressions[] = "$files";
+                       }
+                       // translations
+                       if ( preg_match( '/^trans_/', $files ) ) {
+                               $translations[] = "$files";
+                       }
+               }
+
+               // Process Definitions
+               if ( $definitions ) {
+                       $wikitext[] = '===Definitions===';
+                       $myLine = $this->processText( $definitions );
+                       $wikitext[] = $myLine . "\n|}\n";
+               }
+
+               // Process Expressions
+               if ( $expressions ) {
+                       $wikitext[] = '====List of Expressions====';
+                       $myLine = $this->processText( $expressions );
+                       $wikitext[] = $myLine . "\n|}\n";
+               }
+
+               // Process Translations
+               if ( $translations ) {
+                       $wikitext[] = '===Translations===';
+                       $myLine = $this->processText( $translations );
+                       $wikitext[] = $myLine . "\n|}\n";
+               }
+
+               // output wikitext
+               foreach( $wikitext as $wikilines ) {
+                       $output->addWikiText( $wikilines );
+               }
+       }
+
+       protected function processText( $text ) {
+               global $wgServer, $wgScriptPath, $wgScript, 
$wgWldDownloadScriptPath;
+
+               $presetMyLine = "{| class=\"wikitable\"\n! Language !! Date !! 
Size (bytes) !! Status !! Action \n|-\n";
+               $myLine = $presetMyLine;
+               foreach( $text as $line ) {
+                       if ( preg_match( '/^exp_(.+)\./', $line, $match ) ) {
+                               $language = $match[1];
+                       }
+                       if ( preg_match( '/^def_(.+)\./', $line, $match ) ) {
+                               $language = $match[1];
+                       }
+                       $languageId = getLanguageIdForIso639_3( $language );
+                       // TODO: How to internationalize $nameLanguageId?
+                       $nameLanguageId = WLD_ENGLISH_LANG_ID;
+
+                       $languageName = getLanguageIdLanguageNameFromIds( 
$languageId, $nameLanguageId );
+
+                       $wikiRow = '';
+                       if( $myLine != $presetMyLine ) {
+                               $wikiRow = "|-\n";
+                       }
+                       $myLink = "[$wgServer$wgScriptPath/downloads/$line 
$languageName]";
+                       $myLine .= "$wikiRow| $myLink ";
+                       $filestats = stat( $wgWldDownloadScriptPath . $line );
+
+                       $date = new DateTime();
+                       $date->setTimestamp( $filestats['mtime'] );
+                       $dateTime = $date->format('Y-m-d H:i:s') . "\n";
+
+                       $myLine .= "|| " . $dateTime . " ";
+                       $myLine .= "| align=\"right\" | " . $filestats['size'] 
. " ";
+
+                       $jobName = 'JobQuery/' . $line;
+                       $wldJobs = new WldJobs();
+                       $jobExist = $wldJobs->downloadJobExist( $jobName );
+                       if ( $jobExist == false ) {
+                               $action = 
"[$wgServer$wgScript?title=Special:Ow_downloads&update=$line Regenerate]";
+                               $status = "latest";
+                       } else {
+                               $action = ' ';
+                               $status = "update requested";
+                       }
+                       // ability to update the file
+                       $myLine .= "|| $status || $action";
+                       $myLine .= "\n";
+               }
+               return $myLine;
+       }
+
+}
diff --git a/OmegaWiki/SpecialOWStatistics.php 
b/includes/specials/SpecialOWStatistics.php
similarity index 98%
rename from OmegaWiki/SpecialOWStatistics.php
rename to includes/specials/SpecialOWStatistics.php
index 06419ab..8b0c1d8 100644
--- a/OmegaWiki/SpecialOWStatistics.php
+++ b/includes/specials/SpecialOWStatistics.php
@@ -1,8 +1,9 @@
 <?php
 if ( !defined( 'MEDIAWIKI' ) ) die();
 
-require_once( "Wikidata.php" );
-require_once( 'languages.php' );
+global $wgWldOwScriptPath;
+require_once( $wgWldOwScriptPath . 'Wikidata.php' );
+require_once( $wgWldOwScriptPath . 'languages.php' );
 
 class SpecialOWStatistics extends SpecialPage {
        function __construct() {

-- 
To view, visit https://gerrit.wikimedia.org/r/70325
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If21ee9db67d025891ee851e68a96646124dbe14a
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/WikiLexicalData
Gerrit-Branch: master
Gerrit-Owner: Hiong3-eng5 <[email protected]>
Gerrit-Reviewer: Hiong3-eng5 <[email protected]>
Gerrit-Reviewer: Kipcool <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to