Example #1
0
<?php

require '../shared/config.php';
// Must set the Content-Type header to correctly display UTF-8.
header('Content-Type: text/html; charset=utf-8');
// Get the document ID and page ID.
$documentId = isset($_GET['documentId']) ? $_GET['documentId'] : 16344;
$pageId = isset($_GET['pageId']) ? $_GET['pageId'] : null;
// Set the Adapter object.
require_once 'Scripto/Adapter/Example.php';
$adapter = new Scripto_Adapter_Example();
// Set the Document object.
require_once 'Scripto.php';
$scripto = new Scripto($adapter, array('api_url' => MEDIAWIKI_API_URL, 'db_name' => MEDIAWIKI_DB_NAME));
$doc = $scripto->getDocument($documentId);
// Must set the current page first.
$doc->setPage($pageId);
//var_dump($doc->getBaseTitle());
//var_dump($doc->decodeBaseTitle($doc->getBaseTitle()));
if (isset($_POST['submit_login'])) {
    $scripto->login($_POST['username'], $_POST['password']);
}
if (isset($_POST['submit_logout'])) {
    $scripto->logout();
}
// Determine if the current user can edit MediaWiki.
$canEdit = $doc->canEdit();
if ($canEdit) {
    // Edit the transcription if submitted.
    if (isset($_POST['submit_transcription'])) {
        $doc->editTranscriptionPage($_POST['transcription']);
 /**
  * Import an entire document's transcription into Omeka.
  *
  * @param int|string $documentId The document ID
  * @param string $text The text to import
  * @return bool True: success; false: fail
  */
 public function importDocumentTranscription($documentId, $text)
 {
     if (!$this->documentExists($documentId)) {
         return false;
     }
     $item = $this->_item;
     $element = $item->getElement('Scripto', 'Transcription');
     $item->deleteElementTextsByElementId(array($element->id));
     $isHtml = false;
     if ('html' == get_option('scripto_import_type')) {
         $isHtml = true;
     }
     $text = Scripto::removeNewPPLimitReports($text);
     $item->addTextForElement($element, $text, $isHtml);
     $item->save();
 }
Example #3
0
 /**
  * View transcription interface.
  */
 public function transcribeAction()
 {
     try {
         $scripto = ScriptoPlugin::getScripto();
         $doc = $scripto->getDocument($this->_getParam('item-id'));
         $doc->setPage($this->_getParam('file-id'));
         // Set the File object.
         $file = $this->_helper->db->getTable('File')->find($doc->getPageId());
         // Set the page HTML.
         $transcriptionPageHtml = Scripto::removeHtmlAttributes($doc->getTranscriptionPageHtml());
         $talkPageHtml = Scripto::removeHtmlAttributes($doc->getTalkPageHtml());
         // Set all the document's pages.
         $pages = $doc->getPages();
         // Set the pagination.
         $paginationUrls = array();
         foreach ($pages as $pageId => $pageName) {
             // Custom pagination (page x of y).
             $number_of_pages = count($pages);
             $current_page_id = $doc->getPageId();
             $paginationUrls['current_page_number'] = array_search($current_page_id, array_keys($pages)) + 1;
             $paginationUrls['number_of_pages'] = count($pages);
             if (isset($current)) {
                 $paginationUrls['next'] = $this->view->url(array('action' => 'transcribe', 'item-id' => $doc->getId(), 'file-id' => $pageId), 'scripto_action_item_file');
                 break;
             }
             if ($pageId == $doc->getPageId()) {
                 $current = true;
             } else {
                 $paginationUrls['previous'] = $this->view->url(array('action' => 'transcribe', 'item-id' => $doc->getId(), 'file-id' => $pageId), 'scripto_action_item_file');
             }
         }
     } catch (Scripto_Exception $e) {
         $this->_helper->flashMessenger($e->getMessage());
         $this->_helper->redirector->goto('index');
     }
     // Get the embed HTML for the Zoom.it image viewer.
     if ('zoomit' == get_option('scripto_image_viewer')) {
         $client = new Zend_Http_Client('http://api.zoom.it/v1/content');
         $client->setParameterGet('url', $file->getWebPath(get_option('scripto_file_source')));
         $response = json_decode($client->request()->getBody(), true);
         $this->view->zoomIt = $response;
     }
     $this->view->file = $file;
     $this->view->transcriptionPageHtml = $transcriptionPageHtml;
     $this->view->talkPageHtml = $talkPageHtml;
     $this->view->paginationUrls = $paginationUrls;
     $this->view->scripto = $scripto;
     $this->view->doc = $doc;
 }
Example #4
0
 /**
  * Get the revisions for the specified page.
  *
  * @uses Scripto_Service_MediaWiki::getRevisions()
  * @param string $title
  * @param int $limit
  * @param int $startRevisionId
  * @return array
  */
 protected function _getPageHistory($title, $limit = 10, $startRevisionId = null)
 {
     $revisions = array();
     do {
         $response = $this->_mediawiki->getRevisions($title, array('rvstartid' => $startRevisionId, 'rvlimit' => 100, 'rvprop' => 'ids|flags|timestamp|user|comment|size'));
         $page = current($response['query']['pages']);
         // Return if the page has not been created.
         if (array_key_exists('missing', $page)) {
             return $revisions;
         }
         foreach ($page['revisions'] as $revision) {
             $action = Scripto::getChangeAction(array('comment' => $revision['comment']));
             // Build the revisions.
             $revisions[] = array('revision_id' => $revision['revid'], 'parent_id' => $revision['parentid'], 'user' => $revision['user'], 'timestamp' => $revision['timestamp'], 'comment' => $revision['comment'], 'size' => $revision['size'], 'action' => $action);
             // Break out of the loops if limit has been reached.
             if ($limit == count($revisions)) {
                 break 2;
             }
         }
         // Set the query continue, if any.
         if (isset($response['query-continue'])) {
             $startRevisionId = $response['query-continue']['revisions']['rvstartid'];
         } else {
             $startRevisionId = null;
         }
     } while ($startRevisionId);
     return $revisions;
 }
Example #5
0
<?php

require 'config.php';
// Get the document ID and page ID.
$documentId = isset($_GET['documentId']) ? $_GET['documentId'] : null;
$pageId = isset($_GET['pageId']) ? $_GET['pageId'] : null;
$type = $_GET['type'] == 'talk' ? 'talk' : 'transcription';
// Set the Adapter object.
require_once 'Scripto/Adapter/Example.php';
$adapter = new Scripto_Adapter_Example();
// Set the Document object.
require_once 'Scripto.php';
$scripto = new Scripto($adapter, array('api_url' => MEDIAWIKI_API_URL, 'db_name' => MEDIAWIKI_DB_NAME));
$doc = $scripto->getDocument($documentId);
// Must set the current page first.
$doc->setPage($pageId);
// Get updated transcription
switch ($type) {
    case 'transcription':
        echo $doc->getTranscriptionPageHtml();
        break;
    case 'talk':
        echo $doc->getTalkPageHtml();
        break;
    default:
        echo '';
        break;
}
 /**
  * Handle a submitted config form.
  */
 public function hookConfig($args)
 {
     $post = $args['post'];
     // Validate the MediaWiki API URL.
     if (!Scripto::isValidApiUrl(trim($post['scripto_mediawiki_api_url']))) {
         throw new Omeka_Plugin_Installer_Exception('Invalid MediaWiki API URL');
     }
     // Validate the source element.
     $element = get_record_by_id('Element', (int) $post['scripto_source_element']);
     // Set options that are specific to Scripto.
     set_option('scripto_mediawiki_api_url', trim($post['scripto_mediawiki_api_url']));
     set_option('scripto_source_element', $element->set_name . ':' . $element->name);
     set_option('scripto_image_viewer', $post['scripto_image_viewer']);
     set_option('scripto_viewer_class', trim($post['scripto_viewer_class']));
     set_option('scripto_use_google_docs_viewer', $post['scripto_use_google_docs_viewer']);
     set_option('scripto_iframe_class', trim($post['scripto_iframe_class']));
     set_option('scripto_file_source', trim($post['scripto_file_source']));
     set_option('scripto_files_order', trim($post['scripto_files_order']));
     set_option('scripto_import_type', $post['scripto_import_type']);
     set_option('scripto_home_page_text', trim($post['scripto_home_page_text']));
     set_option('scripto_file_source_path', $this->_getFilePath(get_option('scripto_file_source_path')));
 }
Example #7
0
 /**
  * Handle a submitted config form.
  */
 public function hookConfig()
 {
     // Validate the MediaWiki API URL.
     if (!Scripto::isValidApiUrl($_POST['scripto_mediawiki_api_url'])) {
         throw new Omeka_Plugin_Installer_Exception('Invalid MediaWiki API URL');
     }
     // Set options that are specific to Scripto.
     set_option('scripto_mediawiki_api_url', $_POST['scripto_mediawiki_api_url']);
     set_option('scripto_image_viewer', $_POST['scripto_image_viewer']);
     set_option('scripto_use_google_docs_viewer', $_POST['scripto_use_google_docs_viewer']);
     set_option('scripto_import_type', $_POST['scripto_import_type']);
     set_option('scripto_home_page_text', $_POST['scripto_home_page_text']);
 }