Permalink
Browse files

Adds methods that get page information.

  • Loading branch information...
1 parent e33d65e commit d88251af960835fcd8ada1fdcdf2757785c0a6e4 Jim Safley committed Apr 25, 2011
Showing with 47 additions and 7 deletions.
  1. +47 −5 lib/Scripto/Document.php
  2. +0 −2 lib/Scripto/Service/MediaWiki.php
View
@@ -267,6 +267,32 @@ public function getTalkPagePlainText()
return html_entity_decode(strip_tags($this->_mediawiki->getLatestRevisionHtml('Talk:' . $this->_baseTitle)));
}
+ /**
+ * Get information for the current transcription page'.
+ *
+ * @return array
+ */
+ public function getTranscriptionPageInfo()
+ {
+ if (is_null($this->_pageId)) {
+ throw new Scripto_Exception('The document page must be set before getting the transcription page information.');
+ }
+ return $this->_getPageInfo($this->_baseTitle);
+ }
+
+ /**
+ * Get information for the current talk page.
+ *
+ * @return array
+ */
+ public function getTalkPageInfo()
+ {
+ if (is_null($this->_pageId)) {
+ throw new Scripto_Exception('The document page must be set before getting the transcription page information.');
+ }
+ return $this->_getPageInfo('Talk:' . $this->_baseTitle);
+ }
+
/**
* Get the MediaWiki transcription page revision history for the current page.
*
@@ -515,7 +541,27 @@ public function exportTranscription($type = 'plain_text',
}
/**
- * Get the revisions for the current page.
+ * Get information for the specified page.
+ *
+ * @param string $title
+ * @return array
+ */
+ protected function _getPageInfo($title)
+ {
+ $response = $this->_mediawiki->getInfo($title);
+ $page = current($response['query']['pages']);
+ $pageInfo = array('page_id' => $page['pageid'],
+ 'namespace_index' => $page['ns'],
+ 'mediawiki_title' => $page['title'],
+ 'last_revision_id' => $page['lastrevid'],
+ 'counter' => $page['counter'],
+ 'length' => $page['length'],
+ 'new' => isset($page['new']) ? true: false);
+ return $pageInfo;
+ }
+
+ /**
+ * Get the revisions for the specified page.
*
* @param string $title
* @param int $limit
@@ -524,10 +570,6 @@ public function exportTranscription($type = 'plain_text',
*/
protected function _getPageHistory($title, $limit = 10, $startRevisionId = null)
{
- if (is_null($this->_pageId)) {
- throw new Scripto_Exception('The document page must be set before getting the page history.');
- }
-
$revisions = array();
do {
$response = $this->_mediawiki->getRevisions(
@@ -532,8 +532,6 @@ public function logout()
*/
protected function _request($action, array $params = array())
{
- //echo "<pre>$action:\n";print_r($params);echo '</pre>';
-
// Check if this action is a valid MediaWiki API action.
if (!array_key_exists($action, $this->_actions)) {
throw new Scripto_Service_Exception('Invalid MediaWiki API action.');

0 comments on commit d88251a

Please sign in to comment.