Index: tags/extensions/ApprovedRevs/REL_0_1/ApprovedRevs_body.php |
— | — | @@ -0,0 +1,132 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Main class for the Approved Revs extension. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * |
| 9 | + * @author Yaron Koren |
| 10 | + */ |
| 11 | + |
| 12 | +class ApprovedRevs { |
| 13 | + /** |
| 14 | + * Gets the approved revision ID for this page, or null if there isn't |
| 15 | + * one. |
| 16 | + */ |
| 17 | + public static function getApprovedRevID( $title ) { |
| 18 | + $dbr = wfGetDB( DB_SLAVE ); |
| 19 | + $page_id = $title->getArticleId(); |
| 20 | + $rev_id = $dbr->selectField( 'approved_revs', 'rev_id', array( 'page_id' => $page_id ) ); |
| 21 | + return $rev_id; |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Returns whether or not this page has a revision ID. |
| 26 | + */ |
| 27 | + public static function hasApprovedRevision( $title ) { |
| 28 | + $revision_id = self::getApprovedRevID( $title ); |
| 29 | + return ( ! empty( $revision_id ) ); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Returns the content of the approved revision of this page, or null |
| 34 | + * if there isn't one. |
| 35 | + */ |
| 36 | + public static function getApprovedContent( $title ) { |
| 37 | + $revision_id = ApprovedRevs::getApprovedRevID( $title ); |
| 38 | + if ( empty( $revision_id ) ) { |
| 39 | + return null; |
| 40 | + } |
| 41 | + $article = new Article( $title, $revision_id ); |
| 42 | + return( $article->getContent() ); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Returns whether this page is in a namespace that the Approved Revs |
| 47 | + * extension doesn't support. |
| 48 | + */ |
| 49 | + public static function hasUnsupportedNamespace( $title ) { |
| 50 | + global $egApprovedRevsUnsupportedNamespaces; |
| 51 | + $unsupported_namespaces = $egApprovedRevsUnsupportedNamespaces; |
| 52 | + $unsupported_namespaces[] = NS_FILE; |
| 53 | + $unsupported_namespaces[] = NS_CATEGORY; |
| 54 | + return( in_array( $title->getNamespace(), $unsupported_namespaces ) ); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Sets a certain revision as the approved one for this page in the |
| 59 | + * approved_revs DB table; calls a "links update" on this revision |
| 60 | + * so that category information can be stored correctly, as well as |
| 61 | + * info for extensions such as Semantic MediaWiki; and logs the action. |
| 62 | + */ |
| 63 | + public static function setApprovedRevID( $title, $rev_id ) { |
| 64 | + $dbr = wfGetDB( DB_MASTER ); |
| 65 | + $page_id = $title->getArticleId(); |
| 66 | + $old_rev_id = $dbr->selectField( 'approved_revs', 'rev_id', array( 'page_id' => $page_id ) ); |
| 67 | + if ( $old_rev_id ) { |
| 68 | + $dbr->update( 'approved_revs', array( 'rev_id' => $rev_id ), array( 'page_id' => $page_id ) ); |
| 69 | + } else { |
| 70 | + $dbr->insert( 'approved_revs', array( 'page_id' => $page_id, 'rev_id' => $rev_id ) ); |
| 71 | + } |
| 72 | + |
| 73 | + $parser = new Parser(); |
| 74 | + $parser->setTitle( $title ); |
| 75 | + $article = new Article( $title, $rev_id ); |
| 76 | + $text = $article->getContent(); |
| 77 | + $options = new ParserOptions(); |
| 78 | + $parser->parse( $text, $title, $options, true, true, $rev_id ); |
| 79 | + $u = new LinksUpdate( $title, $parser->getOutput() ); |
| 80 | + $u->doUpdate(); |
| 81 | + |
| 82 | + $log = new LogPage( 'approval' ); |
| 83 | + $rev_url = $title->getFullURL( array( 'old_id' => $rev_id ) ); |
| 84 | + $rev_link = Xml::element( |
| 85 | + 'a', |
| 86 | + array( 'href' => $rev_url ), |
| 87 | + $rev_id |
| 88 | + ); |
| 89 | + $logParams = array( $rev_link ); |
| 90 | + $log->addEntry( |
| 91 | + 'approve', |
| 92 | + $title, |
| 93 | + '', |
| 94 | + $logParams |
| 95 | + ); |
| 96 | + |
| 97 | + wfRunHooks( 'ApprovedRevsRevisionApproved', array( $parser, $title, $rev_id ) ); |
| 98 | + } |
| 99 | + |
| 100 | + public static function deleteRevisionApproval( $title ) { |
| 101 | + $dbr = wfGetDB( DB_MASTER ); |
| 102 | + $page_id = $title->getArticleId(); |
| 103 | + $dbr->delete( 'approved_revs', array( 'page_id' => $page_id ) ); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Unsets the approved revision for this page in the approved_revs DB |
| 108 | + * table; calls a "links update" on this page so that category |
| 109 | + * information can be stored correctly, as well as info for |
| 110 | + * extensions such as Semantic MediaWiki; and logs the action. |
| 111 | + */ |
| 112 | + public static function unsetApproval( $title ) { |
| 113 | + self::deleteRevisionApproval( $title ); |
| 114 | + |
| 115 | + $parser = new Parser(); |
| 116 | + $parser->setTitle( $title ); |
| 117 | + $article = new Article( $title ); |
| 118 | + $text = $article->getContent(); |
| 119 | + $options = new ParserOptions(); |
| 120 | + $parser->parse( $text, $title, $options ); |
| 121 | + $u = new LinksUpdate( $title, $parser->getOutput() ); |
| 122 | + $u->doUpdate(); |
| 123 | + |
| 124 | + $log = new LogPage( 'approval' ); |
| 125 | + $log->addEntry( |
| 126 | + 'unapprove', |
| 127 | + $title, |
| 128 | + '' |
| 129 | + ); |
| 130 | + |
| 131 | + wfRunHooks( 'ApprovedRevsRevisionUnapproved', array( $parser, $title ) ); |
| 132 | + } |
| 133 | +} |
Property changes on: tags/extensions/ApprovedRevs/REL_0_1/ApprovedRevs_body.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 134 | + native |
Index: tags/extensions/ApprovedRevs/REL_0_1/ApprovedRevs.i18n.php |
— | — | @@ -0,0 +1,67 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalization file for the Approved Revs extension. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | +*/ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +/** English |
| 13 | + * @author Yaron Koren |
| 14 | + */ |
| 15 | +$messages['en'] = array( |
| 16 | + // user messages |
| 17 | + 'approvedrevs-desc' => 'Set a single revision of a page as approved', |
| 18 | + 'approvedrevs-logname' => 'Revision approval log', |
| 19 | + 'approvedrevs-logdesc' => 'This is the log of revisions that have been approved.', |
| 20 | + 'approvedrevs-approve' => 'approve', |
| 21 | + 'approvedrevs-unapprove' => 'unapprove', |
| 22 | + 'approvedrevs-approvesuccess' => 'This revision of the page has been set as the approved version.', |
| 23 | + 'approvedrevs-unapprovesuccess' => 'There is no longer an approved version for this page. |
| 24 | +Instead, the most recent revision will be shown.', |
| 25 | + 'approvedrevs-approveaction' => 'set $2 as the approved revision for "[[$1]]"', |
| 26 | + 'approvedrevs-unapproveaction' => 'unset approved revision for "[[$1]]"', |
| 27 | + 'approvedrevs-notlatest' => 'This is the approved revision of this page; it is not the most recent.', |
| 28 | + 'approvedrevs-approvedandlatest' => 'This is the approved revision of this page, as well as being the most recent.', |
| 29 | + 'approvedrevs-viewlatest' => 'View most recent revision.', |
| 30 | + 'approvedpages' => 'Approved pages', |
| 31 | + 'approvedrevs-approvedpages-docu' => 'The following are the pages in the wiki that have an approved revision.', |
| 32 | + 'right-approverevisions' => 'Set a certain revision of a wiki page as approved', |
| 33 | + 'right-viewlinktolatest' => 'View explanatory text at the top of pages that have an approved revision', |
| 34 | +); |
| 35 | + |
| 36 | +/** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
| 37 | + * @author Wizardist |
| 38 | + */ |
| 39 | +$messages['be-tarask'] = array( |
| 40 | + 'approvedrevs-logdesc' => 'Тут месьціцца журнал прынятых рэвізіяў.', |
| 41 | + 'approvedrevs-approve' => 'зацьвердзіць', |
| 42 | + 'approvedrevs-unapprove' => 'адхіліць', |
| 43 | +); |
| 44 | + |
| 45 | +/** Dutch (Nederlands) |
| 46 | + * @author Siebrand |
| 47 | + */ |
| 48 | +$messages['nl'] = array( |
| 49 | + 'approvedrevs-desc' => 'Een versie van een pagina als goedgekeurd instellen', |
| 50 | + 'approvedrevs-logname' => 'Logboek versiegoedkeuring', |
| 51 | + 'approvedrevs-logdesc' => 'Dit is het logboek met de versies die zijn goedgekeurd.', |
| 52 | + 'approvedrevs-approve' => 'goedkeuren', |
| 53 | + 'approvedrevs-unapprove' => 'afkeuren', |
| 54 | + 'approvedrevs-approvesuccess' => 'Deze versie van de pagina is ingesteld als de goedgekeurde versie.', |
| 55 | + 'approvedrevs-unapprovesuccess' => 'Deze pagina heeft niet langer een goedgekeurde versie. |
| 56 | +Daarom wordt de laatste versie weergegeven.', |
| 57 | + 'approvedrevs-approveaction' => 'heeft $2 ingesteld als de goedgekeurde versie voor "[[$1]]"', |
| 58 | + 'approvedrevs-unapproveaction' => 'heeft de goedgekeurde versie verwijderd voor "[[$1]]"', |
| 59 | + 'approvedrevs-notlatest' => 'Dit is de goedgekeurde versie van deze pagina. |
| 60 | +Het is niet de meeste recente versie.', |
| 61 | + 'approvedrevs-approvedandlatest' => 'Dit is de goedgekeurde versie van deze pagina. Er is geen nieuwere versie.', |
| 62 | + 'approvedrevs-viewlatest' => 'Laatste versie bekijken', |
| 63 | + 'approvedpages' => "Goedgekeurde pagina's", |
| 64 | + 'approvedrevs-approvedpages-docu' => "De volgende pagina's in de wiki hebben een goedgekeurde versie.", |
| 65 | + 'right-approverevisions' => 'Een versie van een wikipagina markeren als goedgekeurd.', |
| 66 | + 'right-viewlinktolatest' => "De verklarende tekst bovenaan pagina's zien die die een goedgekeurde versie hebben", |
| 67 | +); |
| 68 | + |
Property changes on: tags/extensions/ApprovedRevs/REL_0_1/ApprovedRevs.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 69 | + native |
Index: tags/extensions/ApprovedRevs/REL_0_1/ApprovedRevs.php |
— | — | @@ -0,0 +1,64 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 5 | + |
| 6 | +/** |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
| 9 | + * |
| 10 | + * @author Yaron Koren |
| 11 | + */ |
| 12 | + |
| 13 | +define( 'APPROVED_REVS_VERSION', '0.1' ); |
| 14 | + |
| 15 | +// credits |
| 16 | +$wgExtensionCredits['other'][] = array( |
| 17 | + 'path' => __FILE__, |
| 18 | + 'name' => 'Approved Revs', |
| 19 | + 'version' => APPROVED_REVS_VERSION, |
| 20 | + 'author' => 'Yaron Koren', |
| 21 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:Approved_Revs', |
| 22 | + 'descriptionmsg' => 'approvedrevs-desc' |
| 23 | +); |
| 24 | + |
| 25 | +// global variables |
| 26 | +$egApprovedRevsIP = dirname( __FILE__ ) . '/'; |
| 27 | +$egApprovedRevsExcludedNamespaces = array(); |
| 28 | + |
| 29 | +// internationalization |
| 30 | +$wgExtensionMessagesFiles['ApprovedRevs'] = $egApprovedRevsIP . 'ApprovedRevs.i18n.php'; |
| 31 | +$wgExtensionAliasesFiles['ApprovedRevs'] = $egApprovedRevsIP . 'ApprovedRevs.alias.php'; |
| 32 | + |
| 33 | +// register all classes |
| 34 | +$wgAutoloadClasses['ApprovedRevs'] = $egApprovedRevsIP . 'ApprovedRevs_body.php'; |
| 35 | +$wgAutoloadClasses['ApprovedRevsHooks'] = $egApprovedRevsIP . 'ApprovedRevs.hooks.php'; |
| 36 | +$wgSpecialPages['ApprovedPages'] = 'ARApprovedPages'; |
| 37 | +$wgAutoloadClasses['ARApprovedPages'] = $egApprovedRevsIP . 'AR_ApprovedPages.php'; |
| 38 | +$wgSpecialPageGroups['ApprovedPages'] = 'pages'; |
| 39 | + |
| 40 | +// hooks |
| 41 | +$wgHooks['ParserBeforeInternalParse'][] = 'ApprovedRevsHooks::setApprovedRevForParsing'; |
| 42 | +$wgHooks['ArticleFromTitle'][] = 'ApprovedRevsHooks::showApprovedRevision'; |
| 43 | +$wgHooks['DisplayOldSubtitle'][] = 'ApprovedRevsHooks::setSubtitle'; |
| 44 | +$wgHooks['SkinTemplateNavigation'][] = 'ApprovedRevsHooks::changeEditLink'; |
| 45 | +$wgHooks['PageHistoryBeforeList'][] = 'ApprovedRevsHooks::storeApprovedRevisionForHistoryPage'; |
| 46 | +$wgHooks['PageHistoryLineEnding'][] = 'ApprovedRevsHooks::addApprovalLink'; |
| 47 | +$wgHooks['UnknownAction'][] = 'ApprovedRevsHooks::setAsApproved'; |
| 48 | +$wgHooks['UnknownAction'][] = 'ApprovedRevsHooks::unsetAsApproved'; |
| 49 | +$wgHooks['BeforeParserFetchTemplateAndtitle'][] = 'ApprovedRevsHooks::setTranscludedPageRev'; |
| 50 | +$wgHooks['ArticleDeleteComplete'][] = 'ApprovedRevsHooks::deleteRevisionApproval'; |
| 51 | +$wgHooks['AdminLinks'][] = 'ApprovedRevsHooks::addToAdminLinks'; |
| 52 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'ApprovedRevsHooks::describeDBSchema'; |
| 53 | + |
| 54 | +// logging |
| 55 | +$wgLogTypes['approval'] = 'approval'; |
| 56 | +$wgLogNames['approval'] = 'approvedrevs-logname'; |
| 57 | +$wgLogHeaders['approval'] = 'approvedrevs-logdesc'; |
| 58 | +$wgLogActions['approval/approve'] = 'approvedrevs-approveaction'; |
| 59 | +$wgLogActions['approval/unapprove'] = 'approvedrevs-unapproveaction'; |
| 60 | + |
| 61 | +// user rights |
| 62 | +$wgAvailableRights[] = 'approverevisions'; |
| 63 | +$wgGroupPermissions['sysop']['approverevisions'] = true; |
| 64 | +$wgAvailableRights[] = 'viewlinktolatest'; |
| 65 | +$wgGroupPermissions['*']['viewlinktolatest'] = true; |
Property changes on: tags/extensions/ApprovedRevs/REL_0_1/ApprovedRevs.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 66 | + native |
Index: tags/extensions/ApprovedRevs/REL_0_1/AR_ApprovedPages.php |
— | — | @@ -0,0 +1,66 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Special page that lists all pages that have an approved revision. |
| 5 | + * |
| 6 | + * @author Yaron Koren |
| 7 | + */ |
| 8 | + |
| 9 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 10 | + |
| 11 | +class ARApprovedPages extends SpecialPage { |
| 12 | + |
| 13 | + /** |
| 14 | + * Constructor |
| 15 | + */ |
| 16 | + function ARApprovedPages() { |
| 17 | + SpecialPage::SpecialPage( 'ApprovedPages' ); |
| 18 | + wfLoadExtensionMessages( 'ApprovedRevs' ); |
| 19 | + } |
| 20 | + |
| 21 | + function execute( $query ) { |
| 22 | + $this->setHeaders(); |
| 23 | + list( $limit, $offset ) = wfCheckLimits(); |
| 24 | + $rep = new ARApprovedPagesPage(); |
| 25 | + return $rep->doQuery( $offset, $limit ); |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +class ARApprovedPagesPage extends QueryPage { |
| 30 | + function getName() { |
| 31 | + return "ApprovedPages"; |
| 32 | + } |
| 33 | + |
| 34 | + function isExpensive() { return false; } |
| 35 | + |
| 36 | + function isSyndicated() { return false; } |
| 37 | + |
| 38 | + function getPageHeader() { |
| 39 | + $header = Xml::element( 'p', null, wfMsg( 'approvedrevs-approvedpages-docu' ) ) . "<br />\n"; |
| 40 | + return $header; |
| 41 | + } |
| 42 | + |
| 43 | + function getPageFooter() { |
| 44 | + } |
| 45 | + |
| 46 | + function getSQL() { |
| 47 | + $dbr = wfGetDB( DB_SLAVE ); |
| 48 | + $approved_revs = $dbr->tableName( 'approved_revs' ); |
| 49 | + $page = $dbr->tableName( 'page' ); |
| 50 | + // QueryPage uses the value from this SQL in an ORDER clause, |
| 51 | + // so return page_title as title. |
| 52 | + return "SELECT 'Page' AS type, |
| 53 | + p.page_title AS title, |
| 54 | + p.page_id AS value |
| 55 | + FROM $approved_revs ar JOIN $page p |
| 56 | + ON ar.page_id = p.page_id"; |
| 57 | + } |
| 58 | + |
| 59 | + function sortDescending() { |
| 60 | + return false; |
| 61 | + } |
| 62 | + |
| 63 | + function formatResult( $skin, $result ) { |
| 64 | + $title = Title::newFromId( $result->value ); |
| 65 | + return $skin->makeLinkObj( $title ); |
| 66 | + } |
| 67 | +} |
Property changes on: tags/extensions/ApprovedRevs/REL_0_1/AR_ApprovedPages.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 68 | + native |
Index: tags/extensions/ApprovedRevs/REL_0_1/ApprovedRevs.hooks.php |
— | — | @@ -0,0 +1,295 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +if ( ! defined( 'MEDIAWIKI' ) ) die(); |
| 5 | + |
| 6 | +/** |
| 7 | + * Functions for the Approved Revs extension called by hooks in the MediaWiki |
| 8 | + * code. |
| 9 | + * |
| 10 | + * @file |
| 11 | + * @ingroup Extensions |
| 12 | + * |
| 13 | + * @author Yaron Koren |
| 14 | + */ |
| 15 | + |
| 16 | +class ApprovedRevsHooks { |
| 17 | + |
| 18 | + static public function setApprovedRevForParsing( &$parser, &$text, &$stripState ) { |
| 19 | + global $wgRequest; |
| 20 | + $action = $wgRequest->getVal( 'action' ); |
| 21 | + if ( $action == 'submit' ) { |
| 22 | + $title = $parser->getTitle(); |
| 23 | + $approvedText = ApprovedRevs::getApprovedContent( $title ); |
| 24 | + if ( ! is_null( $approvedText ) ) { |
| 25 | + $text = $approvedText; |
| 26 | + } |
| 27 | + } |
| 28 | + return true; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Return the approved revision of the page, if there is one, and if |
| 33 | + * the page is simply being viewed, and if no specific revision has |
| 34 | + * been requested. |
| 35 | + */ |
| 36 | + static function showApprovedRevision( &$title, &$article ) { |
| 37 | + // if a revision ID is set, exit |
| 38 | + if ( $title->mArticleID > -1 ) { |
| 39 | + return true; |
| 40 | + } |
| 41 | + // if it's any action other than viewing, exit |
| 42 | + global $wgRequest; |
| 43 | + if ( $wgRequest->getCheck( 'action' ) && |
| 44 | + $wgRequest->getVal( 'action' ) != 'view' && |
| 45 | + $wgRequest->getVal( 'action' ) != 'purge' && |
| 46 | + $wgRequest->getVal( 'action' ) != 'render' ) { |
| 47 | + return true; |
| 48 | + } |
| 49 | + |
| 50 | + $revisionID = ApprovedRevs::getApprovedRevID( $title ); |
| 51 | + if ( ! empty( $revisionID ) ) { |
| 52 | + $article = new Article( $title, $revisionID ); |
| 53 | + } |
| 54 | + return true; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * If user is viewing the page via its main URL, and what they're |
| 59 | + * seeing is the approved revision of the page, remove the standard |
| 60 | + * subtitle shown for all non-latest revisions, and replace it with |
| 61 | + * either nothing or a message explaining the situation, depending |
| 62 | + * on the user's rights |
| 63 | + */ |
| 64 | + static function setSubtitle( &$article, &$revisionID ) { |
| 65 | + if ( ! ApprovedRevs::hasApprovedRevision( $article->getTitle() ) ) { |
| 66 | + return true; |
| 67 | + } |
| 68 | + |
| 69 | + global $wgRequest; |
| 70 | + if ( $wgRequest->getCheck( 'oldid' ) ) { |
| 71 | + return true; |
| 72 | + } |
| 73 | + |
| 74 | + if ( ! $article->getTitle()->userCan( 'viewlinktolatest' ) ) { |
| 75 | + return false; |
| 76 | + } |
| 77 | + |
| 78 | + wfLoadExtensionMessages( 'ApprovedRevs' ); |
| 79 | + if ( $revisionID == $article->getLatest() ) { |
| 80 | + $text = wfMsg( 'approvedrevs-approvedandlatest' ); |
| 81 | + } else { |
| 82 | + $text = wfMsg( 'approvedrevs-notlatest' ); |
| 83 | + global $wgUser; |
| 84 | + $sk = $wgUser->getSkin(); |
| 85 | + $curRevLink = $sk->link( |
| 86 | + $article->getTitle(), |
| 87 | + wfMsgHtml( 'approvedrevs-viewlatest' ), |
| 88 | + array(), |
| 89 | + array( 'oldid' => $article->getLatest() ), |
| 90 | + array( 'known', 'noclasses' ) |
| 91 | + ); |
| 92 | + $text .= ' ' . $curRevLink; |
| 93 | + } |
| 94 | + global $wgOut; |
| 95 | + $wgOut->setSubtitle( $text ); |
| 96 | + return false; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * If user is looking at a revision through a main 'view' URL (no |
| 101 | + * revision specified), have the 'edit' tab link to the basic |
| 102 | + * 'action=edit' URL (i.e., the latest revision), no matter which |
| 103 | + * revision they're actually on. |
| 104 | + */ |
| 105 | + static function changeEditLink( &$skin, &$contentActions ) { |
| 106 | + global $wgRequest; |
| 107 | + if ( $wgRequest->getCheck( 'oldid' ) ) { |
| 108 | + return true; |
| 109 | + } |
| 110 | + if ( ApprovedRevs::hasApprovedRevision( $skin->getTitle() ) ) { |
| 111 | + $contentActions['views']['edit']['href'] = $skin->getTitle()->getLocalUrl( array( 'action' => 'edit' ) ); |
| 112 | + } |
| 113 | + return true; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Store the approved revision ID, if any, directly in the object |
| 118 | + * for this article - this is called so that a query to the database |
| 119 | + * can be made just once for every view of a history page, instead |
| 120 | + * of for every row. |
| 121 | + */ |
| 122 | + static function storeApprovedRevisionForHistoryPage( &$article ) { |
| 123 | + // this will be null if there's no ID |
| 124 | + $approvedRevID = ApprovedRevs::getApprovedRevID( $article->getTitle() ); |
| 125 | + $article->approvedRevID = $approvedRevID; |
| 126 | + // also load extension messages, while we're at it |
| 127 | + wfLoadExtensionMessages( 'ApprovedRevs' ); |
| 128 | + return true; |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * If the user is allowed to make revision approvals, add either an |
| 133 | + * 'approve' or 'unapprove' link to the end of this row in the page |
| 134 | + * history, depending on whether or not this is already the approved |
| 135 | + * revision. If it's the approved revision also add on a "star" |
| 136 | + * icon, regardless of the user. |
| 137 | + */ |
| 138 | + static function addApprovalLink( $historyPage, &$row , &$s ) { |
| 139 | + $title = $historyPage->getTitle(); |
| 140 | + if ( ApprovedRevs::hasUnsupportedNamespace( $title ) ) { |
| 141 | + return true; |
| 142 | + } |
| 143 | + |
| 144 | + $article = $historyPage->getArticle(); |
| 145 | + // use the rev ID field in the $article object, which was |
| 146 | + // stored earlier |
| 147 | + $approvedRevID = $article->approvedRevID; |
| 148 | + if ( $row->rev_id == $approvedRevID ) { |
| 149 | + $s .= '★ '; |
| 150 | + } |
| 151 | + if ( $title->userCan( 'approverevisions' ) ) { |
| 152 | + if ( $row->rev_id == $approvedRevID ) { |
| 153 | + $url = $title->getLocalUrl( |
| 154 | + array( 'action' => 'unapprove' ) |
| 155 | + ); |
| 156 | + $msg = wfMsg( 'approvedrevs-unapprove' ); |
| 157 | + } else { |
| 158 | + $url = $title->getLocalUrl( |
| 159 | + array( 'action' => 'approve', 'oldid' => $row->rev_id ) |
| 160 | + ); |
| 161 | + $msg = wfMsg( 'approvedrevs-approve' ); |
| 162 | + } |
| 163 | + $s .= '(' . Xml::element( |
| 164 | + 'a', |
| 165 | + array( 'href' => $url ), |
| 166 | + $msg |
| 167 | + ) . ')'; |
| 168 | + } |
| 169 | + return true; |
| 170 | + } |
| 171 | + |
| 172 | + /** |
| 173 | + * Handle the 'approve' action, defined for ApprovedRevs - |
| 174 | + * mark the revision as approved, log it, and show a message to |
| 175 | + * the user. |
| 176 | + */ |
| 177 | + static function setAsApproved( $action, $article ) { |
| 178 | + // return "true" if the call failed (meaning, pass on handling |
| 179 | + // of the hook to others), and "false" otherwise |
| 180 | + if ( $action != 'approve' ) { |
| 181 | + return true; |
| 182 | + } |
| 183 | + $title = $article->getTitle(); |
| 184 | + if ( ApprovedRevs::hasUnsupportedNamespace( $title ) ) { |
| 185 | + return true; |
| 186 | + } |
| 187 | + if ( ! $title->userCan( 'approverevisions' ) ) { |
| 188 | + return true; |
| 189 | + } |
| 190 | + global $wgRequest; |
| 191 | + if ( ! $wgRequest->getCheck( 'oldid' ) ) { |
| 192 | + return true; |
| 193 | + } |
| 194 | + $revision_id = $wgRequest->getVal( 'oldid' ); |
| 195 | + ApprovedRevs::setApprovedRevID( $title, $revision_id ); |
| 196 | + |
| 197 | + global $wgOut; |
| 198 | + $wgOut->addHTML( ' ' . Xml::element( |
| 199 | + 'div', |
| 200 | + array( 'class' => 'successbox' ), |
| 201 | + wfMsg( 'approvedrevs-approvesuccess' ) |
| 202 | + ) . "\n" ); |
| 203 | + $wgOut->addHTML( ' ' . Xml::element( |
| 204 | + 'p', |
| 205 | + array( 'style' => 'clear: both' ) |
| 206 | + ) . "\n" ); |
| 207 | + |
| 208 | + // show the revision, instead of the history page |
| 209 | + $article->doPurge(); |
| 210 | + $article->view(); |
| 211 | + return false; |
| 212 | + } |
| 213 | + |
| 214 | + /** |
| 215 | + * Handle the 'unapprove' action, defined for ApprovedRevs - |
| 216 | + * unset the previously-approved revision, log the change, and show |
| 217 | + * a message to the user. |
| 218 | + */ |
| 219 | + static function unsetAsApproved( $action, $article ) { |
| 220 | + // return "true" if the call failed (meaning, pass on handling |
| 221 | + // of the hook to others), and "false" otherwise |
| 222 | + if ( $action != 'unapprove' ) { |
| 223 | + return true; |
| 224 | + } |
| 225 | + $title = $article->getTitle(); |
| 226 | + if ( ! $title->userCan( 'approverevisions' ) ) { |
| 227 | + return true; |
| 228 | + } |
| 229 | + |
| 230 | + ApprovedRevs::unsetApproval( $title ); |
| 231 | + |
| 232 | + global $wgOut; |
| 233 | + $wgOut->addHTML( ' ' . Xml::element( |
| 234 | + 'div', |
| 235 | + array( 'class' => 'successbox' ), |
| 236 | + wfMsg( 'approvedrevs-unapprovesuccess' ) |
| 237 | + ) . "\n" ); |
| 238 | + $wgOut->addHTML( ' ' . Xml::element( |
| 239 | + 'p', |
| 240 | + array( 'style' => 'clear: both' ) |
| 241 | + ) . "\n" ); |
| 242 | + |
| 243 | + // show the revision, instead of the history page |
| 244 | + $article->doPurge(); |
| 245 | + $article->view(); |
| 246 | + return false; |
| 247 | + } |
| 248 | + |
| 249 | + /** |
| 250 | + * Use the approved revision, if it exists, for templates and other |
| 251 | + * transcluded pages. |
| 252 | + */ |
| 253 | + static function setTranscludedPageRev( $parser, &$title, &$skip, &$id ) { |
| 254 | + $revision_id = ApprovedRevs::getApprovedRevID( $title ); |
| 255 | + if ( ! is_null( $revision_id ) ) { |
| 256 | + $id = $revision_id; |
| 257 | + } |
| 258 | + return true; |
| 259 | + } |
| 260 | + |
| 261 | + /** |
| 262 | + * Deletes the approval record in the database if the page itself is |
| 263 | + * deleted. |
| 264 | + */ |
| 265 | + static function deleteRevisionApproval( &$article, &$user, $reason, $id ) { |
| 266 | + ApprovedRevs::deleteRevisionApproval( $article->getTitle() ); |
| 267 | + return true; |
| 268 | + } |
| 269 | + |
| 270 | + /** |
| 271 | + * Adds a link to 'Special:ApprovedPages' to the the page |
| 272 | + * 'Special:AdminLinks', defined by the Admin Links extension. |
| 273 | + */ |
| 274 | + function addToAdminLinks( &$admin_links_tree ) { |
| 275 | + $general_section = $admin_links_tree->getSection( wfMsg( 'adminlinks_general' ) ); |
| 276 | + $extensions_row = $general_section->getRow( 'extensions' ); |
| 277 | + if ( is_null( $extensions_row ) ) { |
| 278 | + $extensions_row = new ALRow( 'extensions' ); |
| 279 | + $general_section->addRow( $extensions_row ); |
| 280 | + } |
| 281 | + $extensions_row->addItem( ALItem::newFromSpecialPage( 'ApprovedPages' ) ); |
| 282 | + return true; |
| 283 | + } |
| 284 | + |
| 285 | + public static function describeDBSchema() { |
| 286 | + global $wgExtNewTables, $wgDBtype; |
| 287 | + |
| 288 | + $dir = dirname( __FILE__ ); |
| 289 | + |
| 290 | + // DB updates |
| 291 | + //if ( $wgDBtype == 'mysql' ) { |
| 292 | + $wgExtNewTables[] = array( 'approved_revs', "$dir/ApprovedRevs.sql" ); |
| 293 | + //} |
| 294 | + return true; |
| 295 | + } |
| 296 | +} |
Property changes on: tags/extensions/ApprovedRevs/REL_0_1/ApprovedRevs.hooks.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 297 | + native |
Index: tags/extensions/ApprovedRevs/REL_0_1/README |
— | — | @@ -0,0 +1,35 @@ |
| 2 | +Approved Revs Extension |
| 3 | + |
| 4 | + Version 0.1 |
| 5 | + Yaron Koren |
| 6 | + |
| 7 | +This is free software licensed under the GNU General Public License. Please |
| 8 | +see http://www.gnu.org/copyleft/gpl.html for further details, including the |
| 9 | +full text and terms of the license. |
| 10 | + |
| 11 | +== Overview == |
| 12 | + |
| 13 | +Approved Revs is an extension to MediaWiki that lets administrators mark a |
| 14 | +certain revision of a page as "approved". The approved revision is the one |
| 15 | +displayed when users view the page at its main URL. |
| 16 | + |
| 17 | +For more information, see the extension homepage at: |
| 18 | +http://www.mediawiki.org/wiki/Extension:Approved_Revs |
| 19 | + |
| 20 | +== Requirements == |
| 21 | + |
| 22 | +This version of the Approved Revs extension requires MediaWiki 1.11 or |
| 23 | +higher. |
| 24 | + |
| 25 | +== Installation == |
| 26 | + |
| 27 | +To install the extension, place the entire 'ApprovedRevs' directory |
| 28 | +within your MediaWiki 'extensions' directory, then add the following |
| 29 | +line to your 'LocalSettings.php' file: |
| 30 | + |
| 31 | + require_once( "$IP/extensions/ApprovedRevs/ApprovedRevs.php" ); |
| 32 | + |
| 33 | +== Contact == |
| 34 | + |
| 35 | +Comments, questions, suggestions and bug reports should be sent to Yaron |
| 36 | +Koren, at yaron57@gmail.com. |
Property changes on: tags/extensions/ApprovedRevs/REL_0_1/README |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 37 | + native |
Index: tags/extensions/ApprovedRevs/REL_0_1/ApprovedRevs.alias.php |
— | — | @@ -0,0 +1,13 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Aliases for special pages of Approved Revs extension. |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +$aliases = array(); |
| 9 | + |
| 10 | +/** English |
| 11 | + */ |
| 12 | +$aliases['en'] = array( |
| 13 | + 'ApprovedPages' => array( 'ApprovedPages' ), |
| 14 | +); |
Property changes on: tags/extensions/ApprovedRevs/REL_0_1/ApprovedRevs.alias.php |
___________________________________________________________________ |
Name: svn:keywords |
1 | 15 | + Id |
Name: svn:eol-style |
2 | 16 | + native |
Index: tags/extensions/ApprovedRevs/REL_0_1/ApprovedRevs.sql |
— | — | @@ -0,0 +1,6 @@ |
| 2 | +CREATE TABLE /*_*/approved_revs ( |
| 3 | + page_id int(8) default NULL, |
| 4 | + rev_id int(8) default NULL |
| 5 | +) /*$wgDBTableOptions*/; |
| 6 | + |
| 7 | +CREATE UNIQUE INDEX approved_revs_page_id ON /*_*/approved_revs (page_id); |
Property changes on: tags/extensions/ApprovedRevs/REL_0_1/ApprovedRevs.sql |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 8 | + native |