r67288 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67287‎ | r67288 | r67289 >
Date:18:03, 3 June 2010
Author:tisane
Status:deferred (Comments)
Tags:
Comment:
Adding documentation to RPED and PWD, etc.
Modified paths:
  • /trunk/extensions/PureWikiDeletion/PureWikiDeletion.hooks.php (modified) (history)
  • /trunk/extensions/PureWikiDeletion/PureWikiDeletion.php (modified) (history)
  • /trunk/extensions/PureWikiDeletion/SpecialPureWikiDeletion.php (modified) (history)
  • /trunk/extensions/RPED/ApiRPED.php (modified) (history)
  • /trunk/extensions/RPED/RPED.hooks.php (modified) (history)
  • /trunk/extensions/RPED/RPED.i18n.php (modified) (history)
  • /trunk/extensions/RPED/RPED.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RPED/RPED.php
@@ -32,7 +32,7 @@
3333 'author' => 'Tisane',
3434 'url' => 'http://www.mediawiki.org/wiki/Extension:RemotePageExistenceDetection',
3535 'descriptionmsg' => 'rped-desc',
36 - 'version' => '1.0.1',
 36+ 'version' => '1.0.2',
3737 );
3838
3939 $dir = dirname( __FILE__ ) . '/';
@@ -44,3 +44,7 @@
4545
4646 $wgHooks['LoadExtensionSchemaUpdates'][] = 'RPEDHooks::RPEDCreateTable';
4747 $wgHooks['LinkBegin'][] = 'RPEDHooks::wikipediaLink';
 48+
 49+$wgRPEDBrokenLinkStyle = "color: red";
 50+$wgRPEDExcludeNamespaced = false;
 51+$wgRemoteStyle = 'color: blue';
