Index: trunk/extensions/ApprovedRevs/ApprovedRevs.php |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | * @author Yaron Koren |
11 | 11 | */ |
12 | 12 | |
13 | | -define( 'APPROVED_REVS_VERSION', '0.3.1' ); |
| 13 | +define( 'APPROVED_REVS_VERSION', '0.4' ); |
14 | 14 | |
15 | 15 | // credits |
16 | 16 | $wgExtensionCredits['other'][] = array( |
— | — | @@ -24,6 +24,7 @@ |
25 | 25 | // global variables |
26 | 26 | $egApprovedRevsIP = dirname( __FILE__ ) . '/'; |
27 | 27 | $egApprovedRevsNamespaces = array( NS_MAIN, NS_TEMPLATE, NS_HELP, NS_PROJECT ); |
| 28 | +$egApprovedRevsBlankIfUnapproved = false; |
28 | 29 | |
29 | 30 | // internationalization |
30 | 31 | $wgExtensionMessagesFiles['ApprovedRevs'] = $egApprovedRevsIP . 'ApprovedRevs.i18n.php'; |
— | — | @@ -35,10 +36,15 @@ |
36 | 37 | $wgSpecialPages['ApprovedPages'] = 'ARApprovedPages'; |
37 | 38 | $wgAutoloadClasses['ARApprovedPages'] = $egApprovedRevsIP . 'AR_ApprovedPages.php'; |
38 | 39 | $wgSpecialPageGroups['ApprovedPages'] = 'pages'; |
| 40 | +$wgSpecialPages['UnapprovedPages'] = 'ARUnapprovedPages'; |
| 41 | +$wgAutoloadClasses['ARUnapprovedPages'] = $egApprovedRevsIP . 'AR_UnapprovedPages.php'; |
| 42 | +$wgSpecialPageGroups['UnapprovedPages'] = 'pages'; |
39 | 43 | |
40 | 44 | // hooks |
41 | 45 | $wgHooks['ParserBeforeInternalParse'][] = 'ApprovedRevsHooks::setApprovedRevForParsing'; |
| 46 | +$wgHooks['ArticleSaveComplete'][] = 'ApprovedRevsHooks::setLatestAsApproved'; |
42 | 47 | $wgHooks['ArticleFromTitle'][] = 'ApprovedRevsHooks::showApprovedRevision'; |
| 48 | +$wgHooks['ArticleAfterFetchContent'][] = 'ApprovedRevsHooks::showBlankIfUnapproved'; |
43 | 49 | $wgHooks['DisplayOldSubtitle'][] = 'ApprovedRevsHooks::setSubtitle'; |
44 | 50 | $wgHooks['SkinTemplateNavigation'][] = 'ApprovedRevsHooks::changeEditLink'; |
45 | 51 | $wgHooks['PageHistoryBeforeList'][] = 'ApprovedRevsHooks::storeApprovedRevisionForHistoryPage'; |
— | — | @@ -66,4 +72,5 @@ |
67 | 73 | $wgAvailableRights[] = 'viewlinktolatest'; |
68 | 74 | $wgGroupPermissions['*']['viewlinktolatest'] = true; |
69 | 75 | |
| 76 | +// page properties |
70 | 77 | $wgPageProps['approvedrevs'] = 'Whether or not the page is approvable'; |
Index: trunk/extensions/ApprovedRevs/ApprovedRevs.hooks.php |
— | — | @@ -1,7 +1,5 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -if ( ! defined( 'MEDIAWIKI' ) ) die(); |
5 | | - |
6 | 4 | /** |
7 | 5 | * Functions for the Approved Revs extension called by hooks in the MediaWiki |
8 | 6 | * code. |
— | — | @@ -14,38 +12,74 @@ |
15 | 13 | |
16 | 14 | class ApprovedRevsHooks { |
17 | 15 | |
| 16 | + /** |
| 17 | + * If the page is being saved, set the text of the approved revision |
| 18 | + * as the text to be parsed, for correct saving of categories, |
| 19 | + * Semantic MediaWiki properties, etc. |
| 20 | + */ |
18 | 21 | static public function setApprovedRevForParsing( &$parser, &$text, &$stripState ) { |
19 | 22 | global $wgRequest; |
20 | 23 | $action = $wgRequest->getVal( 'action' ); |
21 | 24 | if ( $action == 'submit' ) { |
22 | 25 | $title = $parser->getTitle(); |
| 26 | + if ( ! ApprovedRevs::pageIsApprovable( $title ) ) { |
| 27 | + return true; |
| 28 | + } |
| 29 | + // if this is someone with approval power editing the |
| 30 | + // page, exit now, because this will become the |
| 31 | + // approved revision anyway |
| 32 | + if ( $title->userCan( 'approverevisions' ) ) { |
| 33 | + return true; |
| 34 | + } |
23 | 35 | $approvedText = ApprovedRevs::getApprovedContent( $title ); |
24 | 36 | if ( !is_null( $approvedText ) ) { |
25 | 37 | $text = $approvedText; |
26 | 38 | } |
| 39 | + // if there's no approved revision, and 'blank if |
| 40 | + // unapproved' is set to true, set the text to blank |
| 41 | + if ( is_null( $approvedText ) ) { |
| 42 | + global $egApprovedRevsBlankIfUnapproved; |
| 43 | + if ( $egApprovedRevsBlankIfUnapproved ) { |
| 44 | + $text = ''; |
| 45 | + } |
| 46 | + } |
27 | 47 | } |
28 | 48 | return true; |
29 | 49 | } |
30 | 50 | |
31 | 51 | /** |
| 52 | + * If the user saving this page has approval power, automatically |
| 53 | + * set this latest revision to be the approved one - don't bother |
| 54 | + * logging the approval, though; the log is reserved for manual |
| 55 | + * approvals. |
| 56 | + */ |
| 57 | + static public function setLatestAsApproved( &$article ) { |
| 58 | + $title = $article->getTitle(); |
| 59 | + if ( ! ApprovedRevs::pageIsApprovable( $title ) ) { |
| 60 | + return true; |
| 61 | + } |
| 62 | + if ( $title->userCan( 'approverevisions' ) ) { |
| 63 | + // the rev ID is actually passed in via the hook, but |
| 64 | + // it's at the end of a very long set of parameters, |
| 65 | + // so for the sake of sanity we'll just re-get it |
| 66 | + // here instead |
| 67 | + $latestRevisionID = $title->getLatestRevID(); |
| 68 | + // save approval without logging |
| 69 | + ApprovedRevs::saveApprovedRevIDInDB( $title, $latestRevisionID ); |
| 70 | + } |
| 71 | + return true; |
| 72 | + } |
| 73 | + |
| 74 | + /** |
32 | 75 | * Return the approved revision of the page, if there is one, and if |
33 | 76 | * the page is simply being viewed, and if no specific revision has |
34 | 77 | * been requested. |
35 | 78 | */ |
36 | 79 | static function showApprovedRevision( &$title, &$article ) { |
37 | | - // if a revision ID is set, exit |
38 | | - if ( $title->mArticleID > -1 ) { |
| 80 | + if ( ! ApprovedRevs::isDefaultPageRequest() ) { |
39 | 81 | return true; |
40 | 82 | } |
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 | | - |
| 83 | + |
50 | 84 | $revisionID = ApprovedRevs::getApprovedRevID( $title ); |
51 | 85 | if ( ! empty( $revisionID ) ) { |
52 | 86 | $article = new Article( $title, $revisionID ); |
— | — | @@ -53,6 +87,24 @@ |
54 | 88 | return true; |
55 | 89 | } |
56 | 90 | |
| 91 | + public static function showBlankIfUnapproved( &$article, &$content ) { |
| 92 | + if ( ! ApprovedRevs::isDefaultPageRequest() ) { |
| 93 | + return true; |
| 94 | + } |
| 95 | + |
| 96 | + $title = $article->getTitle(); |
| 97 | + $revisionID = ApprovedRevs::getApprovedRevID( $title ); |
| 98 | + if ( empty( $revisionID ) ) { |
| 99 | + global $egApprovedRevsBlankIfUnapproved; |
| 100 | + if ( $egApprovedRevsBlankIfUnapproved ) { |
| 101 | + $content = ''; |
| 102 | + global $wgOut; |
| 103 | + $wgOut->setSubtitle( wfMsg( 'approvedrevs-blankpageshown' ) ); |
| 104 | + } |
| 105 | + } |
| 106 | + return true; |
| 107 | + } |
| 108 | + |
57 | 109 | /** |
58 | 110 | * If user is viewing the page via its main URL, and what they're |
59 | 111 | * seeing is the approved revision of the page, remove the standard |
— | — | @@ -236,11 +288,20 @@ |
237 | 289 | |
238 | 290 | ApprovedRevs::unsetApproval( $title ); |
239 | 291 | |
| 292 | + // the message depends on whether the page should display |
| 293 | + // a blank right now or not |
| 294 | + global $egApprovedRevsBlankIfUnapproved; |
| 295 | + if ( $egApprovedRevsBlankIfUnapproved ) { |
| 296 | + $successMsg = wfMsg( 'approvedrevs-unapprovesuccess2' ); |
| 297 | + } else { |
| 298 | + $successMsg = wfMsg( 'approvedrevs-unapprovesuccess' ); |
| 299 | + } |
| 300 | + |
240 | 301 | global $wgOut; |
241 | 302 | $wgOut->addHTML( ' ' . Xml::element( |
242 | 303 | 'div', |
243 | 304 | array( 'class' => 'successbox' ), |
244 | | - wfMsg( 'approvedrevs-unapprovesuccess' ) |
| 305 | + $successMsg |
245 | 306 | ) . "\n" ); |
246 | 307 | $wgOut->addHTML( ' ' . Xml::element( |
247 | 308 | 'p', |
— | — | @@ -266,7 +327,7 @@ |
267 | 328 | } |
268 | 329 | |
269 | 330 | /** |
270 | | - * Deletes the approval record in the database if the page itself is |
| 331 | + * Delete the approval record in the database if the page itself is |
271 | 332 | * deleted. |
272 | 333 | */ |
273 | 334 | static function deleteRevisionApproval( &$article, &$user, $reason, $id ) { |
— | — | @@ -306,7 +367,7 @@ |
307 | 368 | } |
308 | 369 | |
309 | 370 | /** |
310 | | - * Adds a link to 'Special:ApprovedPages' to the the page |
| 371 | + * Add a link to 'Special:ApprovedPages' to the the page |
311 | 372 | * 'Special:AdminLinks', defined by the Admin Links extension. |
312 | 373 | */ |
313 | 374 | function addToAdminLinks( &$admin_links_tree ) { |
— | — | @@ -317,6 +378,7 @@ |
318 | 379 | $general_section->addRow( $extensions_row ); |
319 | 380 | } |
320 | 381 | $extensions_row->addItem( ALItem::newFromSpecialPage( 'ApprovedPages' ) ); |
| 382 | + $extensions_row->addItem( ALItem::newFromSpecialPage( 'UnapprovedPages' ) ); |
321 | 383 | return true; |
322 | 384 | } |
323 | 385 | |
— | — | @@ -326,6 +388,7 @@ |
327 | 389 | $dir = dirname( __FILE__ ); |
328 | 390 | |
329 | 391 | // DB updates |
| 392 | + // For now, there's just a single SQL file for all DB types. |
330 | 393 | //if ( $wgDBtype == 'mysql' ) { |
331 | 394 | $wgExtNewTables[] = array( 'approved_revs', "$dir/ApprovedRevs.sql" ); |
332 | 395 | //} |
Index: trunk/extensions/ApprovedRevs/ApprovedRevs_body.php |
— | — | @@ -45,6 +45,33 @@ |
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
| 49 | + * Helper function - returns whether the user is currently requesting |
| 50 | + * a page via the simple URL for it - not specfying a version number, |
| 51 | + * not editing the page, etc. |
| 52 | + */ |
| 53 | + public static function isDefaultPageRequest() { |
| 54 | + // this first test seems to no longer work with MW 1.16 |
| 55 | + /* |
| 56 | + if ( $title->mArticleID > -1 ) { |
| 57 | + return true; |
| 58 | + } |
| 59 | + */ |
| 60 | + global $wgRequest; |
| 61 | + if ( $wgRequest->getCheck( 'oldid' ) ) { |
| 62 | + return false; |
| 63 | + } |
| 64 | + // check if it's an action other than viewing |
| 65 | + global $wgRequest; |
| 66 | + if ( $wgRequest->getCheck( 'action' ) && |
| 67 | + $wgRequest->getVal( 'action' ) != 'view' && |
| 68 | + $wgRequest->getVal( 'action' ) != 'purge' && |
| 69 | + $wgRequest->getVal( 'action' ) != 'render' ) { |
| 70 | + return false; |
| 71 | + } |
| 72 | + return true; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
49 | 76 | * Returns whether this page can be approved - either because it's in |
50 | 77 | * a supported namespace, or because it's been specially marked as |
51 | 78 | * approvable. Also stores the boolean answer as a field in the page |
— | — | @@ -82,13 +109,7 @@ |
83 | 110 | return $isApprovable; |
84 | 111 | } |
85 | 112 | |
86 | | - /** |
87 | | - * Sets a certain revision as the approved one for this page in the |
88 | | - * approved_revs DB table; calls a "links update" on this revision |
89 | | - * so that category information can be stored correctly, as well as |
90 | | - * info for extensions such as Semantic MediaWiki; and logs the action. |
91 | | - */ |
92 | | - public static function setApprovedRevID( $title, $rev_id, $is_latest = false ) { |
| 113 | + public static function saveApprovedRevIDInDB( $title, $rev_id ) { |
93 | 114 | $dbr = wfGetDB( DB_MASTER ); |
94 | 115 | $page_id = $title->getArticleId(); |
95 | 116 | $old_rev_id = $dbr->selectField( 'approved_revs', 'rev_id', array( 'page_id' => $page_id ) ); |
— | — | @@ -97,7 +118,16 @@ |
98 | 119 | } else { |
99 | 120 | $dbr->insert( 'approved_revs', array( 'page_id' => $page_id, 'rev_id' => $rev_id ) ); |
100 | 121 | } |
| 122 | + } |
101 | 123 | |
| 124 | + /** |
| 125 | + * Sets a certain revision as the approved one for this page in the |
| 126 | + * approved_revs DB table; calls a "links update" on this revision |
| 127 | + * so that category information can be stored correctly, as well as |
| 128 | + * info for extensions such as Semantic MediaWiki; and logs the action. |
| 129 | + */ |
| 130 | + public static function setApprovedRevID( $title, $rev_id, $is_latest = false ) { |
| 131 | + self::saveApprovedRevIDInDB( $title, $rev_id ); |
102 | 132 | // if the revision being approved is definitely the latest |
103 | 133 | // one, there's no need to call the parser on it |
104 | 134 | if ( !$is_latest ) { |