Page MenuHomePhabricator

SpecialAllpages.php.patch

Authored By
bzimport
Nov 21 2014, 8:49 PM
Size
14 KB
Referenced Files
None
Subscribers
None

SpecialAllpages.php.patch

Index: includes/SpecialAllpages.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/SpecialAllpages.php,v
retrieving revision 1.51.6.1
diff -u -r1.51.6.1 SpecialAllpages.php
--- includes/SpecialAllpages.php 2 Aug 2005 11:08:19 -0000 1.51.6.1
+++ includes/SpecialAllpages.php 13 Sep 2005 21:57:10 -0000
@@ -27,54 +27,31 @@
wfMsg( 'allarticles' )
);
+ $xml = $wgRequest->getBool('xml') && !$specialPage->including();
+
+ if ($xml) {
+ $output = new AllpagesOutput_Xml();
+ } else {
+ $output = new AllpagesOutput_Html();
+ }
+
+ $output->including($specialPage->including());
+ $output->namespace($namespace);
+
if ( isset($par) ) {
- indexShowChunk( $namespace, $par, $specialPage->including() );
+ indexShowChunk( $namespace, $par, $output );
} elseif ( isset($from) ) {
- indexShowChunk( $namespace, $from, $specialPage->including() );
+ indexShowChunk( $namespace, $from, $output );
} else {
- indexShowToplevel ( $namespace, $specialPage->including() );
+ indexShowToplevel ( $namespace, $output );
}
+ $output->output();
}
-
-/**
- * HTML for the top form
- * @param integer $namespace A namespace constant (default NS_MAIN).
- * @param string $from Article name we are starting listing at.
- */
-function indexNamespaceForm ( $namespace = NS_MAIN, $from = '' ) {
- global $wgContLang, $wgScript;
- $t = Title::makeTitle( NS_SPECIAL, "Allpages" );
-
- $namespaceselect = HTMLnamespaceselector($namespace, null);
-
- $frombox = "<input type='text' size='20' name='from' id='nsfrom' value=\""
- . htmlspecialchars ( $from ) . '"/>';
- $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . '" />';
-
- $out = "<div class='namespaceoptions'><form method='get' action='{$wgScript}'>";
- $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
- $out .= "
-<table id='nsselect' class='allpages'>
- <tr>
- <td align='right'>" . wfMsgHtml('allpagesfrom') . "</td>
- <td align='left'><label for='nsfrom'>$frombox</label></td>
- </tr>
- <tr>
- <td align='right'><label for='namespace'>" . wfMsgHtml('namespace') . "</label></td>
- <td align='left'>
- $namespaceselect $submitbutton
- </td>
- </tr>
-</table>
-";
- $out .= '</form></div>';
- return $out;
-}
/**
* @param integer $namespace (default NS_MAIN)
*/
-function indexShowToplevel ( $namespace = NS_MAIN, $including = false ) {
+function indexShowToplevel ( $namespace = NS_MAIN, &$output ) {
global $wgOut, $indexMaxperpage, $toplevelMaxperpage, $wgContLang, $wgRequest, $wgUser;
$sk = $wgUser->getSkin();
$fname = "indexShowToplevel";
@@ -139,68 +116,27 @@
// If there are only two or less sections, don't even display them.
// Instead, display the first section directly.
if( count( $lines ) <= 2 ) {
- indexShowChunk( $namespace, '', false, $including );
+ indexShowChunk( $namespace, '', $output );
return;
}
# At this point, $lines should contain an even number of elements.
- $out .= "<table style='background: inherit;'>";
+ $output->beginTopLevel();
while ( count ( $lines ) > 0 ) {
$inpoint = array_shift ( $lines );
$outpoint = array_shift ( $lines );
- $out .= indexShowline ( $inpoint, $outpoint, $namespace, false );
+ $output->printTopLevelItem( $inpoint, $outpoint, $namespace );
}
- $out .= '</table>';
-
- $nsForm = indexNamespaceForm ( $namespace, '', false );
+ $output->endTopLevel();
- # Is there more?
- if ( $including ) {
- $out2 = '';
- } else {
- $morelinks = '';
- if ( $morelinks != '' ) {
- $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
- $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
- $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">';
- $out2 .= $morelinks . '</td></tr></table><hr />';
- } else {
- $out2 = $nsForm . '<hr />';
- }
- }
-
- $wgOut->addHtml( $out2 . $out );
+ // Output now handled by calling function
}
-
-/**
- * @todo Document
- * @param string $from
- * @param integer $namespace (Default NS_MAIN)
- */
-function indexShowline( $inpoint, $outpoint, $namespace = NS_MAIN ) {
- global $wgOut, $wgLang, $wgUser;
- $sk = $wgUser->getSkin();
- $dbr =& wfGetDB( DB_SLAVE );
-
- $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
- $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
- $queryparams = ($namespace ? "namespace=$namespace" : '');
- $special = Title::makeTitle( NS_SPECIAL, 'Allpages/' . $inpoint );
- $link = $special->escapeLocalUrl( $queryparams );
-
- $out = wfMsg(
- 'alphaindexline',
- "<a href=\"$link\">$inpointf</a></td><td><a href=\"$link\">",
- "</a></td><td align=\"left\"><a href=\"$link\">$outpointf</a>"
- );
- return '<tr><td align="right">'.$out.'</td></tr>';
-}
/**
* @param integer $namespace (Default NS_MAIN)
* @param string $from list all pages from this name (default FALSE)
*/
-function indexShowChunk( $namespace = NS_MAIN, $from, $including = false ) {
+function indexShowChunk( $namespace = NS_MAIN, $from, &$output ) {
global $wgOut, $wgUser, $indexMaxperpage, $wgContLang;
$fname = 'indexShowChunk';
@@ -228,17 +164,191 @@
### FIXME: side link to previous
$n = 0;
- $out = '<table style="background: inherit;" border="0" width="100%">';
$namespaces = $wgContLang->getFormattedNamespaces();
+ $output->beginIndexChunk();
while( ($n < $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
- $t = Title::makeTitle( $s->page_namespace, $s->page_title );
+ $output->printChunkItem( $s->page_namespace, $s->page_title, $s->page_is_redirect );
+ }
+
+ $output->endIndexChunk();
+}
+
+/** A template class to inherit from.
+ * This is to define the interface and document it. Doesn't actually implement
+ * much.
+ */
+class AllpagesOutput {
+ /*private*/ var $mIncluding;
+ /*private*/ var $mNamespace;
+ /*private*/ var $mOut;
+
+ /** Gets/sets the current including state.
+ * @return The state of the include flag at the time
+ * of the call (ie, returns the old value on a
+ * set).
+ */
+ function including($val=Null) {
+ $oldval = $this->mIncluding;
+ if (!is_null($val)) {
+ $this->mIncluding = $val;
+ }
+ return $oldval;
+ }
+
+ /** Gets/sets the current namespace.
+ * @return The state of the namespace at the time
+ * of the call (ie, returns the old value on a
+ * set).
+ */
+ function namespace($val=Null) {
+ $oldval = $this->mNamespace;
+ if (!is_null($val)) {
+ $this->mNamespace = $val;
+ }
+ return $oldval;
+ }
+
+ /** Tells it to begin a page for an "index" list.
+ * You get this when you go to Special:Allpages on a larger wiki.
+ */
+ function beginTopLevel() {}
+ /** Prints an item for a top-level list.
+ * @todo Document
+ * @param string $from
+ * @param integer $namespace (Default NS_MAIN)
+ */
+ function printTopLevelItem($inpoint, $outpoint, $namespace) {}
+ /** Ends an index list
+ */
+ function endTopLevel() {}
+
+ /** Begins a page list
+ */
+ function beginIndexChunk() {}
+ /** Prints a page
+ * Things like seperation of regular, redirects, and unknown
+ * is handled here.
+ * @param $ns int The namespace ID of the page
+ * @param $title string The page DB key (ie, "Main_Page")
+ */
+ function printChunkItem($ns, $title, $redirect) {}
+ /** Ends a page list
+ */
+ function endIndexChunk() {}
+
+ /** Outputs any text buffered by previous methods.
+ */
+ function output() {}
+}
+
+/** Implements the AllpagesOutput class for (X)HTML.
+ */
+class AllpagesOutput_Html extends AllpagesOutput {
+ /*private*/ var $n = 0; // Used to count number of items, so rows can be done right
+ /*private*/ var $mOut2 = '';
+ /**
+ * HTML for the top form
+ * @param integer $namespace A namespace constant (default NS_MAIN).
+ * @param string $from Article name we are starting listing at.
+ */
+ function indexNamespaceForm ( $from = '' ) {
+ global $wgContLang, $wgScript;
+ $t = Title::makeTitle( NS_SPECIAL, "Allpages" );
+
+ $namespaceselect = HTMLnamespaceselector($this->namespace(), null);
+
+ $frombox = "<input type='text' size='20' name='from' id='nsfrom' value=\""
+ . htmlspecialchars ( $from ) . '"/>';
+ $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . '" />';
+
+ $out = "<div class='namespaceoptions'><form method='get' action='{$wgScript}'>";
+ $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
+ $out .= "
+<table id='nsselect' class='allpages'>
+ <tr>
+ <td align='right'>" . wfMsgHtml('allpagesfrom') . "</td>
+ <td align='left'><label for='nsfrom'>$frombox</label></td>
+ </tr>
+ <tr>
+ <td align='right'><label for='namespace'>" . wfMsgHtml('namespace') . "</label></td>
+ <td align='left'>
+ $namespaceselect $submitbutton
+ </td>
+ </tr>
+</table>
+";
+ $out .= '</form></div>';
+ return $out;
+ }
+
+ function beginTopLevel() {
+ $this->mOut .= "<table style='background: inherit;'>";
+ }
+ function printTopLevelItem($inpoint, $outpoint, $namespace) {
+/* global $wgOut, $wgLang, $wgUser;
+ $sk = $wgUser->getSkin();
+ $dbr =& wfGetDB( DB_SLAVE );*/
+
+ $queryparams = ($this->namespace() ? "namespace=$namespace" : '');
+ $special = Title::makeTitle( NS_SPECIAL, 'Allpages/' . $inpoint );
+
+ $link = $special->escapeLocalUrl( $queryparams );
+
+ $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
+ $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
+
+ $queryparams = ($namespace ? "namespace=$namespace" : '');
+ $special = Title::makeTitle( NS_SPECIAL, 'Allpages/' . $inpoint );
+ $link = htmlspecialchars($special->getPrefixedDBkey()."?$queryparams");
+ $link = $special->escapeLocalUrl( $queryparams );
+
+ $out = wfMsg(
+ 'alphaindexline',
+ "<a href=\"$link\">$inpointf</a></td><td><a href=\"$link\">",
+ "</a></td><td align=\"left\"><a href=\"$link\">$outpointf</a>"
+ );
+ $this->mOut .= '<tr><td align="right">'.$out.'</td></tr>';
+ }
+ function endTopLevel() {
+ $this->mOut .= '</table>';
+ $nsForm = $this->indexNamespaceForm ( '', false );
+
+ # Is there more?
+ if ( $this->including() ) {
+ $out2 = '';
+ } else {
+ $morelinks = ''; // ????
+ if ( $morelinks != '' ) {
+ $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
+ $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
+ $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">';
+ $out2 .= $morelinks . '</td></tr></table><hr />';
+ } else {
+ $out2 = $nsForm . '<hr />';
+ }
+ }
+ $this->mOut2 = $out2;
+ }
+
+ function beginIndexChunk() {
+ $this->mOut = '<table style="background: inherit;" border="0" width="100%">';
+ }
+ function printChunkItem($ns, $title, $redirect) {
+ global $wgOut, $wgUser, $indexMaxperpage, $wgContLang;
+ $sk = $wgUser->getSkin();
+ $out = '';
+
+ $n =& $this->n; // used for convenience only.
+
+ $t = Title::makeTitle( $ns, $title);
if( $t ) {
- $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
+ $link = ($redirect ? '<div class="allpagesredirect">' : '' ) .
$sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
- ($s->page_is_redirect ? '</div>' : '' );
+ ($redirect ? '</div>' : '' );
} else {
- $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
+ $link = htmlspecialchars( $title );
+ $link = '[['.$link.']]';
}
if( $n % 3 == 0 ) {
$out .= '<tr>';
@@ -248,32 +358,83 @@
if( $n % 3 == 0 ) {
$out .= '</tr>';
}
+
+ $this->mOut .= $out;
}
- if( ($n % 3) != 0 ) {
- $out .= '</tr>';
+ function endIndexChunk() {
+ $out = '';
+ if ( ($this->n % 3) != 0 ) {
+ $out .= '</tr>';
+ }
+ $out .= '</table>';
+ $this->mOut .= $out;
}
- $out .= '</table>';
- if ( $including ) {
- $out2 = '';
- } else {
- $nsForm = indexNamespaceForm ( $namespace, $from );
- $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
- $out2 .= '<tr valign="top"><td align="left">' . $nsForm;
- $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
- $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
- wfMsg ( 'allpages' ) );
- if ( ($n == $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
- $namespaceparam = $namespace ? "&namespace=$namespace" : "";
- $out2 .= " | " . $sk->makeKnownLink(
- $wgContLang->specialPage( "Allpages" ),
- wfMsg ( 'nextpage', $s->page_title ),
- "from=" . wfUrlEncode ( $s->page_title ) . $namespaceparam );
- }
- $out2 .= "</td></tr></table><hr />";
+ function output() {
+ global $wgOut;
+ $wgOut->addHtml( $this->mOut2 . $this->mOut );
}
+}
- $wgOut->addHtml( $out2 . $out );
-}
+/** Implements the AllpagesOutput class for XML.
+ */
+class AllpagesOutput_Xml extends AllpagesOutput {
+ /** Constructor
+ */
+ function AllpagesOutput_Xml() {
+ global $wgOut;
+ $wgOut->disable();
+ ini_set('html_errors', false);
+ header('Content-Type: text/xml');
+ $this->mOut = '<'.'?xml version="1.0" ?'.">\n"; // Always the first thing
+ }
+
+ function beginTopLevel() {
+ header('Status: 300 Multiple Choices',true,300);
+ $this->mOut .= "<pagelist type=\"indexlist\">\n";
+ // The type attribute is set based on whether it's an actual page list (pagelist) or a list of
+ // subranges (indexlist)
+
+ }
+ function printTopLevelItem($inpoint, $outpoint, $foo=null) {
+ $queryparams = ($this->namespace() ? "namespace={$this->namespace()}" : '');
+ $special = Title::makeTitle( NS_SPECIAL, 'Allpages/' . $inpoint );
+ $link = htmlspecialchars($special->getPrefixedDBkey()."?$queryparams");
+
+ $inpointf = htmlspecialchars( $inpoint );
+ $outpointf = htmlspecialchars( $outpoint );
+
+ $this->mOut .= "<li begin=\"$inpointf\" end=\"$outpointf\">$link</li>";
+ }
+ function endTopLevel() {
+ $this->mOut .= '</pagelist>';
+ }
+
+ function beginIndexChunk() {
+ $this->mOut .= "<pagelist type=\"pagelist\">\n";
+ }
+ function printChunkItem($ns, $title, $redirect) {
+ $out = '';
+ $t = Title::makeTitle( $ns, $title );
+ if( $t ) {
+ $out = ($redirect ? '<li status="redirect">' : '<li>' ) .
+ htmlspecialchars( $t->getPrefixedDBkey() ) .
+ "</li>\n";
+ } else {
+ $link = htmlspecialchars( $title );
+ $out = '<li status="unknown">' . // Unknown title, not unknown status
+ $link .
+ "</li>\n";
+ }
+ $this->mOut .= $out;
+ }
+ function endIndexChunk() {
+ $this->mOut .= '</pagelist>';
+ }
+
+ function output() {
+ echo $this->mOut; // That's the entire page
+ }
+}
?>

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1886
Default Alt Text
SpecialAllpages.php.patch (14 KB)

Event Timeline