summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Specials/Admin/PropertyStatsRebuildJobTaskHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Specials/Admin/PropertyStatsRebuildJobTaskHandler.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Specials/Admin/PropertyStatsRebuildJobTaskHandler.php162
1 files changed, 162 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Specials/Admin/PropertyStatsRebuildJobTaskHandler.php b/www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Specials/Admin/PropertyStatsRebuildJobTaskHandler.php
new file mode 100644
index 00000000..c0b94382
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Specials/Admin/PropertyStatsRebuildJobTaskHandler.php
@@ -0,0 +1,162 @@
+<?php
+
+namespace SMW\MediaWiki\Specials\Admin;
+
+use Html;
+use SMW\ApplicationFactory;
+use SMW\DIWikiPage;
+use SMW\MediaWiki\Renderer\HtmlFormRenderer;
+use SMW\Message;
+use Title;
+use WebRequest;
+
+/**
+ * @license GNU GPL v2+
+ * @since 2.5
+ *
+ * @author mwjames
+ */
+class PropertyStatsRebuildJobTaskHandler extends TaskHandler {
+
+ /**
+ * @var HtmlFormRenderer
+ */
+ private $htmlFormRenderer;
+
+ /**
+ * @var OutputFormatter
+ */
+ private $outputFormatter;
+
+ /**
+ * @var boolean
+ */
+ public $isApiTask = true;
+
+ /**
+ * @since 2.5
+ *
+ * @param HtmlFormRenderer $htmlFormRenderer
+ * @param OutputFormatter $outputFormatter
+ */
+ public function __construct( HtmlFormRenderer $htmlFormRenderer, OutputFormatter $outputFormatter ) {
+ $this->htmlFormRenderer = $htmlFormRenderer;
+ $this->outputFormatter = $outputFormatter;
+ }
+
+ /**
+ * @since 3.0
+ *
+ * {@inheritDoc}
+ */
+ public function getSection() {
+ return self::SECTION_DATAREPAIR;
+ }
+
+ /**
+ * @since 3.0
+ *
+ * {@inheritDoc}
+ */
+ public function hasAction() {
+ return true;
+ }
+
+ /**
+ * @since 3.0
+ *
+ * {@inheritDoc}
+ */
+ public function isApiTask() {
+ return $this->isApiTask;
+ }
+
+ /**
+ * @since 2.5
+ *
+ * {@inheritDoc}
+ */
+ public function isTaskFor( $task ) {
+ return $task === 'pstatsrebuild';
+ }
+
+ /**
+ * @since 2.5
+ *
+ * {@inheritDoc}
+ */
+ public function getHtml() {
+
+ $subject = DIWikiPage::newFromTitle( \SpecialPage::getTitleFor( 'SMWAdmin' ) );
+
+ // smw-admin-propertystatistics
+ $this->htmlFormRenderer
+ ->addHeader( 'h4', $this->msg( 'smw-admin-propertystatistics-title' ) )
+ ->addParagraph( $this->msg( 'smw-admin-propertystatistics-intro', Message::PARSE ), [ 'class' => 'plainlinks' ] );
+
+ if ( $this->isEnabledFeature( SMW_ADM_PSTATS ) && !$this->hasPendingJob() ) {
+ $this->htmlFormRenderer
+ ->setMethod( 'post' )
+ ->addHiddenField( 'action', 'pstatsrebuild' )
+ ->addSubmitButton(
+ $this->msg( 'smw-admin-propertystatistics-button' ),
+ [
+ 'class' => $this->isApiTask() ? 'smw-admin-api-job-task' : '',
+ 'data-job' => 'SMW\PropertyStatisticsRebuildJob',
+ 'data-subject' => $subject->getHash()
+ ]
+ );
+ } elseif ( $this->isEnabledFeature( SMW_ADM_PSTATS ) ) {
+ $this->htmlFormRenderer->addParagraph(
+ Html::element(
+ 'span',
+ [
+ 'class' => 'smw-admin-circle-orange'
+ ]
+ ) . Html::element(
+ 'span',
+ [
+ 'style' => 'font-style:italic; margin-left:25px;'
+ ],
+ $this->msg( 'smw-admin-propertystatistics-active' )
+ )
+ );
+ } else {
+ $this->htmlFormRenderer->addParagraph(
+ $this->msg( 'smw-admin-feature-disabled' )
+ );
+ }
+
+ return Html::rawElement(
+ 'div',
+ [],
+ $this->htmlFormRenderer->getForm()
+ );
+ }
+
+ /**
+ * @since 2.5
+ *
+ * {@inheritDoc}
+ */
+ public function handleRequest( WebRequest $webRequest ) {
+
+ if ( !$this->isEnabledFeature( SMW_ADM_PSTATS ) || $this->hasPendingJob() || $this->isApiTask() ) {
+ return $this->outputFormatter->redirectToRootPage( '', [ 'tab' => 'rebuild' ] );
+ }
+
+ $job = ApplicationFactory::getInstance()->newJobFactory()->newByType(
+ 'smw.propertyStatisticsRebuild',
+ \SpecialPage::getTitleFor( 'SMWAdmin' )
+ );
+
+ $job->insert();
+
+ $this->outputFormatter->redirectToRootPage( '', [ 'tab' => 'rebuild' ] );
+ }
+
+ private function hasPendingJob() {
+ return ApplicationFactory::getInstance()->getJobQueue()->hasPendingJob( 'smw.propertyStatisticsRebuild' );
+ }
+
+}