Index: trunk/extensions/ApprovedRevs/ApprovedRevs_body.php |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | * @author Yaron Koren |
11 | 11 | */ |
12 | 12 | class ApprovedRevs { |
| 13 | + |
13 | 14 | /** |
14 | 15 | * Gets the approved revision ID for this page, or null if there isn't |
15 | 16 | * one. |
Index: trunk/extensions/ApprovedRevs/ApprovedRevs.i18n.php |
— | — | @@ -38,6 +38,10 @@ |
39 | 39 | 'approvedrevs-revisionnumber' => 'revision $1', |
40 | 40 | 'approvedrevs-approvedby' => 'approved by $1 on $2', |
41 | 41 | 'approvedrevs-difffromlatest' => 'diff from latest', |
| 42 | + 'approvedrevs-viewlatest' => 'view latest', |
| 43 | + 'approvedrevs-approvelatest' => 'approve latest', |
| 44 | + 'approvedrevs-approvethisrev' => 'Approve this revision', |
| 45 | + 'approvedrevs-viewlatestrev' => 'View the latest revision', |
42 | 46 | 'right-approverevisions' => 'Set a certain revision of a wiki page as approved', |
43 | 47 | 'right-viewlinktolatest' => 'View explanatory text at the top of pages that have an approved revision', |
44 | 48 | ); |
Index: trunk/extensions/ApprovedRevs/ApprovedRevs.php |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 | $egApprovedRevsNamespaces = array( NS_MAIN, NS_TEMPLATE, NS_HELP, NS_PROJECT ); |
29 | 29 | $egApprovedRevsBlankIfUnapproved = false; |
30 | 30 | $egApprovedRevsAutomaticApprovals = true; |
| 31 | +$egApprovedRevsShowApproveLatest = false; |
31 | 32 | |
32 | 33 | // internationalization |
33 | 34 | $wgExtensionMessagesFiles['ApprovedRevs'] = $egApprovedRevsIP . 'ApprovedRevs.i18n.php'; |
— | — | @@ -62,6 +63,7 @@ |
63 | 64 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'ApprovedRevsHooks::describeDBSchema'; |
64 | 65 | $wgHooks['EditPage::showEditForm:initial'][] = 'ApprovedRevsHooks::addWarningToEditPage'; |
65 | 66 | $wgHooks['sfHTMLBeforeForm'][] = 'ApprovedRevsHooks::addWarningToSFForm'; |
| 67 | +$wgHooks['ArticleViewHeader'][] = 'ApprovedRevsHooks::onArticleViewHeader'; |
66 | 68 | |
67 | 69 | // logging |
68 | 70 | $wgLogTypes['approval'] = 'approval'; |
Index: trunk/extensions/ApprovedRevs/SpecialApprovedRevs.php |
— | — | @@ -22,18 +22,22 @@ |
23 | 23 | ApprovedRevs::addCSS(); |
24 | 24 | $this->setHeaders(); |
25 | 25 | list( $limit, $offset ) = wfCheckLimits(); |
| 26 | + |
26 | 27 | $mode = $wgRequest->getVal( 'show' ); |
27 | 28 | $rep = new SpecialApprovedRevsPage( $mode ); |
| 29 | + |
28 | 30 | if ( method_exists( $rep, 'execute' ) ) { |
29 | 31 | return $rep->execute( $query ); |
30 | 32 | } else { |
31 | 33 | return $rep->doQuery( $offset, $limit ); |
32 | 34 | } |
33 | 35 | } |
| 36 | + |
34 | 37 | } |
35 | 38 | |
36 | 39 | class SpecialApprovedRevsPage extends QueryPage { |
37 | | - private $mMode; |
| 40 | + |
| 41 | + protected $mMode; |
38 | 42 | |
39 | 43 | public function __construct( $mode ) { |
40 | 44 | if ( $this instanceof SpecialPage ) { |
— | — | @@ -56,6 +60,7 @@ |
57 | 61 | $approvedPagesPage = SpecialPage::getPage( 'ApprovedRevs' ); |
58 | 62 | $approvedPagesTitle = SpecialPage::getPage( 'ApprovedRevs' )->getTitle(); |
59 | 63 | $navLine = wfMsg( 'approvedrevs-view' ) . ' '; |
| 64 | + |
60 | 65 | if ( $this->mMode == '' ) { |
61 | 66 | $navLine .= Xml::element( 'strong', |
62 | 67 | null, |
— | — | @@ -67,7 +72,9 @@ |
68 | 73 | wfMsg( 'approvedrevs-approvedpages' ) |
69 | 74 | ); |
70 | 75 | } |
71 | | - $navLine .= " | "; |
| 76 | + |
| 77 | + $navLine .= ' | '; |
| 78 | + |
72 | 79 | if ( $this->mMode == 'notlatest' ) { |
73 | 80 | $navLine .= Xml::element( 'strong', |
74 | 81 | null, |
— | — | @@ -79,7 +86,9 @@ |
80 | 87 | wfMsg( 'approvedrevs-notlatestpages' ) |
81 | 88 | ); |
82 | 89 | } |
83 | | - $navLine .= " | "; |
| 90 | + |
| 91 | + $navLine .= ' | '; |
| 92 | + |
84 | 93 | if ( $this->mMode == 'unapproved' ) { |
85 | 94 | $navLine .= Xml::element( 'strong', |
86 | 95 | null, |
— | — | @@ -91,8 +100,8 @@ |
92 | 101 | wfMsg( 'approvedrevs-unapprovedpages' ) |
93 | 102 | ); |
94 | 103 | } |
95 | | - $header = Xml::tags( 'p', null, $navLine ) . "\n"; |
96 | | - return $header; |
| 104 | + |
| 105 | + return Xml::tags( 'p', null, $navLine ) . "\n"; |
97 | 106 | } |
98 | 107 | |
99 | 108 | /** |
— | — | @@ -100,12 +109,14 @@ |
101 | 110 | */ |
102 | 111 | function linkParameters() { |
103 | 112 | $params = array(); |
| 113 | + |
104 | 114 | if ( $this->mMode == 'notlatest' ) { |
105 | 115 | $params['show'] = 'notlatest'; |
106 | 116 | } elseif ( $this->mMode == 'unapproved' ) { |
107 | 117 | $params['show'] = 'unapproved'; |
108 | 118 | } else { // all approved pages |
109 | 119 | } |
| 120 | + |
110 | 121 | return $params; |
111 | 122 | } |
112 | 123 | |
— | — | @@ -141,7 +152,8 @@ |
142 | 153 | WHERE p.page_latest != ar.rev_id AND $nsCond"; |
143 | 154 | } elseif ( $this->mMode == 'unapproved' ) { |
144 | 155 | return "SELECT 'Page' AS type, |
145 | | - p.page_id AS id |
| 156 | + p.page_id AS id, |
| 157 | + p.page_latest AS latest_id |
146 | 158 | FROM $approved_revs ar RIGHT OUTER JOIN $page p |
147 | 159 | ON ar.page_id = p.page_id |
148 | 160 | WHERE ar.page_id IS NULL AND $nsCond"; |
— | — | @@ -185,7 +197,7 @@ |
186 | 198 | } elseif ( $this->mMode == 'unapproved' ) { |
187 | 199 | return array( |
188 | 200 | 'tables' => array( 'ar' => 'approved_revs', 'p' => 'page' ), |
189 | | - 'fields' => array( 'p.page_id AS id' ), |
| 201 | + 'fields' => array( 'p.page_id AS id', 'p.page_latest AS latest_id' ), |
190 | 202 | 'join_conds' => array( |
191 | 203 | 'p' => array( |
192 | 204 | 'RIGHT OUTER JOIN', 'ar.page_id=p.page_id' |
— | — | @@ -224,10 +236,36 @@ |
225 | 237 | |
226 | 238 | function formatResult( $skin, $result ) { |
227 | 239 | $title = Title::newFromId( $result->id ); |
228 | | - $pageLink = $skin->makeLinkObj( $title ); |
229 | 240 | |
| 241 | + // link introduced in 1.16, where makeLinkObj got deprecated |
| 242 | + $pageLink = is_callable( $skin, 'link' ) ? $skin->link( $title ) : $skin->makeLinkObj( $title ); |
| 243 | + |
230 | 244 | if ( $this->mMode == 'unapproved' ) { |
231 | | - return $pageLink; |
| 245 | + global $egApprovedRevsShowApproveLatest; |
| 246 | + |
| 247 | + $viewLatest = Xml::element( 'a', |
| 248 | + array( 'href' => $title->getLocalUrl( |
| 249 | + array( |
| 250 | + 'oldid' => $result->latest_id |
| 251 | + ) |
| 252 | + ) ), |
| 253 | + wfMsg( 'approvedrevs-viewlatest' ) |
| 254 | + ); |
| 255 | + |
| 256 | + $approveLatest = ''; |
| 257 | + if ( $egApprovedRevsShowApproveLatest ) { |
| 258 | + $approveLatest = ', ' . Xml::element( 'a', |
| 259 | + array( 'href' => $title->getLocalUrl( |
| 260 | + array( |
| 261 | + 'action' => 'approve', |
| 262 | + 'oldid' => $result->latest_id |
| 263 | + ) |
| 264 | + ) ), |
| 265 | + wfMsg( 'approvedrevs-approvelatest' ) |
| 266 | + ); |
| 267 | + } |
| 268 | + |
| 269 | + return "$pageLink ({$viewLatest}{$approveLatest})"; |
232 | 270 | } elseif ( $this->mMode == 'notlatest' ) { |
233 | 271 | $diffLink = Xml::element( 'a', |
234 | 272 | array( 'href' => $title->getLocalUrl( |
— | — | @@ -243,14 +281,10 @@ |
244 | 282 | } else { |
245 | 283 | global $wgUser, $wgOut, $wgLang; |
246 | 284 | |
247 | | - if ( $result->rev_id == $result->latest_id ) { |
248 | | - $class = "approvedRevIsLatest"; |
249 | | - } else { |
250 | | - $class = "approvedRevNotLatest"; |
251 | | - } |
252 | | - |
253 | 285 | $additionalInfo = Xml::element( 'span', |
254 | | - array ( 'class' => $class ), |
| 286 | + array ( |
| 287 | + 'class' => $result->rev_id == $result->latest_id ? 'approvedRevIsLatest' : 'approvedRevNotLatest' |
| 288 | + ), |
255 | 289 | wfMsg( 'approvedrevs-revisionnumber', $result->rev_id ) |
256 | 290 | ); |
257 | 291 | |
Index: trunk/extensions/ApprovedRevs/ApprovedRevs.hooks.php |
— | — | @@ -406,6 +406,7 @@ |
407 | 407 | // show the revision, instead of the history page |
408 | 408 | $article->doPurge(); |
409 | 409 | $article->view(); |
| 410 | + |
410 | 411 | return false; |
411 | 412 | } |
412 | 413 | |
— | — | @@ -450,6 +451,7 @@ |
451 | 452 | // show the revision, instead of the history page |
452 | 453 | $article->doPurge(); |
453 | 454 | $article->view(); |
| 455 | + |
454 | 456 | return false; |
455 | 457 | } |
456 | 458 | |
— | — | @@ -537,4 +539,52 @@ |
538 | 540 | } |
539 | 541 | return true; |
540 | 542 | } |
| 543 | + |
| 544 | + /** |
| 545 | + * Hook to insert things into article headers. |
| 546 | + * |
| 547 | + * @since 0.5.6 |
| 548 | + * |
| 549 | + * @param Article &$article |
| 550 | + * @param boolean $outputDone |
| 551 | + * @param boolean $useParserCache |
| 552 | + * |
| 553 | + * @return true |
| 554 | + */ |
| 555 | + public static function onArticleViewHeader( Article &$article, &$outputDone, &$useParserCache ) { |
| 556 | + global $wgOut, $wgRequest, $egApprovedRevsBlankIfUnapproved; |
| 557 | + |
| 558 | + if ( ApprovedRevs::pageIsApprovable( $article->getTitle() ) |
| 559 | + && $article->getTitle()->userCan( 'approverevisions' ) ) { |
| 560 | + |
| 561 | + $approvedId = ApprovedRevs::getApprovedRevID( $article->getTitle() ); |
| 562 | + |
| 563 | + if ( empty( $approvedId ) || $approvedId != $article->getRevIdFetched() ) { |
| 564 | + if ( $egApprovedRevsBlankIfUnapproved && !$wgRequest->getCheck( 'oldid' ) ) { |
| 565 | + $wgOut->addHTML( Xml::element( 'a', |
| 566 | + array( 'href' => $article->getTitle()->getLocalUrl( |
| 567 | + array( |
| 568 | + 'oldid' => $article->getRevIdFetched() |
| 569 | + ) |
| 570 | + ) ), |
| 571 | + wfMsg( 'approvedrevs-viewlatestrev' ) |
| 572 | + ) ); |
| 573 | + } |
| 574 | + else { |
| 575 | + $wgOut->addHTML( '<b>' . Xml::element( 'a', |
| 576 | + array( 'href' => $article->getTitle()->getLocalUrl( |
| 577 | + array( |
| 578 | + 'action' => 'approve', |
| 579 | + 'oldid' => $article->getRevIdFetched() |
| 580 | + ) |
| 581 | + ) ), |
| 582 | + wfMsg( 'approvedrevs-approvethisrev' ) |
| 583 | + ) . '</b>' ); |
| 584 | + } |
| 585 | + } |
| 586 | + } |
| 587 | + |
| 588 | + return true; |
| 589 | + } |
| 590 | + |
541 | 591 | } |