Permalink
Browse files

Separates the canEdit() check into transcription and talk pages.

  • Loading branch information...
1 parent e297b6c commit ea2b4024cf8bfd00f39af8514adaecb824db8ef5 Jim Safley committed Apr 29, 2011
Showing with 64 additions and 43 deletions.
  1. +64 −43 lib/Scripto/Document.php
View
@@ -343,53 +343,29 @@ public function getTalkPageHistory($limit = 10, $startRevisionId = null)
}
/**
- * Determine if the current user can edit the MediaWiki page.
- *
- * It is possible to restrict anonymous editing in MediaWiki.
- * @link http://www.mediawiki.org/wiki/Manual:Preventing_access#Restrict_editing_of_all_pages
- *
- * @return bool
- */
- public function canEdit()
+ * Determine if the current user can edit the MediaWiki transcription page.
+ *
+ * @return bool
+ */
+ public function canEditTranscriptionPage()
{
if (is_null($this->_pageId)) {
- throw new Scripto_Exception('The document page must be set before determining whether the user can edit it.');
- }
-
- $userInfo = $this->_mediawiki->getUserInfo('rights');
-
- // Users without edit rights cannot edit pages.
- if (!in_array('edit', $userInfo['query']['userinfo']['rights'])) {
- return false;
- }
-
- $pageProtections = $this->_transcriptionPageInfo['protections'];
-
- // Users with edit rights can edit unprotected pages.
- if (empty($pageProtections)) {
- return true;
+ throw new Scripto_Exception('The document page must be set before determining whether the user can edit the transcription page.');
}
-
- // Iterate the page protections.
- foreach ($pageProtections as $pageProtection) {
-
- // The page is edit-protected.
- if ('edit' == $pageProtection['type']) {
-
- // Users with edit and protect rights can edit protected pages.
- if (in_array('protect', $userInfo['query']['userinfo']['rights'])) {
- return true;
-
- // Users with edit but without protect rights cannot edit
- // protected pages.
- } else {
- return false;
- }
- }
+ return $this->_canEdit($this->_transcriptionPageInfo['protections']);
+ }
+
+ /**
+ * Determine if the current user can edit the MediaWiki talk page.
+ *
+ * @return bool
+ */
+ public function canEditTalkPage()
+ {
+ if (is_null($this->_pageId)) {
+ throw new Scripto_Exception('The document page must be set before determining whether the user can edit the talk page.');
}
-
- // Users with edit rights can edit pages that are not edit-protected.
- return true;
+ return $this->_canEdit($this->_talkPageInfo['protections']);
}
/**
@@ -569,6 +545,51 @@ public function exportTranscription($type = 'plain_text',
}
/**
+ * Determine if the current user can edit the specified MediaWiki page.
+ *
+ * It is possible to restrict anonymous editing in MediaWiki.
+ * @link http://www.mediawiki.org/wiki/Manual:Preventing_access#Restrict_editing_of_all_pages
+ *
+ * @param array $pageProtections
+ * @return bool
+ */
+ protected function _canEdit(array $pageProtections)
+ {
+ $userInfo = $this->_mediawiki->getUserInfo('rights');
+
+ // Users without edit rights cannot edit pages.
+ if (!in_array('edit', $userInfo['query']['userinfo']['rights'])) {
+ return false;
+ }
+
+ // Users with edit rights can edit unprotected pages.
+ if (empty($pageProtections)) {
+ return true;
+ }
+
+ // Iterate the page protections.
+ foreach ($pageProtections as $pageProtection) {
+
+ // The page is edit-protected.
+ if ('edit' == $pageProtection['type']) {
+
+ // Users with edit and protect rights can edit protected pages.
+ if (in_array('protect', $userInfo['query']['userinfo']['rights'])) {
+ return true;
+
+ // Users with edit but without protect rights cannot edit
+ // protected pages.
+ } else {
+ return false;
+ }
+ }
+ }
+
+ // Users with edit rights can edit pages that are not edit-protected.
+ return true;
+ }
+
+ /**
* Get information for the specified page.
*
* @param string $title

0 comments on commit ea2b402

Please sign in to comment.