/
ApprovedRevs.hooks.php
905 lines (808 loc) · 26.4 KB
/
ApprovedRevs.hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
<?php
/**
* Functions for the Approved Revs extension called by hooks in the MediaWiki
* code.
*
* @file
* @ingroup Extensions
*
* @author Yaron Koren
* @author Jeroen De Dauw
*/
class ApprovedRevsHooks {
static $mNoSaveOccurring = false;
static public function userRevsApprovedAutomatically( $title ) {
global $egApprovedRevsAutomaticApprovals;
return ( ApprovedRevs::userCanApprove( $title ) && $egApprovedRevsAutomaticApprovals );
}
/**
* "noindex" and "nofollow" meta-tags are added to every revision page,
* so that search engines won't index them - remove those if this is
* the approved revision.
* There doesn't seem to be an ideal MediaWiki hook to use for this
* function - it currently uses 'PersonalUrls', which works.
*/
static public function removeRobotsTag( &$personal_urls, &$title ) {
if ( ! ApprovedRevs::isDefaultPageRequest() ) {
return true;
}
$revisionID = ApprovedRevs::getApprovedRevID( $title );
if ( ! empty( $revisionID ) ) {
global $wgOut;
$wgOut->setRobotPolicy( 'index,follow' );
}
return true;
}
/**
* Call LinksUpdate on the text of this page's approved revision,
* if there is one.
*/
static public function updateLinksAfterEdit( &$page, &$editInfo, $changed ) {
$title = $page->getTitle();
if ( ! ApprovedRevs::pageIsApprovable( $title ) ) {
return true;
}
// If this user's revisions get approved automatically,
// exit now, because this will be the approved
// revision anyway.
if ( self::userRevsApprovedAutomatically( $title ) ) {
return true;
}
$text = '';
$approvedText = ApprovedRevs::getApprovedContent( $title );
if ( !is_null( $approvedText ) ) {
$text = $approvedText;
}
// If there's no approved revision, and 'blank if
// unapproved' is set to true, set the text to blank.
if ( is_null( $approvedText ) ) {
global $egApprovedRevsBlankIfUnapproved;
if ( $egApprovedRevsBlankIfUnapproved ) {
$text = '';
} else {
// If it's an unapproved page and there's no
// page blanking, exit here.
return true;
}
}
$editInfo = $page->prepareTextForEdit( $text );
$u = new LinksUpdate( $page->mTitle, $editInfo->output );
$u->doUpdate();
return true;
}
/**
* If the user saving this page has approval power, and automatic
* approvals are enabled, and the page is approvable, and either
* (a) this page already has an approved revision, or (b) unapproved
* pages are shown as blank on this wiki, automatically set this
* latest revision to be the approved one - don't bother logging
* the approval, though; the log is reserved for manual approvals.
*/
static public function setLatestAsApproved( &$article , &$user, $text,
$summary, $flags, $unused1, $unused2, &$flags, $revision,
&$status, $baseRevId ) {
if ( is_null( $revision ) ) {
return true;
}
$title = $article->getTitle();
if ( ! self::userRevsApprovedAutomatically( $title ) ) {
return true;
}
if ( !ApprovedRevs::pageIsApprovable( $title ) ) {
return true;
}
global $egApprovedRevsBlankIfUnapproved;
if ( !$egApprovedRevsBlankIfUnapproved ) {
$approvedRevID = ApprovedRevs::getApprovedRevID( $title );
if ( empty( $approvedRevID ) ) {
return true;
}
}
// Save approval without logging.
ApprovedRevs::saveApprovedRevIDInDB( $title, $revision->getID() );
return true;
}
/**
* Set the text that's stored for the page for standard searches.
*/
static public function setSearchText( &$article , &$user, $text,
$summary, $flags, $unused1, $unused2, &$flags, $revision,
&$status, $baseRevId ) {
if ( is_null( $revision ) ) {
return true;
}
$title = $article->getTitle();
if ( !ApprovedRevs::pageIsApprovable( $title ) ) {
return true;
}
$revisionID = ApprovedRevs::getApprovedRevID( $title );
if ( is_null( $revisionID ) ) {
return true;
}
// We only need to modify the search text if the approved
// revision is not the latest one.
if ( $revisionID != $article->getLatest() ) {
$approvedArticle = new Article( $title, $revisionID );
$approvedText = $approvedArticle->getContent();
ApprovedRevs::setPageSearchText( $title, $approvedText );
}
return true;
}
/**
* Sets the correct page revision to display the "text snippet" for
* a search result.
*/
public static function setSearchRevisionID( $title, &$id ) {
$revisionID = ApprovedRevs::getApprovedRevID( $title );
if ( !is_null( $revisionID ) ) {
$id = $revisionID;
}
return true;
}
/**
* Return the approved revision of the page, if there is one, and if
* the page is simply being viewed, and if no specific revision has
* been requested.
*/
static function showApprovedRevision( &$title, &$article ) {
if ( ! ApprovedRevs::isDefaultPageRequest() ) {
return true;
}
$namespace = $title->getNamespace();
global $egApprovedRevsNamespaces;
if ( ! in_array ( $namespace, $egApprovedRevsNamespaces ) ) {
return true;
}
global $egApprovedRevsBlankIfUnapproved;
$revisionID = ApprovedRevs::getApprovedRevID( $title );
// Starting in around MW 1.24, blanking of unapproved pages
// seems to no longer work unless code like this is called -
// possibly because the cache needs to be disabled. There
// may be a better way to accomplish that than this, but this
// works, and it doesn't seem to have a noticeable negative
// impact, so we'll go with it for now, at least.
if ( ! empty( $revisionID ) || $egApprovedRevsBlankIfUnapproved ) {
$article = new Article( $title, $revisionID );
// This call (whichever it is) is necessary because it
// causes $article->mRevision to get initialized,
// which in turn allows "edit section" links to show
// up if the approved revision is also the latest.
if ( method_exists( $article, 'getRevisionFetched' ) ) {
// MW 1.19+
$article->getRevisionFetched();
} else {
// MW 1.18
$article->fetchContent();
}
}
return true;
}
public static function showBlankIfUnapproved( &$article, &$content ) {
global $egApprovedRevsBlankIfUnapproved;
if ( ! $egApprovedRevsBlankIfUnapproved ) {
return true;
}
$title = $article->getTitle();
if ( ! ApprovedRevs::pageIsApprovable( $title ) ) {
return true;
}
$revisionID = ApprovedRevs::getApprovedRevID( $title );
if ( !empty( $revisionID ) ) {
return true;
}
// Disable the cache for every page, if users aren't meant
// to see pages with no approved revision, and this page
// has no approved revision. This looks extreme - but
// there doesn't seem to be any other way to distinguish
// between a user looking at the main view of page, and a
// user specifically looking at the latest revision of the
// page (which we don't want to show as blank.)
global $wgEnableParserCache;
$wgEnableParserCache = false;
if ( ! ApprovedRevs::isDefaultPageRequest() ) {
return true;
}
ApprovedRevs::addCSS();
$content = '';
return true;
}
/**
* Called for MW 1.21+.
*/
public static function showBlankIfUnapproved2( &$article, &$contentObject ) {
return self::showBlankIfUnapproved( $article, $contentObject->mText );
}
/**
* Sets the subtitle when viewing old revisions of a page.
* This function's code is mostly copied from Article::setOldSubtitle(),
* and it is meant to serve as a replacement for that function, using
* the 'DisplayOldSubtitle' hook.
* This display has the following differences from the standard one:
* - It includes a link to the approved revision, which goes to the
* default page.
* - It includes a "diff" link alongside it.
* - The "Latest revision" link points to the correct revision ID,
* instead of to the default page (unless the latest revision is also
* the approved one).
*
* @author Eli Handel
*/
static function setOldSubtitle( $article, $revisionID ) {
$title = $article->getTitle(); # Added for ApprovedRevs - and removed hook
$unhide = $article->getContext()->getRequest()->getInt( 'unhide' ) == 1;
// Cascade unhide param in links for easy deletion browsing.
$extraParams = array();
if ( $unhide ) {
$extraParams['unhide'] = 1;
}
if ( $article->mRevision && $article->mRevision->getId() === $revisionID ) {
$revision = $article->mRevision;
} else {
$revision = Revision::newFromId( $revisionID );
}
$timestamp = $revision->getTimestamp();
$latestID = $article->getLatest(); // Modified for Approved Revs
$current = ( $revisionID == $latestID );
$approvedID = ApprovedRevs::getApprovedRevID( $title );
$language = $article->getContext()->getLanguage();
$user = $article->getContext()->getUser();
$td = $language->userTimeAndDate( $timestamp, $user );
$tddate = $language->userDate( $timestamp, $user );
$tdtime = $language->userTime( $timestamp, $user );
// Show the user links if they're allowed to see them.
// If hidden, then show them only if requested...
$userlinks = Linker::revUserTools( $revision, !$unhide );
$infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
? 'revision-info-current'
: 'revision-info';
$outputPage = $article->getContext()->getOutput();
$outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
$td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
$tdtime, $revision->getUser() )->parse() . "</div>" );
// Created for Approved Revs
$latestLinkParams = array();
if ( $latestID != $approvedID ) {
$latestLinkParams['oldid'] = $latestID;
}
$lnk = $current
? wfMessage( 'currentrevisionlink' )->escaped()
: Linker::linkKnown(
$title,
wfMessage( 'currentrevisionlink' )->escaped(),
array(),
$latestLinkParams + $extraParams
);
$curdiff = $current
? wfMessage( 'diff' )->escaped()
: Linker::linkKnown(
$title,
wfMessage( 'diff' )->escaped(),
array(),
array(
'diff' => 'cur',
'oldid' => $revisionID
) + $extraParams
);
$prev = $title->getPreviousRevisionID( $revisionID );
$prevlink = $prev
? Linker::linkKnown(
$title,
wfMessage( 'previousrevision' )->escaped(),
array(),
array(
'direction' => 'prev',
'oldid' => $revisionID
) + $extraParams
)
: wfMessage( 'previousrevision' )->escaped();
$prevdiff = $prev
? Linker::linkKnown(
$title,
wfMessage( 'diff' )->escaped(),
array(),
array(
'diff' => 'prev',
'oldid' => $revisionID
) + $extraParams
)
: wfMessage( 'diff' )->escaped();
$nextlink = $current
? wfMessage( 'nextrevision' )->escaped()
: Linker::linkKnown(
$title,
wfMessage( 'nextrevision' )->escaped(),
array(),
array(
'direction' => 'next',
'oldid' => $revisionID
) + $extraParams
);
$nextdiff = $current
? wfMessage( 'diff' )->escaped()
: Linker::linkKnown(
$title,
wfMessage( 'diff' )->escaped(),
array(),
array(
'diff' => 'next',
'oldid' => $revisionID
) + $extraParams
);
// Added for Approved Revs
$approved = ( $approvedID != null && $revisionID == $approvedID );
$approvedlink = $approved
? wfMessage( 'approvedrevs-approvedrevision' )->escaped()
: Linker::linkKnown(
$title,
wfMessage( 'approvedrevs-approvedrevision' )->escaped(),
array(),
$extraParams
);
$approveddiff = $approved
? wfMessage( 'diff' )->escaped()
: Linker::linkKnown(
$title,
wfMessage( 'diff' )->escaped(),
array(),
array(
'diff' => $approvedID,
'oldid' => $revisionID
) + $extraParams
);
$cdel = Linker::getRevDeleteLink( $user, $revision, $title );
if ( $cdel !== '' ) {
$cdel .= ' ';
}
// Modified for ApprovedRevs
$outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
wfMessage( 'approvedrevs-revision-nav' )->rawParams(
$prevdiff, $prevlink, $approvedlink, $approveddiff, $lnk, $curdiff, $nextlink, $nextdiff
)->escaped() . "</div>" );
}
/**
* If user is viewing the page via its main URL, and what they're
* seeing is the approved revision of the page, remove the standard
* subtitle shown for all non-latest revisions, and replace it with
* either nothing or a message explaining the situation, depending
* on the user's rights.
*/
static function setSubtitle( &$article, &$revisionID ) {
$title = $article->getTitle();
if ( ! ApprovedRevs::hasApprovedRevision( $title ) ) {
return true;
}
global $wgRequest;
if ( $wgRequest->getCheck( 'oldid' ) ) {
// If the user is looking at the latest revision,
// disable caching, to avoid the wiki getting the
// contents from the cache, and thus getting the
// approved contents instead.
if ( $revisionID == $article->getLatest() ) {
global $wgEnableParserCache;
$wgEnableParserCache = false;
}
self::setOldSubtitle( $article, $revisionID );
// Don't show default Article::setOldSubtitle().
return false;
}
if ( ! $title->userCan( 'viewlinktolatest' ) ) {
return false;
}
ApprovedRevs::addCSS();
if ( $revisionID == $article->getLatest() ) {
$text = Xml::element(
'span',
array( 'class' => 'approvedAndLatestMsg' ),
wfMessage( 'approvedrevs-approvedandlatest' )->text()
);
} else {
$text = wfMessage( 'approvedrevs-notlatest' )->parse();
$text .= ' ' . Linker::link(
$title,
wfMessage( 'approvedrevs-viewlatestrev' )->parse(),
array(),
array( 'oldid' => $article->getLatest() ),
array( 'known', 'noclasses' )
);
$text = Xml::tags(
'span',
array( 'class' => 'notLatestMsg' ),
$text
);
}
global $wgOut;
if ( $wgOut->getSubtitle() != '' ) {
$wgOut->addSubtitle( '<br />' . $text );
} else {
$wgOut->setSubtitle( $text );
}
return false;
}
/**
* Add a warning to the top of the 'edit' page if the approved
* revision is not the same as the latest one, so that users don't
* get confused, since they'll be seeing the latest one.
*/
public static function addWarningToEditPage( &$editPage ) {
// only show the warning if it's not an old revision
global $wgRequest;
if ( $wgRequest->getCheck( 'oldid' ) ) {
return true;
}
$title = $editPage->getArticle()->getTitle();
$approvedRevID = ApprovedRevs::getApprovedRevID( $title );
$latestRevID = $title->getLatestRevID();
if ( ! empty( $approvedRevID ) && $approvedRevID != $latestRevID ) {
ApprovedRevs::addCSS();
// A lengthy way to avoid not calling $wgOut...
// hopefully this is better!
$editPage->getArticle()->getContext()->getOutput()->wrapWikiMsg( "<p class=\"approvedRevsEditWarning\">$1</p>\n", 'approvedrevs-editwarning' );
}
return true;
}
/**
* Same as addWarningToEditPage(), but for the Semantic Foms
* 'edit with form' tab.
*/
public static function addWarningToSFForm( &$pageName, &$preFormHTML ) {
// The title could be obtained via $pageName in theory - the
// problem is that, pre-SF 2.0.2, that variable wasn't set
// correctly.
global $wgTitle;
$approvedRevID = ApprovedRevs::getApprovedRevID( $wgTitle );
$latestRevID = $wgTitle->getLatestRevID();
if ( ! empty( $approvedRevID ) && $approvedRevID != $latestRevID ) {
ApprovedRevs::addCSS();
$preFormHTML .= Xml::element ( 'p',
array( 'style' => 'font-weight: bold' ),
wfMessage( 'approvedrevs-editwarning' )->text() ) . "\n";
}
return true;
}
/**
* If user is looking at a revision through a main 'view' URL (no
* revision specified), have the 'edit' tab link to the basic
* 'action=edit' URL (i.e., the latest revision), no matter which
* revision they're actually on.
*/
static function changeEditLink( $skin, &$contentActions ) {
global $wgRequest;
if ( $wgRequest->getCheck( 'oldid' ) ) {
return true;
}
$title = $skin->getTitle();
if ( ApprovedRevs::hasApprovedRevision( $title ) ) {
// the URL is the same regardless of whether the tab
// is 'edit' or 'view source', but the "action" is
// different
if ( array_key_exists( 'edit', $contentActions ) ) {
$contentActions['edit']['href'] = $title->getLocalUrl( array( 'action' => 'edit' ) );
}
if ( array_key_exists( 'viewsource', $contentActions ) ) {
$contentActions['viewsource']['href'] = $title->getLocalUrl( array( 'action' => 'edit' ) );
}
}
return true;
}
/**
* Same as changedEditLink(), but only for the Vector skin (and
* related skins).
*/
static function changeEditLinkVector( &$skin, &$links ) {
// the old '$content_actions' array is thankfully just a
// sub-array of this one
self::changeEditLink( $skin, $links['views'] );
return true;
}
/**
* Store the approved revision ID, if any, directly in the object
* for this article - this is called so that a query to the database
* can be made just once for every view of a history page, instead
* of for every row.
*/
static function storeApprovedRevisionForHistoryPage( &$article ) {
// A bug in some versions of MW 1.19 causes $article to be null.
if ( is_null( $article ) ) {
return true;
}
// This will be null if there's no ID.
$approvedRevID = ApprovedRevs::getApprovedRevID( $article->getTitle() );
$article->getTitle()->approvedRevID = $approvedRevID;
return true;
}
/**
* If the user is allowed to make revision approvals, add either an
* 'approve' or 'unapprove' link to the end of this row in the page
* history, depending on whether or not this is already the approved
* revision. If it's the approved revision also add on a "star"
* icon, regardless of the user.
*/
static function addApprovalLink( $historyPage, &$row , &$s ) {
$title = $historyPage->getTitle();
if ( ! ApprovedRevs::pageIsApprovable( $title ) ) {
return true;
}
$article = $historyPage->getArticle();
// use the rev ID field in the $article object, which was
// stored earlier
$approvedRevID = $title->approvedRevID;
if ( $row->rev_id == $approvedRevID ) {
$s .= ' ★';
}
if ( ApprovedRevs::userCanApprove( $title ) ) {
if ( $row->rev_id == $approvedRevID ) {
$url = $title->getLocalUrl(
array( 'action' => 'unapprove' )
);
$msg = wfMessage( 'approvedrevs-unapprove' )->text();
} else {
$url = $title->getLocalUrl(
array( 'action' => 'approve', 'oldid' => $row->rev_id )
);
$msg = wfMessage( 'approvedrevs-approve' )->text();
}
$s .= ' (' . Xml::element(
'a',
array( 'href' => $url ),
$msg
) . ')';
}
return true;
}
/**
* Handle the 'approve' action, defined for ApprovedRevs -
* mark the revision as approved, log it, and show a message to
* the user.
*/
static function setAsApproved( $action, $article ) {
// Return "true" if the call failed (meaning, pass on handling
// of the hook to others), and "false" otherwise.
if ( $action != 'approve' ) {
return true;
}
$title = $article->getTitle();
if ( ! ApprovedRevs::pageIsApprovable( $title ) ) {
return true;
}
if ( ! ApprovedRevs::userCanApprove( $title ) ) {
return true;
}
global $wgRequest;
if ( ! $wgRequest->getCheck( 'oldid' ) ) {
return true;
}
$revisionID = $wgRequest->getVal( 'oldid' );
ApprovedRevs::setApprovedRevID( $title, $revisionID );
global $wgOut;
$wgOut->addHTML( "\t\t" . Xml::element(
'div',
array( 'class' => 'successbox' ),
wfMessage( 'approvedrevs-approvesuccess' )->text()
) . "\n" );
$wgOut->addHTML( "\t\t" . Xml::element(
'p',
array( 'style' => 'clear: both' )
) . "\n" );
// Seems to be needed when the latest version is approved -
// at least when the Cargo extension is being used.
$article->doPurge();
// Show the revision, instead of the history page.
$article->view();
return false;
}
/**
* Handle the 'unapprove' action, defined for ApprovedRevs -
* unset the previously-approved revision, log the change, and show
* a message to the user.
*/
static function unsetAsApproved( $action, $article ) {
// return "true" if the call failed (meaning, pass on handling
// of the hook to others), and "false" otherwise
if ( $action != 'unapprove' ) {
return true;
}
$title = $article->getTitle();
if ( ! ApprovedRevs::userCanApprove( $title ) ) {
return true;
}
ApprovedRevs::unsetApproval( $title );
// the message depends on whether the page should display
// a blank right now or not
global $egApprovedRevsBlankIfUnapproved;
if ( $egApprovedRevsBlankIfUnapproved ) {
$successMsg = wfMessage( 'approvedrevs-unapprovesuccess2' )->text();
} else {
$successMsg = wfMessage( 'approvedrevs-unapprovesuccess' )->text();
}
global $wgOut;
$wgOut->addHTML( "\t\t" . Xml::element(
'div',
array( 'class' => 'successbox' ),
$successMsg
) . "\n" );
$wgOut->addHTML( "\t\t" . Xml::element(
'p',
array( 'style' => 'clear: both' )
) . "\n" );
// show the revision, instead of the history page
$article->doPurge();
$article->view();
return false;
}
/**
* Use the approved revision, if it exists, for templates and other
* transcluded pages.
*/
static function setTranscludedPageRev( $parser, $title, &$skip, &$id ) {
$revisionID = ApprovedRevs::getApprovedRevID( $title );
if ( ! empty( $revisionID ) ) {
$id = $revisionID;
}
return true;
}
/**
* Delete the approval record in the database if the page itself is
* deleted.
*/
static function deleteRevisionApproval( &$article, &$user, $reason, $id ) {
ApprovedRevs::deleteRevisionApproval( $article->getTitle() );
return true;
}
/**
* Register magic-word variable IDs
*/
static function addMagicWordVariableIDs( &$magicWordVariableIDs ) {
$magicWordVariableIDs[] = 'MAG_APPROVEDREVS';
return true;
}
/**
* Set values in the page_props table based on the presence of the
* 'APPROVEDREVS' magic word in a page
*/
static function handleMagicWords( &$parser, &$text ) {
$mw_hide = MagicWord::get( 'MAG_APPROVEDREVS' );
if ( $mw_hide->matchAndRemove( $text ) ) {
$parser->mOutput->setProperty( 'approvedrevs', 'y' );
}
return true;
}
/**
* Add a link to 'Special:ApprovedPages' to the the page
* 'Special:AdminLinks', defined by the Admin Links extension.
*/
static function addToAdminLinks( &$admin_links_tree ) {
$general_section = $admin_links_tree->getSection( wfMessage( 'adminlinks_general' )->text() );
$extensions_row = $general_section->getRow( 'extensions' );
if ( is_null( $extensions_row ) ) {
$extensions_row = new ALRow( 'extensions' );
$general_section->addRow( $extensions_row );
}
$extensions_row->addItem( ALItem::newFromSpecialPage( 'ApprovedRevs' ) );
return true;
}
public static function describeDBSchema( $updater = null ) {
$dir = dirname( __FILE__ );
// DB updates
// For now, there's just a single SQL file for all DB types.
if ( $updater === null ) {
global $wgExtNewTables, $wgDBtype;
//if ( $wgDBtype == 'mysql' ) {
$wgExtNewTables[] = array( 'approved_revs', "$dir/ApprovedRevs.sql" );
//}
} else {
//if ( $updater->getDB()->getType() == 'mysql' ) {
$updater->addExtensionUpdate( array( 'addTable', 'approved_revs', "$dir/ApprovedRevs.sql", true ) );
//}
}
return true;
}
/**
* Display a message to the user if (a) "blank if unapproved" is set,
* (b) the page is approvable, (c) the user has 'viewlinktolatest'
* permission, and (d) either the page has no approved revision, or
* the user is looking at a revision that's not the latest - the
* displayed message depends on which of those cases it is.
* @TODO - this should probably get split up into two methods.
*
* @since 0.5.6
*
* @param Article &$article
* @param boolean $outputDone
* @param boolean $useParserCache
*
* @return true
*/
public static function setArticleHeader( Article &$article, &$outputDone, &$useParserCache ) {
global $wgOut, $wgRequest, $egApprovedRevsBlankIfUnapproved;
// For now, we only set the header if "blank if unapproved"
// is set.
if ( ! $egApprovedRevsBlankIfUnapproved ) {
return true;
}
$title = $article->getTitle();
if ( ! ApprovedRevs::pageIsApprovable( $title ) ) {
return true;
}
// If the user isn't supposed to see these kinds of
// messages, exit.
if ( ! $title->userCan( 'viewlinktolatest' ) ) {
return false;
}
// If there's an approved revision for this page, and the
// user is looking at it - either by simply going to the page,
// or by looking at the revision that happens to be approved -
// don't display anything.
$approvedRevID = ApprovedRevs::getApprovedRevID( $title );
if ( ! empty( $approvedRevID ) &&
( ! $wgRequest->getCheck( 'oldid' ) ||
$wgRequest->getInt( 'oldid' ) == $approvedRevID ) ) {
return true;
}
// Disable caching, so that if it's a specific ID being shown
// that happens to be the latest, it doesn't show a blank page.
$useParserCache = false;
$wgOut->addHTML( '<span style="margin-left: 10.75px">' );
// If the user is looking at a specific revision, show an
// "approve this revision" message - otherwise, it means
// there's no approved revision (we would have exited out if
// there were), so show a message explaining why the page is
// blank, with a link to the latest revision.
if ( $wgRequest->getCheck( 'oldid' ) ) {
if ( ApprovedRevs::userCanApprove( $title ) ) {
// @TODO - why is this message being shown
// at all? Aren't the "approve this revision"
// links in the history page always good
// enough?
$wgOut->addHTML( Xml::tags( 'span', array( 'id' => 'contentSub2' ),
Xml::element( 'a',
array( 'href' => $title->getLocalUrl(
array(
'action' => 'approve',
'oldid' => $wgRequest->getInt( 'oldid' )
)
) ),
wfMessage( 'approvedrevs-approvethisrev' )->text()
) ) );
}
} else {
$wgOut->addSubtitle(
htmlspecialchars( wfMessage( 'approvedrevs-blankpageshown' )->text() ) . ' ' .
Xml::element( 'a',
array( 'href' => $title->getLocalUrl(
array(
'oldid' => $article->getRevIdFetched()
)
) ),
wfMessage( 'approvedrevs-viewlatestrev' )->text()
)
);
}
$wgOut->addHTML( '</span>' );
return true;
}
/**
* If this page is approvable, but has no approved revision, display
* a header message stating that, if the setting to display this
* message is activated.
*/
public static function displayNotApprovedHeader( Article &$article, &$outputDone, &$useParserCache ) {
global $egApprovedRevsShowNotApprovedMessage;
if ( !$egApprovedRevsShowNotApprovedMessage) {
return true;
}
$title = $article->getTitle();
if ( ! ApprovedRevs::pageIsApprovable( $title ) ) {
return true;
}
if ( ! ApprovedRevs::hasApprovedRevision( $title ) ) {
$text = wfMessage( 'approvedrevs-noapprovedrevision' )->text();
global $wgOut;
if ( $wgOut->getSubtitle() != '' ) {
$wgOut->addSubtitle( '<br />' . $text );
} else {
$wgOut->setSubtitle( $text );
}
}
return true;
}
}