\ No newline at end of file
Index: trunk/extensions/RPED/RPED.hooks.php
@@ -14,7 +14,8 @@
1515 public static function wikipediaLink( $skin, $target, &$text,
1616 &$customAttribs, &$query, &$options, &$ret
1717 ) {
18 - global $wgLocalStyle, $wgRemoteStyle, $wgPureWikiDeletionInEffect, $wgTitle, $wgRequest;
 18+ global $wgLocalStyle, $wgRemoteStyle, $wgPureWikiDeletionInEffect
 19+ , $wgTitle, $wgRequest, $wgRPEDBrokenLinkStyle, $wgRPEDExcludeNamespaced;
1920 wfLoadExtensionMessages('RPED');
2021 if ( $wgTitle->getNamespace () == -1 ) {
2122 return true;
@@ -30,6 +31,40 @@
3132
3233 $itIsBlank = false;
3334
 35+ // If it's an external link, see if it leads to Wikipedia, and
 36+ // if so, whether that page exists on Wikipedia
 37+ if ( $target->isExternal() ) {
 38+ $interwikiURL = wfMsgExt( 'rped-wikipedia-url','parsemag');
 39+ $dbr = wfGetDB( DB_SLAVE );
 40+ $title = $target->getDBkey ();
 41+
 42+ if ( strpos ( $title, ':' ) && $wgRPEDExcludeNamespaced ) {
 43+ return true;
 44+ }
 45+
 46+ $interwikiPrefix = $target->getInterwiki ();
 47+ $result = $dbr->selectRow(
 48+ 'interwiki',
 49+ 'iw_prefix',
 50+ array( "iw_url" => $interwikiURL
 51+ , "iw_prefix" => $interwikiPrefix )
 52+ );
 53+
 54+ if ( !$result ) {
 55+ return true;
 56+ }
 57+
 58+ $result = $dbr->selectRow(
 59+ 'rped_page',
 60+ 'rped_page_id',
 61+ array( "rped_page_title" => $title )
 62+ );
 63+ if ( !$result ) {
 64+ $query['action'] = "edit";
 65+ $customAttribs['style'] = $wgRPEDBrokenLinkStyle;
 66+ }
 67+ return true;
 68+ }
3469 // Return immediately if we know it's existent on the local wiki
3570 if ( in_array( 'known', $options ) ) {
3671 if ( !isset( $query['action'] ) && !isset( $query['curid'] ) ) {
@@ -50,7 +85,6 @@
5186 'blank_page_id',
5287 array( "blank_page_id" => $id )
5388 );
54 -
5589 if ( !$result ) {
5690 return true;
5791 }
@@ -79,8 +113,9 @@
80114 if ( !$result ) {
81115 return true;
82116 } else {
83 - $title = htmlentities( $title );
84 - $url = wfMsgExt( 'rped-wikipedia-url','parsemag') . $title;
 117+ $newTitle = $target->getPrefixedURL ();
 118+ #$title = urlencode ( $title );
 119+ $url = wfMsgExt( 'rped-wikipedia-url','parsemag', $newTitle );
85120
86121 // The page that we'll link to
87122 $text = '<a href="' . $url . $fragment. '">' . $text. '</a>';
Index: trunk/extensions/RPED/ApiRPED.php
@@ -31,6 +31,11 @@
3232 return;
3333 }
3434
 35+ /*
 36+ * Insert or delete a row from the rped_page table
 37+ * @param key "insert" or "delete"
 38+ * @param $value Page name to delete
 39+ */
3540 public function paramProcess( $key,$value ){
3641 $dbr = wfGetDB( DB_SLAVE );
3742 $dbw = wfGetDB( DB_MASTER );
Index: trunk/extensions/RPED/RPED.i18n.php
@@ -12,7 +12,7 @@
1313 $messages['en'] = array(
1414 'rped' => 'Remote page existence detection',
1515 'rped-desc' => 'Links wikilinks to Wikipedia if the page does not exist on the local wiki but exists on Wikipedia',
16 - 'rped-wikipedia-url' => 'http://en.wikipedia.org/wiki/',
 16+ 'rped-wikipedia-url' => 'http://en.wikipedia.org/wiki/$1',
1717 );
1818
1919 /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца))
@@ -22,7 +22,7 @@
2323 $messages['be-tarask'] = array(
2424 'rped' => 'Выяўленьне існаваньня вонкавай старонкі',
2525 'rped-desc' => 'Устаўляе вікі-спасылкі на Вікіпэдыю, калі старонка не існуе ў лякальнай вікі, але існуе ў Вікіпэдыі',
26 - 'rped-wikipedia-url' => 'http://be.wikipedia.org/',
 26+ 'rped-wikipedia-url' => 'http://be.wikipedia.org/wiki/$1',
2727 );
2828
2929 /** Breton (Brezhoneg)
@@ -32,7 +32,7 @@
3333 $messages['br'] = array(
3434 'rped' => 'Detektadur a-bell ar pajennoù zo anezho',
3535 'rped-desc' => "Liammañ a ra ar wikiliammoù ouzh Wikipedia ma n'eus ket eus ar bajenn war ar wiki lec'hel ha m'emañ war Wikipedia",
36 - 'rped-wikipedia-url' => 'http://br.wikipedia.org/',
 36+ 'rped-wikipedia-url' => 'http://br.wikipedia.org/wiki/$1',
3737 );
3838
3939 /** German (Deutsch)
@@ -41,7 +41,7 @@
4242 $messages['de'] = array(
4343 'rped' => 'Ermittlung websitefremder Webseiten',
4444 'rped-desc' => 'Leitet Wikilinks zur Wikipedia, sofern die betreffende Seite nicht im lokalen Wiki, aber in der Wikipedia vorhanden ist',
45 - 'rped-wikipedia-url' => 'http://de.wikipedia.org/',
 45+ 'rped-wikipedia-url' => 'http://de.wikipedia.org/wiki/$1',
4646 );
4747
4848 /** Lower Sorbian (Dolnoserbski)
@@ -50,7 +50,7 @@
5151 $messages['dsb'] = array(
5252 'rped' => 'Namakanje eksistence zdalonego boka',
5353 'rped-desc' => 'Wótkazujo wikiwótkaze do Wikipedije, jolic bok njeeksistěrujo w lokalnem wikiju, ale eksistěrujo we Wikipediji',
54 - 'rped-wikipedia-url' => 'http://dsb.wikipedia.org/',
 54+ 'rped-wikipedia-url' => 'http://dsb.wikipedia.org/wiki/$1',
5555 );
5656
5757 /** Spanish (Español)
@@ -59,7 +59,7 @@
6060 $messages['es'] = array(
6161 'rped' => 'Detección de existencia de página remota',
6262 'rped-desc' => 'Enlaza los wikienlaces a Wikipedia si la página no existe en la wiki local pero existe en Wikipedia',
63 - 'rped-wikipedia-url' => 'http://es.wikipedia.org/',
 63+ 'rped-wikipedia-url' => 'http://es.wikipedia.org/wiki/$1',
6464 );
6565
6666 /** French (Français)
@@ -68,7 +68,7 @@
6969 $messages['fr'] = array(
7070 'rped' => "Détection d'existence des pages à distance",
7171 'rped-desc' => "Lie les wikiliens vers Wikipédia si la page n'existe pas sur le wiki local mais existe sur Wikipédia",
72 - 'rped-wikipedia-url' => 'http://fr.wikipedia.org/',
 72+ 'rped-wikipedia-url' => 'http://fr.wikipedia.org/wiki/$1',
7373 );
7474
7575 /** Galician (Galego)
@@ -77,7 +77,7 @@
7878 $messages['gl'] = array(
7979 'rped' => 'Detección remota da existencia de páxinas',
8080 'rped-desc' => 'Crea ligazóns cara á Wikipedia se a páxina non existe no wiki local pero si na Wikipedia',
81 - 'rped-wikipedia-url' => 'http://gl.wikipedia.org/',
 81+ 'rped-wikipedia-url' => 'http://gl.wikipedia.org/wiki/$1',
8282 );
8383
8484 /** Swiss German (Alemannisch)
@@ -86,7 +86,7 @@
8787 $messages['gsw'] = array(
8888 'rped' => 'Erkännig vu främde Netzsyte',
8989 'rped-desc' => 'Leitet Wikilinks uf d Wikipedia, wänn die Syte nit im lokale Wiki git, derfir aber in dr Wikipedia',
90 - 'rped-wikipedia-url' => 'http://gsw.wikipedia.org/',
 90+ 'rped-wikipedia-url' => 'http://gsw.wikipedia.org/wiki/$1',
9191 );
9292
9393 /** Upper Sorbian (Hornjoserbsce)
@@ -95,7 +95,7 @@
9696 $messages['hsb'] = array(
9797 'rped' => 'Wotkryće eksistency zdaleneje strony',
9898 'rped-desc' => 'Wotkazuje wikiwotkazy do Wikipedije, jeli strona njeeksistuje w lokalnym wikiju, ale eksistuje we Wikipediji',
99 - 'rped-wikipedia-url' => 'http://hsb.wikipedia.org/',
 99+ 'rped-wikipedia-url' => 'http://hsb.wikipedia.org/wiki/$1',
100100 );
101101
102102 /** Hungarian (Magyar)
@@ -104,7 +104,7 @@
105105 $messages['hu'] = array(
106106 'rped' => 'Ellenőrzi, hogy egy távoli lap létezik-e',
107107 'rped-desc' => 'A wikilinkeket a Wikipédiára irányítja, ha a lap nem létezik a helyi wikiben, de a Wikipédián igen',
108 - 'rped-wikipedia-url' => 'http://hu.wikipedia.org/',
 108+ 'rped-wikipedia-url' => 'http://hu.wikipedia.org/wiki/$1',
109109 );
110110
111111 /** Interlingua (Interlingua)
@@ -113,7 +113,7 @@
114114 $messages['ia'] = array(
115115 'rped' => 'Detection del existentia de paginas remote',
116116 'rped-desc' => 'Face wiki-ligamines a Wikipedia si le pagina non existe in le wiki local ma existe in Wikipedia',
117 - 'rped-wikipedia-url' => 'http://ia.wikipedia.org/',
 117+ 'rped-wikipedia-url' => 'http://ia.wikipedia.org/wiki/$1',
118118 );
119119
120120 /** Indonesian (Bahasa Indonesia)
@@ -137,7 +137,7 @@
138138 * @author Universal Life
139139 */
140140 $messages['lad'] = array(
141 - 'rped-wikipedia-url' => 'http://lad.wikipedia.org/',
 141+ 'rped-wikipedia-url' => 'http://lad.wikipedia.org/wiki/$1',
142142 );
143143
144144 /** Luxembourgish (Lëtzebuergesch)
@@ -154,7 +154,7 @@
155155 $messages['mk'] = array(
156156 'rped' => 'Пронаоѓач на постоечка надворешна страница',
157157 'rped-desc' => 'Поврзува викиврски со Википедија ако страницата не постои на локалното вики, но постои на Википедија',
158 - 'rped-wikipedia-url' => 'http://mk.wikipedia.org/',
 158+ 'rped-wikipedia-url' => 'http://mk.wikipedia.org/wiki/$1',
159159 );
160160
161161 /** Dutch (Nederlands)
@@ -163,7 +163,7 @@
164164 $messages['nl'] = array(
165165 'rped' => "Detectie van pagina's in andere wiki's",
166166 'rped-desc' => 'Verwijst naar Wikipedia als de pagina niet bestaat in de lokale wiki maar wel in Wikipedia',
167 - 'rped-wikipedia-url' => 'http://nl.wikipedia.org/',
 167+ 'rped-wikipedia-url' => 'http://nl.wikipedia.org/wiki/$1',
168168 );
169169
170170 /** Norwegian (bokmål)‬ (‪Norsk (bokmål)‬)
@@ -172,7 +172,7 @@
173173 $messages['no'] = array(
174174 'rped' => 'Eksistensdeteksjon av eksterne sider',
175175 'rped-desc' => 'Lenker wikilenker til Wikipedia om siden ikke finnes på den lokale wikien men finnes på Wikipedia',
176 - 'rped-wikipedia-url' => 'http://no.wikipedia.org/',
 176+ 'rped-wikipedia-url' => 'http://no.wikipedia.org/wiki/$1',
177177 );
178178
179179 /** Occitan (Occitan)
@@ -189,7 +189,7 @@
190190 $messages['pms'] = array(
191191 'rped' => "Determinassion d'esistensa dle pàgine a distansa",
192192 'rped-desc' => "A colega j'anliure wiki a Wikipedia se la pàgina a esist pa an sla wiki local ma a esist dzora a Wikipedia",
193 - 'rped-wikipedia-url' => 'http://pms.wikipedia.org/',
 193+ 'rped-wikipedia-url' => 'http://pms.wikipedia.org/wiki/$1',
194194 );
195195
196196 /** Portuguese (Português)
@@ -198,7 +198,7 @@
199199 $messages['pt'] = array(
200200 'rped' => 'Detecção da existência de páginas remotas',
201201 'rped-desc' => 'Liga um link à Wikipédia, se a página de destino não existe na wiki local mas existe na Wikipédia',
202 - 'rped-wikipedia-url' => 'http://pt.wikipedia.org/',
 202+ 'rped-wikipedia-url' => 'http://pt.wikipedia.org/wiki/$1',
203203 );
204204
205205 /** Russian (Русский)
@@ -207,7 +207,7 @@
208208 $messages['ru'] = array(
209209 'rped' => 'Обнаружение существования внешней страницы',
210210 'rped-desc' => 'Ставит вики-ссылки на Википедию, если страницы не существует в локальной вики, но она присутствует в Википедии',
211 - 'rped-wikipedia-url' => 'http://ru.wikipedia.org/',
 211+ 'rped-wikipedia-url' => 'http://ru.wikipedia.org/wiki/$1',
212212 );
213213
214214 /** Tagalog (Tagalog)
Index: trunk/extensions/PureWikiDeletion/PureWikiDeletion.php
@@ -32,7 +32,7 @@
3333 'url' => 'http://www.mediawiki.org/wiki/Extension:PureWikiDeletion',
3434 'description' => 'Implements pure wiki deletion',
3535 'descriptionmsg' => 'purewikideletion-desc',
36 - 'version' => '1.0.3',
 36+ 'version' => '1.0.4',
3737 );
3838
3939 $dir = dirname( __FILE__ ) . '/';
@@ -62,6 +62,9 @@
6363
6464 $wgDefaultUserOptions['watchblank'] = 0;
6565 $wgDefaultUserOptions['watchunblank'] = 0;
 66+$wgPureWikiDeletionLoginRequiredToBlank = false;
 67+$wgPureWikiDeletionLoginRequiredToUnblank = false;
 68+$wgPureWikiDeletionBlankLinkStyle="color: red";
6669
6770 $wgLogTypes[] = 'blank';
6871 $wgLogNames['blank'] = 'blank-log-name';
@@ -94,6 +97,10 @@
9598 return $rv;
9699 }
97100
 101+/**
 102+* Do not allow an anonymous user to blank or unblank a page unless this wiki
 103+* allows it
 104+*/
98105 function PureWikiDeletionSaveHook( &$article, &$user, &$text, &$summary,
99106 $minor, $watch, $sectionanchor, &$flags ) {
100107 global $wgOut, $wgPureWikiDeletionLoginRequiredToBlank, $wgPureWikiDeletionLoginRequiredToUnblank;
@@ -124,6 +131,9 @@
125132 return true;
126133 }
127134
 135+/**
 136+* Checkboxes in preferences for watching pages a user blanks or unblanks
 137+*/
128138 function PureWikiDeletionGetPreferences( $user, &$preferences ) {
129139 $prefs = array(
130140 'watchblank' => array(
@@ -142,6 +152,10 @@
143153 return true;
144154 }
145155
 156+/**
 157+* Stop an anonymous user from even wasting his time trying to unblank a page if
 158+* this wiki does not allow him to do so
 159+*/
146160 function PureWikiDeletionAlternateEditHook ( $editPage ) {
147161 global $wgUser, $wgOut, $wgPureWikiDeletionLoginRequiredToUnblank;
148162 if ( $wgUser->isLoggedIn() || !$wgPureWikiDeletionLoginRequiredToUnblank ) {
Index: trunk/extensions/PureWikiDeletion/SpecialPureWikiDeletion.php
@@ -1,7 +1,8 @@
22 <?php
33
44 /**
5 - * Special page to direct the user to a random page
 5+ * Special page to direct the user to a random page that is not in the blank_page
 6+ * table
67 *
78 * @ingroup SpecialPage
89 * @author Rob Church <robchur@gmail.com>, Ilmari Karonen
@@ -115,453 +116,10 @@
116117 }
117118 }
118119
119 -
120120 /**
121 - * Implements Special:Allpages
122 - * @ingroup SpecialPage
123 - */
124 -class AllPagesExcludeBlank extends IncludableSpecialPage {
125 -
126 - /**
127 - * Maximum number of pages to show on single subpage.
128 - */
129 - protected $maxPerPage = 345;
130 -
131 - /**
132 - * Maximum number of pages to show on single index subpage.
133 - */
134 - protected $maxLineCount = 200;
135 -
136 - /**
137 - * Maximum number of chars to show for an entry.
138 - */
139 - protected $maxPageLength = 70;
140 -
141 - /**
142 - * Determines, which message describes the input field 'nsfrom'.
143 - */
144 - protected $nsfromMsg = 'allpagesfrom';
145 -
146 - function __construct( $name = 'Allpages' ){
147 - parent::__construct( $name );
148 - }
149 -
150 - /**
151 - * Entry point : initialise variables and call subfunctions.
152 - * @param $par String: becomes "FOO" when called like Special:Allpages/FOO (default NULL)
153 - * @param $specialPage See the SpecialPage object.
154 - */
155 - function execute( $par ) {
156 - global $wgRequest, $wgOut, $wgContLang;
157 -
158 - $this->setHeaders();
159 - $this->outputHeader();
160 -
161 - # GET values
162 - $from = $wgRequest->getVal( 'from', null );
163 - $to = $wgRequest->getVal( 'to', null );
164 - $namespace = $wgRequest->getInt( 'namespace' );
165 -
166 - $namespaces = $wgContLang->getNamespaces();
167 -
168 - $wgOut->setPagetitle( ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces) ) ) ?
169 - wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) ) :
170 - wfMsg( 'allarticles' )
171 - );
172 -
173 - if( isset($par) ) {
174 - $this->showChunk( $namespace, $par, $to );
175 - } elseif( isset($from) && !isset($to) ) {
176 - $this->showChunk( $namespace, $from, $to );
177 - } else {
178 - $this->showToplevel( $namespace, $from, $to );
179 - }
180 - }
181 -
182 - /**
183 - * HTML for the top form
184 - * @param integer $namespace A namespace constant (default NS_MAIN).
185 - * @param string $from dbKey we are starting listing at.
186 - * @param string $to dbKey we are ending listing at.
187 - */
188 - function namespaceForm( $namespace = NS_MAIN, $from = '', $to = '' ) {
189 - global $wgScript;
190 - $t = $this->getTitle();
191 -
192 - $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
193 - $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
194 - $out .= Xml::hidden( 'title', $t->getPrefixedText() );
195 - $out .= Xml::openElement( 'fieldset' );
196 - $out .= Xml::element( 'legend', null, wfMsg( 'allpages' ) );
197 - $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
198 - $out .= "<tr>
199 - <td class='mw-label'>" .
200 - Xml::label( wfMsg( 'allpagesfrom' ), 'nsfrom' ) .
201 - "</td>
202 - <td class='mw-input'>" .
203 - Xml::input( 'from', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
204 - "</td>
205 - </tr>
206 - <tr>
207 - <td class='mw-label'>" .
208 - Xml::label( wfMsg( 'allpagesto' ), 'nsto' ) .
209 - "</td>
210 - <td class='mw-input'>" .
211 - Xml::input( 'to', 30, str_replace('_',' ',$to), array( 'id' => 'nsto' ) ) .
212 - "</td>
213 - </tr>
214 - <tr>
215 - <td class='mw-label'>" .
216 - Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
217 - "</td>
218 - <td class='mw-input'>" .
219 - Xml::namespaceSelector( $namespace, null ) . ' ' .
220 - Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
221 - "</td>
222 - </tr>";
223 - $out .= Xml::closeElement( 'table' );
224 - $out .= Xml::closeElement( 'fieldset' );
225 - $out .= Xml::closeElement( 'form' );
226 - $out .= Xml::closeElement( 'div' );
227 - return $out;
228 - }
229 -
230 - /**
231 - * @param integer $namespace (default NS_MAIN)
232 - */
233 - function showToplevel( $namespace = NS_MAIN, $from = '', $to = '' ) {
234 - global $wgOut, $wgContLang;
235 - $align = $wgContLang->isRtl() ? 'left' : 'right';
236 -
237 - # TODO: Either make this *much* faster or cache the title index points
238 - # in the querycache table.
239 -
240 - $dbr = wfGetDB( DB_SLAVE );
241 - $out = "";
242 - $where = array( 'page_namespace' => $namespace );
243 -
244 - $from = Title::makeTitleSafe( $namespace, $from );
245 - $to = Title::makeTitleSafe( $namespace, $to );
246 - $from = ( $from && $from->isLocal() ) ? $from->getDBKey() : null;
247 - $to = ( $to && $to->isLocal() ) ? $to->getDBKey() : null;
248 -
249 - if( isset($from) )
250 - $where[] = 'page_title >= '.$dbr->addQuotes( $from );
251 - if( isset($to) )
252 - $where[] = 'page_title <= '.$dbr->addQuotes( $to );
253 -
254 - global $wgMemc;
255 - $key = wfMemcKey( 'allpages', 'ns', $namespace, $from, $to );
256 - $lines = $wgMemc->get( $key );
257 -
258 - $count = $dbr->estimateRowCount( 'page', '*', $where, __METHOD__ );
259 - $maxPerSubpage = intval($count/$this->maxLineCount);
260 - $maxPerSubpage = max($maxPerSubpage,$this->maxPerPage);
261 -
262 - if( !is_array( $lines ) ) {
263 - $options = array( 'LIMIT' => 1 );
264 - $options['ORDER BY'] = 'page_title ASC';
265 - $firstTitle = $dbr->selectField( 'page', 'page_title', $where, __METHOD__, $options );
266 - $lastTitle = $firstTitle;
267 - # This array is going to hold the page_titles in order.
268 - $lines = array( $firstTitle );
269 - # If we are going to show n rows, we need n+1 queries to find the relevant titles.
270 - $done = false;
271 - while( !$done ) {
272 - // Fetch the last title of this chunk and the first of the next
273 - $chunk = ( $lastTitle === false )
274 - ? array()
275 - : array( 'page_title >= ' . $dbr->addQuotes( $lastTitle ) );
276 - $res = $dbr->select( 'page', /* FROM */
277 - 'page_title', /* WHAT */
278 - array_merge($where,$chunk),
279 - __METHOD__,
280 - array ('LIMIT' => 2, 'OFFSET' => $maxPerSubpage - 1, 'ORDER BY' => 'page_title ASC')
281 - );
282 -
283 - if( $s = $dbr->fetchObject( $res ) ) {
284 - array_push( $lines, $s->page_title );
285 - } else {
286 - // Final chunk, but ended prematurely. Go back and find the end.
287 - $endTitle = $dbr->selectField( 'page', 'MAX(page_title)',
288 - array_merge($where,$chunk),
289 - __METHOD__ );
290 - array_push( $lines, $endTitle );
291 - $done = true;
292 - }
293 - if( $s = $res->fetchObject() ) {
294 - array_push( $lines, $s->page_title );
295 - $lastTitle = $s->page_title;
296 - } else {
297 - // This was a final chunk and ended exactly at the limit.
298 - // Rare but convenient!
299 - $done = true;
300 - }
301 - $res->free();
302 - }
303 - $wgMemc->add( $key, $lines, 3600 );
304 - }
305 -
306 - // If there are only two or less sections, don't even display them.
307 - // Instead, display the first section directly.
308 - if( count( $lines ) <= 2 ) {
309 - if( !empty($lines) ) {
310 - $this->showChunk( $namespace, $lines[0], $lines[count($lines)-1] );
311 - } else {
312 - $wgOut->addHTML( $this->namespaceForm( $namespace, $from, $to ) );
313 - }
314 - return;
315 - }
316 -
317 - # At this point, $lines should contain an even number of elements.
318 - $out .= "<table class='allpageslist' style='background: inherit;'>";
319 - while( count ( $lines ) > 0 ) {
320 - $inpoint = array_shift( $lines );
321 - $outpoint = array_shift( $lines );
322 - $out .= $this->showline( $inpoint, $outpoint, $namespace );
323 - }
324 - $out .= '</table>';
325 - $nsForm = $this->namespaceForm( $namespace, $from, $to );
326 -
327 - # Is there more?
328 - if( $this->including() ) {
329 - $out2 = '';
330 - } else {
331 - if( isset($from) || isset($to) ) {
332 - global $wgUser;
333 - $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
334 - $out2 .= '<tr valign="top"><td>' . $nsForm;
335 - $out2 .= '</td><td align="' . $align . '" style="font-size: smaller; margin-bottom: 1em;">' .
336 - $wgUser->getSkin()->makeKnownLinkObj( $this->getTitle(), wfMsgHtml ( 'allpages' ) );
337 - $out2 .= "</td></tr></table>";
338 - } else {
339 - $out2 = $nsForm;
340 - }
341 - }
342 - $wgOut->addHTML( $out2 . $out );
343 - }
344 -
345 - /**
346 - * Show a line of "ABC to DEF" ranges of articles
347 - * @param string $inpoint Lower limit of pagenames
348 - * @param string $outpout Upper limit of pagenames
349 - * @param integer $namespace (Default NS_MAIN)
350 - */
351 - function showline( $inpoint, $outpoint, $namespace = NS_MAIN ) {
352 - global $wgContLang;
353 - $align = $wgContLang->isRtl() ? 'left' : 'right';
354 - $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
355 - $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
356 - // Don't let the length runaway
357 - $inpointf = $wgContLang->truncate( $inpointf, $this->maxPageLength );
358 - $outpointf = $wgContLang->truncate( $outpointf, $this->maxPageLength );
359 -
360 - $queryparams = $namespace ? "namespace=$namespace&" : '';
361 - $special = $this->getTitle();
362 - $link = $special->escapeLocalUrl( $queryparams . 'from=' . urlencode($inpoint) . '&to=' . urlencode($outpoint) );
363 -
364 - $out = wfMsgHtml( 'alphaindexline',
365 - "<a href=\"$link\">$inpointf</a></td><td>",
366 - "</td><td><a href=\"$link\">$outpointf</a>"
367 - );
368 - return '<tr><td align="' . $align . '">'.$out.'</td></tr>';
369 - }
370 -
371 - /**
372 - * @param integer $namespace (Default NS_MAIN)
373 - * @param string $from list all pages from this name (default FALSE)
374 - * @param string $to list all pages to this name (default FALSE)
375 - */
376 - function showChunk( $namespace = NS_MAIN, $from = false, $to = false ) {
377 - global $wgOut, $wgUser, $wgContLang, $wgLang;
378 -
379 - $sk = $wgUser->getSkin();
380 -
381 - $fromList = $this->getNamespaceKeyAndText($namespace, $from);
382 - $toList = $this->getNamespaceKeyAndText( $namespace, $to );
383 - $namespaces = $wgContLang->getNamespaces();
384 - $align = $wgContLang->isRtl() ? 'left' : 'right';
385 -
386 - $n = 0;
387 -
388 - if ( !$fromList || !$toList ) {
389 - $out = wfMsgWikiHtml( 'allpagesbadtitle' );
390 - } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
391 - // Show errormessage and reset to NS_MAIN
392 - $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
393 - $namespace = NS_MAIN;
394 - } else {
395 - list( $namespace, $fromKey, $from ) = $fromList;
396 - list( $namespace2, $toKey, $to ) = $toList;
397 -
398 - $dbr = wfGetDB( DB_SLAVE );
399 - $conds = array(
400 - 'page_namespace' => $namespace,
401 - 'page_title >= ' . $dbr->addQuotes( $fromKey )
402 - );
403 - if( $toKey !== "" ) {
404 - $conds[] = 'page_title <= ' . $dbr->addQuotes( $toKey );
405 - }
406 -
407 - $res = $dbr->select( 'page',
408 - array( 'page_namespace', 'page_title', 'page_is_redirect' ),
409 - $conds,
410 - __METHOD__,
411 - array(
412 - 'ORDER BY' => 'page_title',
413 - 'LIMIT' => $this->maxPerPage + 1,
414 - 'USE INDEX' => 'name_title',
415 - )
416 - );
417 -
418 - if( $res->numRows() > 0 ) {
419 - $out = '<table style="background: inherit;" border="0" width="100%">';
420 -
421 - while( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
422 - $t = Title::makeTitle( $s->page_namespace, $s->page_title );
423 - if( $t ) {
424 - $link = ( $s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
425 - $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
426 - ($s->page_is_redirect ? '</div>' : '' );
427 - } else {
428 - $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
429 - }
430 - if( $n % 3 == 0 ) {
431 - $out .= '<tr>';
432 - }
433 - $out .= "<td width=\"33%\">$link</td>";
434 - $n++;
435 - if( $n % 3 == 0 ) {
436 - $out .= '</tr>';
437 - }
438 - }
439 - if( ($n % 3) != 0 ) {
440 - $out .= '</tr>';
441 - }
442 - $out .= '</table>';
443 - } else {
444 - $out = '';
445 - }
446 - }
447 -
448 - if ( $this->including() ) {
449 - $out2 = '';
450 - } else {
451 - if( $from == '' ) {
452 - // First chunk; no previous link.
453 - $prevTitle = null;
454 - } else {
455 - # Get the last title from previous chunk
456 - $dbr = wfGetDB( DB_SLAVE );
457 - $res_prev = $dbr->select(
458 - 'page',
459 - 'page_title',
460 - array( 'page_namespace' => $namespace, 'page_title < '.$dbr->addQuotes($from) ),
461 - __METHOD__,
462 - array( 'ORDER BY' => 'page_title DESC', 'LIMIT' => $this->maxPerPage, 'OFFSET' => ($this->maxPerPage - 1 ) )
463 - );
464 -
465 - # Get first title of previous complete chunk
466 - if( $dbr->numrows( $res_prev ) >= $this->maxPerPage ) {
467 - $pt = $dbr->fetchObject( $res_prev );
468 - $prevTitle = Title::makeTitle( $namespace, $pt->page_title );
469 - } else {
470 - # The previous chunk is not complete, need to link to the very first title
471 - # available in the database
472 - $options = array( 'LIMIT' => 1 );
473 - if ( ! $dbr->implicitOrderby() ) {
474 - $options['ORDER BY'] = 'page_title';
475 - }
476 - $reallyFirstPage_title = $dbr->selectField( 'page', 'page_title',
477 - array( 'page_namespace' => $namespace ), __METHOD__, $options );
478 - # Show the previous link if it s not the current requested chunk
479 - if( $from != $reallyFirstPage_title ) {
480 - $prevTitle = Title::makeTitle( $namespace, $reallyFirstPage_title );
481 - } else {
482 - $prevTitle = null;
483 - }
484 - }
485 - }
486 -
487 - $self = $this->getTitle();
488 -
489 - $nsForm = $this->namespaceForm( $namespace, $from, $to );
490 - $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
491 - $out2 .= '<tr valign="top"><td>' . $nsForm;
492 - $out2 .= '</td><td align="' . $align . '" style="font-size: smaller; margin-bottom: 1em;">' .
493 - $sk->makeKnownLinkObj( $self,
494 - wfMsgHtml ( 'allpages' ) );
495 -
496 - # Do we put a previous link ?
497 - if( isset( $prevTitle ) && $pt = $prevTitle->getText() ) {
498 - $q = 'from=' . $prevTitle->getPartialUrl()
499 - . ( $namespace ? '&namespace=' . $namespace : '' );
500 - $prevLink = $sk->makeKnownLinkObj( $self,
501 - wfMsgHTML( 'prevpage', htmlspecialchars( $pt ) ), $q );
502 - $out2 = $wgLang->pipeList( array( $out2, $prevLink ) );
503 - }
504 -
505 - if( $n == $this->maxPerPage && $s = $res->fetchObject() ) {
506 - # $s is the first link of the next chunk
507 - $t = Title::MakeTitle($namespace, $s->page_title);
508 - $q = 'from=' . $t->getPartialUrl()
509 - . ( $namespace ? '&namespace=' . $namespace : '' );
510 - $nextLink = $sk->makeKnownLinkObj( $self,
511 - wfMsgHtml( 'nextpage', htmlspecialchars( $t->getText() ) ), $q );
512 - $out2 = $wgLang->pipeList( array( $out2, $nextLink ) );
513 - }
514 - $out2 .= "</td></tr></table>";
515 - }
516 -
517 - $wgOut->addHTML( $out2 . $out );
518 - if( isset($prevLink) or isset($nextLink) ) {
519 - $wgOut->addHTML( '<hr /><p style="font-size: smaller; float: ' . $align . '">' );
520 - if( isset( $prevLink ) ) {
521 - $wgOut->addHTML( $prevLink );
522 - }
523 - if( isset( $prevLink ) && isset( $nextLink ) ) {
524 - $wgOut->addHTML( wfMsgExt( 'pipe-separator'
525 - , 'escapenoentities' ) );
526 - }
527 - if( isset( $nextLink ) ) {
528 - $wgOut->addHTML( $nextLink );
529 - }
530 - $wgOut->addHTML( '</p>' );
531 -
532 - }
533 -
534 - }
535 -
536 - /**
537 - * @param int $ns the namespace of the article
538 - * @param string $text the name of the article
539 - * @return array( int namespace, string dbkey, string pagename ) or NULL on error
540 - * @static (sort of)
541 - * @access private
542 - */
543 - function getNamespaceKeyAndText($ns, $text) {
544 - if ( $text == '' )
545 - return array( $ns, '', '' ); # shortcut for common case
546 -
547 - $t = Title::makeTitleSafe($ns, $text);
548 - if ( $t && $t->isLocal() ) {
549 - return array( $t->getNamespace(), $t->getDBkey(),
550 - $t->getText() );
551 - } else if ( $t ) {
552 - return NULL;
553 - }
554 -
555 - # try again, in case the problem was an empty pagename
556 - $text = preg_replace('/(#|$)/', 'X$1', $text);
557 - $t = Title::makeTitleSafe($ns, $text);
558 - if ( $t && $t->isLocal() ) {
559 - return array( $t->getNamespace(), '', '' );
560 - } else {
561 - return NULL;
562 - }
563 - }
564 -}
565 -
 121+* Fill the blank_page table with title of all the currently blank pages; ignore
 122+* the File namespace. Purge caches as needed
 123+*/
566124 class PopulateBlankedPagesTable extends SpecialPage {
567125 function __construct() {
568126 parent::__construct( 'PopulateBlankedPagesTable','purewikideletion' );
Index: trunk/extensions/PureWikiDeletion/PureWikiDeletion.hooks.php
@@ -9,6 +9,9 @@
1010
1111 class PureWikiDeletionHooks {
1212
 13+ /**
 14+ * When a user visits the URL of a blanked page, redirect to the edit page
 15+ */
1316 public static function PureWikiDeletionOutputPageParserOutputHook( &$out, $parseroutput ) {
1417 $dbr = wfGetDB( DB_SLAVE );
1518 $target = $out->getTitle();
@@ -33,6 +36,11 @@
3437 return true;
3538 }
3639
 40+ /**
 41+ * After a page is saved, add or remove it from the blank_page table if
 42+ * it has been blanked or unblanked, respectively; if blanked, redirect
 43+ * the user to the "Action complete" page
 44+ */
3745 public static function PureWikiDeletionSaveCompleteHook( &$article, &$user, $text, $summary,
3846 $minoredit, &$watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId,
3947 &$redirect ) {
@@ -107,7 +115,9 @@
108116 return true;
109117 }
110118
111 -
 119+ /**
 120+ * Change the link style if the target page is in the blank_table
 121+ */
112122 public static function PureWikiDeletionLink( $skin, $target, &$text, &$customAttribs, &$query, &$options
113123 , &$ret ) {
114124 global $wgPureWikiDeletionBlankLinkStyle;
@@ -136,6 +146,9 @@
137147 return true;
138148 }
139149
 150+ /**
 151+ * Provide historical information about a blank page that the user is editing
 152+ */
140153 public static function PureWikiDeletionEditHook( &$editPage ) {
141154 global $wgLang, $wgUser;
142155 wfLoadExtensionMessages( 'PureWikiDeletion' );
@@ -179,6 +192,9 @@
180193 return true;
181194 }
182195
 196+ /**
 197+ * Remove blanked pages from the blank_page table when they are deleted
 198+ */
183199 public static function PureWikiDeletionDeleteHook( &$article, &$user, $reason, $id )
184200 {
185201 $dbr = wfGetDB( DB_SLAVE );
@@ -192,7 +208,10 @@
193209 }
194210 return true;
195211 }
196 -
 212+
 213+ /**
 214+ * Add blanked pages back to the blank_page table when they are undeleted
 215+ */
197216 public static function PureWikiDeletionUndeleteHook( $title, $create ) {
198217 $dbr = wfGetDB( DB_SLAVE );
199218 $myRevision = Revision::loadFromTitle( $dbr, $title );

Comments

#Comment by Skizzerz (talk | contribs)   00:59, 7 June 2010

"Adding documentation to RPED and PWD, etc." -- it's generally nicer to actually list everything that you did in the commit instead of saying etc. so that reviewers can see if some change done might have been accidentally committed or whatnot.

Status & tagging log