r80403 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80402‎ | r80403 | r80404 >
Date:15:49, 15 January 2011
Author:ialex
Status:deferred
Tags:
Comment:
* Moved hooks to their own file
* Don't use a proxy object in $wgArticle, replaced by ArticleViewFooter hook introduced in r80333, this also fixes bug 26724
* Also modified the proxy object when saving the edit to be compatible with r80402
Modified paths:
  • /trunk/extensions/TalkHere/TalkHere.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TalkHere/TalkHere.php
@@ -31,62 +31,15 @@
3232 $wgExtensionMessagesFiles['TalkHere'] = $dir . 'TalkHere.i18n.php';
3333
3434 ///// hook it up /////////////////////////////////////////////////////
35 -$wgAutoloadClasses['TalkHereArticle'] = $dir . 'TalkHereArticle.php';
36 -$wgAutoloadClasses['TalkHereEditTarget'] = $dir . 'TalkHereArticle.php';
 35+$wgAutoloadClasses['TalkHereHooks'] = $dir . 'TalkHereHooks.php';
3736
38 -$wgHooks['BeforePageDisplay'][] = 'wfTalkHereBeforePageDisplay';
39 -$wgHooks['ArticleFromTitle'][] = 'wfTalkHereArticleFromTitle';
40 -$wgHooks['CustomEditor'][] = 'wfTalkHereCustomEditor';
41 -$wgHooks['EditPage::showEditForm:fields'][] = 'wfTalkHereShowEditFormFields';
 37+$wgHooks['BeforePageDisplay'][] = 'TalkHereHooks::onBeforePageDisplay';
 38+$wgHooks['CustomEditor'][] = 'TalkHereHooks::onCustomEditor';
 39+$wgHooks['EditPage::showEditForm:fields'][] = 'TalkHereHooks::onShowEditFormFields';
 40+$wgHooks['ArticleViewFooter'][] = 'TalkHereHooks::onArticleViewFooter';
4241
4342 $wgAjaxExportList[] = 'wfTalkHereAjaxEditor';
4443
45 -function wfTalkHereBeforePageDisplay( $out, $skin ) {
46 - global $wgScriptPath, $wgJsMimeType, $wgUseAjax;
47 -
48 - $out->addExtensionStyle( $wgScriptPath . '/extensions/TalkHere/TalkHere.css' );
49 -
50 - if ( $wgUseAjax ) {
51 - $out->addScriptFile( $wgScriptPath . '/extensions/TalkHere/TalkHere.js' );
52 - }
53 -
54 - return true;
55 -}
56 -
57 -function wfTalkHereArticleFromTitle( &$title, &$article ) {
58 - global $wgRequest, $wgTalkHereNamespaces;
59 -
60 - if ( isset( $title->noTalkHere ) ) {
61 - return true; //stop recursion
62 - }
63 -
64 - $action = $wgRequest->getVal( 'action' );
65 - $oldid = $wgRequest->getVal( 'oldid' );
66 - $diff = $wgRequest->getVal( 'diff' );
67 -
68 - if ($action == 'purge') $action = null; //"purge" is not considered an action in this context
69 -
70 - if ( $action || $oldid || $diff ) return true;
71 -
72 - $ns = $title->getNamespace();
73 -
74 - if ( !MWNamespace::isTalk($ns) && MWNamespace::canTalk($ns) && $title->exists()
75 - && ( !$wgTalkHereNamespaces || in_array($ns, $wgTalkHereNamespaces) ) ) {
76 - $tns = MWNamespace::getTalk($ns);
77 - $talk = Title::makeTitle($tns, $title->getDBkey());
78 -
79 - if ($talk && $talk->userCan('read')) {
80 - $t = clone $title;
81 - $t->noTalkHere = true; //stop recursion
82 -
83 - $a = MediaWiki::articleFromTitle( $t );
84 - $article = new TalkHereArticle( $a, $talk );
85 - }
86 - }
87 -
88 - return true;
89 -}
90 -
9144 function mangleEditForm( &$out, $returnto = false, $ajax = false ) { //HACK! too bad we need this :(
9245 global $wgUser;
9346 $sk = $wgUser->getSkin();
@@ -105,41 +58,6 @@
10659 $out->addHTML($html);
10760 }
10861
109 -function wfTalkHereCustomEditor( $article, $user ) {
110 - global $wgRequest, $wgOut;
111 -
112 - $action = $wgRequest->getVal( 'action' );
113 - $oldid = $wgRequest->getVal( 'oldid' );
114 - $returnto = $wgRequest->getVal( 'wpReturnTo' );
115 - $talkhere = $wgRequest->getVal( 'wpTalkHere' );
116 - if (!$talkhere || $action != 'submit' || !$returnto || $oldid) return true; //go on as normal
117 -
118 - $to = Title::newFromText($returnto);
119 - if (!$to) return true; //go on as normal
120 -
121 - //use a wrapper to override redirection target
122 - $a = new TalkHereEditTarget( $article, $to );
123 - $editor = new EditPage( $a );
124 - $editor->submit();
125 -
126 - mangleEditForm( $wgOut, $returnto ); //HACK. This sucks.
127 - return false;
128 -}
129 -
130 -function wfTalkHereShowEditFormFields( &$editor, &$out ) {
131 - global $wgRequest;
132 -
133 - $returnto = $wgRequest->getVal( 'wpReturnTo' );
134 - $talkhere = $wgRequest->getVal( 'wpTalkHere' );
135 -
136 - if ($talkhere && $returnto) {
137 - $out->addHTML('<input type="hidden" value="1" name="wpTalkHere" id="wpTalkHere" />');
138 - $out->addHTML('<input type="hidden" value="'.htmlspecialchars($returnto).'" name="wpReturnTo" id="wpReturnTo" />');
139 - }
140 -
141 - return true;
142 -}
143 -
14462 function wfTalkHereAjaxEditor( $page, $section, $returnto ) {
14563 global $wgRequest, $wgTitle, $wgOut;
14664

Follow-up revisions

RevisionCommit summaryAuthorDate
r80404Fix for r80403: seems I only commited one fileialex15:50, 15 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r80333Added ArticleViewFooter hook to allow extensions adding additional items to t...ialex21:54, 14 January 2011
r80402Modified EditPage to use Article::doEdit() instead of Article::insertNewArtic...ialex15:21, 15 January 2011

Status & tagging log